[IMP]: caldav: converted wizards into osv_memory wizards
bzr revid: rpa@tinyerp.com-20100311083818-fp3ve2g95mwa3wxu
This commit is contained in:
committed by
rpa (Open ERP)
parent
f8fbe2e5dc
commit
e7fb07589f
@@ -20,10 +20,10 @@
|
||||
##############################################################################
|
||||
|
||||
import caldav
|
||||
import caldav_cache
|
||||
import caldav_fs
|
||||
import caldav_node
|
||||
import webdav_server
|
||||
#import caldav_cache
|
||||
#import caldav_fs
|
||||
#import caldav_node
|
||||
#import webdav_server
|
||||
import wizard
|
||||
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||
|
||||
@@ -49,7 +49,9 @@
|
||||
"demo_xml" : [],
|
||||
"update_xml" : [
|
||||
'security/ir.model.access.csv',
|
||||
'caldav_wizard.xml',
|
||||
'wizard/calendar_event_export_view.xml',
|
||||
'wizard/calendar_event_import_view.xml',
|
||||
'wizard/calendar_event_subscribe_view.xml',
|
||||
'caldav_view.xml'
|
||||
],
|
||||
"installable" : True,
|
||||
|
||||
@@ -1,19 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<openerp>
|
||||
<data>
|
||||
<wizard string="Import .ics File" model="basic.calendar"
|
||||
name="calendar.event.import" id="wizard_cal_event_import" />
|
||||
|
||||
<wizard string="Subscribe"
|
||||
model="basic.calendar" name="calendar.event.subscribe"
|
||||
id="wizard_cal_event_subscribe" multi="True" />
|
||||
|
||||
<wizard string="Export .ics File" model="basic.calendar"
|
||||
name="calendar.event.export" id="wizard_cal_event_export" />
|
||||
|
||||
<wizard string="Edit this event" model="basic.calendar.event"
|
||||
name="calendar.event.edit.this" id="wizard_edit_this_event"
|
||||
menu="False" />
|
||||
|
||||
</data>
|
||||
</openerp>
|
||||
@@ -19,9 +19,8 @@
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
import wizard_cal_export
|
||||
import wizard_cal_import
|
||||
import wizard_cal_subscribe
|
||||
import calendar_event_export
|
||||
import calendar_event_import
|
||||
import calendar_event_subscribe
|
||||
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||
|
||||
|
||||
@@ -0,0 +1,69 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
##############################################################################
|
||||
#
|
||||
# OpenERP, Open Source Management Solution
|
||||
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Affero General Public License as
|
||||
# published by the Free Software Foundation, either version 3 of the
|
||||
# License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Affero General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
from osv import fields, osv
|
||||
from tools.translate import _
|
||||
import netsvc
|
||||
import pooler
|
||||
import time
|
||||
import tools
|
||||
import wizard
|
||||
import base64
|
||||
|
||||
class calendar_event_export(osv.osv_memory):
|
||||
"""
|
||||
Export Calendar Event.
|
||||
"""
|
||||
def _process_export_ics(self, cr, uid, context):
|
||||
"""
|
||||
Get Default value for file_path field.
|
||||
"""
|
||||
model = context.get('model', 'basic.calendar')
|
||||
model_obj = self.pool.get(model)
|
||||
calendar = model_obj.export_cal(cr, uid, context['active_ids'], context)
|
||||
#TODO: check why returns wrong value
|
||||
return base64.encodestring(calendar)
|
||||
|
||||
def _process_export_ics_name(self, cr, uid, context):
|
||||
"""
|
||||
Get Default value for Name field.
|
||||
"""
|
||||
model = context.get('model', 'basic.calendar')
|
||||
model_obj = self.pool.get(model)
|
||||
calendar = model_obj.export_cal(cr, uid, context['active_ids'], context)
|
||||
return 'OpenERP %s.ics' % (model_obj._description)
|
||||
|
||||
_name = "calendar.event.export"
|
||||
_description = "Event Export"
|
||||
_columns = {
|
||||
'file_path':fields.binary('Save ICS file', filters='*.ics', required=True),
|
||||
'name':fields.char('File name', size=34, required=True, help='Save in .ics format')
|
||||
}
|
||||
|
||||
_defaults={
|
||||
'name':_process_export_ics_name,
|
||||
'file_path':_process_export_ics
|
||||
}
|
||||
|
||||
calendar_event_export()
|
||||
|
||||
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||
@@ -0,0 +1,49 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<openerp>
|
||||
<data>
|
||||
<record id="view_calendar_event_export" model="ir.ui.view">
|
||||
<field name="name">calendar.event.export.form</field>
|
||||
<field name="model">calendar.event.export</field>
|
||||
<field name="type">form</field>
|
||||
<field name="arch" type="xml">
|
||||
<form string="Export ICS">
|
||||
<group colspan="4" >
|
||||
<field name="name"/>
|
||||
<field name="file_path" colspan="4" width="300"/>
|
||||
</group>
|
||||
<separator string="" colspan="4" />
|
||||
<group colspan="4" col="6">
|
||||
<button icon="gtk-cancel" special="cancel" string="_Cancel"/>
|
||||
</group>
|
||||
</form>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="action_calendar_event_export" model="ir.actions.act_window">
|
||||
<field name="name">Export .ics File</field>
|
||||
<field name="res_model">calendar.event.export</field>
|
||||
<field name="view_type">form</field>
|
||||
<field name="view_mode">tree,form</field>
|
||||
<field name="view_id" ref="view_calendar_event_export"/>
|
||||
<field name="target">new</field>
|
||||
<field name="context">{'record_id':active_id}</field>
|
||||
</record>
|
||||
|
||||
<!-- <record id="action_calendar_event_export_values" model="ir.values">-->
|
||||
<!-- <field name="model_id" ref="caldav.model_basic_calendar" />-->
|
||||
<!-- <field name="object" eval="1" />-->
|
||||
<!-- <field name="name">Export .ics File</field>-->
|
||||
<!-- <field name="key2">client_action_multi</field>-->
|
||||
<!-- <field name="value" eval="'ir.actions.act_window,' + str(ref('action_calendar_event_export'))"/>-->
|
||||
<!-- <field name="key">action</field> -->
|
||||
<!-- <field name="model">basic.calendar</field>-->
|
||||
<!-- </record>-->
|
||||
|
||||
|
||||
<act_window id="action_calendar_event_export_values"
|
||||
key2="client_action_multi" name="Export .ics File"
|
||||
res_model="calendar.event.export" src_model="basic.calendar"
|
||||
view_mode="form" target="new" view_type="form" />
|
||||
|
||||
</data>
|
||||
</openerp>
|
||||
@@ -0,0 +1,78 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
##############################################################################
|
||||
#
|
||||
# OpenERP, Open Source Management Solution
|
||||
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Affero General Public License as
|
||||
# published by the Free Software Foundation, either version 3 of the
|
||||
# License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Affero General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
from osv import fields, osv
|
||||
from tools.translate import _
|
||||
import netsvc
|
||||
import pooler
|
||||
import time
|
||||
import tools
|
||||
import wizard
|
||||
import base64
|
||||
|
||||
class calendar_event_import(osv.osv_memory):
|
||||
"""
|
||||
Import Calendar Event.
|
||||
"""
|
||||
cnt = 0
|
||||
def _process_imp_ics(self, cr, uid, ids, context=None):
|
||||
"""
|
||||
Process Import ics File.
|
||||
@param cr: the current row, from the database cursor,
|
||||
@param uid: the current user’s ID for security checks,
|
||||
@param ids: List of calendar event import’s IDs
|
||||
@return: dictionary of calendar evet import window with Import successful msg.
|
||||
"""
|
||||
for data in self.read(cr, uid, ids):
|
||||
model = data.get('model', 'basic.calendar')
|
||||
model_obj = self.pool.get(model)
|
||||
context.update({'model': model})
|
||||
data_obj = self.pool.get('ir.model.data')
|
||||
id2 = data_obj._get_id(cr, uid, 'caldav', 'view_calendar_event_import_display')
|
||||
if id2:
|
||||
id2 = data_obj.browse(cr, uid, id2, context=context).res_id
|
||||
vals = model_obj.import_cal(cr, uid, data['file_path'], context['active_id'], context)
|
||||
global cnt
|
||||
if vals:
|
||||
cnt = len(vals)
|
||||
value = {
|
||||
'view_type': 'form',
|
||||
'view_mode': 'form',
|
||||
'res_model': 'calendar.event.import',
|
||||
'views': [(id2,'form'),(False,'tree'),(False,'calendar'),(False,'graph')],
|
||||
'type': 'ir.actions.act_window',
|
||||
'target': 'new'
|
||||
}
|
||||
return value
|
||||
|
||||
_name = "calendar.event.import"
|
||||
_description = "Event Import"
|
||||
_columns = {
|
||||
'file_path': fields.binary('Select ICS file', filters='*.ics', required=True),
|
||||
'msg': fields.text('', readonly=True),
|
||||
}
|
||||
_defaults={
|
||||
'msg':lambda *a:'Import Sucessful'
|
||||
}
|
||||
|
||||
calendar_event_import()
|
||||
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||
@@ -0,0 +1,61 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<openerp>
|
||||
<data>
|
||||
<record id="view_calendar_event_import" model="ir.ui.view">
|
||||
<field name="name">calendar.event.import.form</field>
|
||||
<field name="model">calendar.event.import</field>
|
||||
<field name="type">form</field>
|
||||
<field name="arch" type="xml">
|
||||
<form string="Import ICS">
|
||||
<group colspan="4" >
|
||||
<separator string="Select ICS file"/>
|
||||
<field name="file_path" colspan="4" width="300" nolabel="1"/>
|
||||
</group>
|
||||
<separator string="" colspan="4" />
|
||||
<group colspan="4" col="6">
|
||||
<button icon="gtk-cancel" special="cancel" string="_Cancel"/>
|
||||
<button icon="gtk-ok" name="_process_imp_ics" string="_Import" type="object"/>
|
||||
</group>
|
||||
</form>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="view_calendar_event_import_display" model="ir.ui.view">
|
||||
<field name="name">calendar.event.import.form.display</field>
|
||||
<field name="model">calendar.event.import</field>
|
||||
<field name="type">form</field>
|
||||
<field name="arch" type="xml">
|
||||
<form string="Import Message">
|
||||
<group colspan="4" >
|
||||
<field name="msg" colspan="4" width="300" nolabel="1"/>
|
||||
</group>
|
||||
<separator string="" colspan="4" />
|
||||
<group colspan="4">
|
||||
<button icon="gtk-ok" special="cancel" string="Ok"/>
|
||||
</group>
|
||||
</form>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="action_calendar_event_import" model="ir.actions.act_window">
|
||||
<field name="name">Import .ics File</field>
|
||||
<field name="res_model">calendar.event.import</field>
|
||||
<field name="view_type">form</field>
|
||||
<field name="view_mode">tree,form</field>
|
||||
<field name="view_id" ref="view_calendar_event_import"/>
|
||||
<field name="target">new</field>
|
||||
<field name="context">{'record_id':active_id}</field>
|
||||
</record>
|
||||
|
||||
<record id="action_calendar_event_import_values" model="ir.values">
|
||||
<field name="model_id" ref="caldav.model_basic_calendar" />
|
||||
<field name="object" eval="1" />
|
||||
<field name="name">Import .ics File</field>
|
||||
<field name="key2">client_action_multi</field>
|
||||
<field name="value" eval="'ir.actions.act_window,' + str(ref('action_calendar_event_import'))"/>
|
||||
<field name="key">action</field>
|
||||
<field name="model">basic.calendar</field>
|
||||
</record>
|
||||
|
||||
</data>
|
||||
</openerp>
|
||||
@@ -0,0 +1,89 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
##############################################################################
|
||||
#
|
||||
# OpenERP, Open Source Management Solution
|
||||
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Affero General Public License as
|
||||
# published by the Free Software Foundation, either version 3 of the
|
||||
# License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Affero General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
from osv import fields, osv
|
||||
from tools.translate import _
|
||||
import netsvc
|
||||
import pooler
|
||||
import time
|
||||
import tools
|
||||
import wizard
|
||||
import base64
|
||||
import urllib
|
||||
|
||||
class calendar_event_subscribe(osv.osv_memory):
|
||||
"""
|
||||
Subscribe Calendar Event.
|
||||
"""
|
||||
cnt = 0
|
||||
def _process_imp_ics(self, cr, uid, ids, context=None):
|
||||
"""
|
||||
process ics file.
|
||||
@param cr: the current row, from the database cursor,
|
||||
@param uid: the current user’s ID for security checks,
|
||||
@param ids: List of calendar event subscribe’s IDs
|
||||
@return: dictionary of calendar evet subscribe window with Import successful msg.
|
||||
"""
|
||||
global cnt
|
||||
for data in self.read(cr, uid, ids):
|
||||
try:
|
||||
f = urllib.urlopen(data['url_path'])
|
||||
caldata = f.fp.read()
|
||||
f.close()
|
||||
except Exception,e:
|
||||
raise osv.except_osv(_('Error!'), _('Please provide Proper URL !'))
|
||||
model = data.get('model', 'basic.calendar')
|
||||
model_obj = self.pool.get(model)
|
||||
context.update({'url': data['url_path'],
|
||||
'model': data.get('model', 'basic.calendar')})
|
||||
vals = model_obj.import_cal(cr, uid, base64.encodestring(caldata), \
|
||||
context['active_id'], context)
|
||||
if vals:
|
||||
cnt = vals['count']
|
||||
data_obj = self.pool.get('ir.model.data')
|
||||
id2 = data_obj._get_id(cr, uid, 'caldav', 'view_calendar_event_subscribe_display')
|
||||
if id2:
|
||||
id2 = data_obj.browse(cr, uid, id2, context=context).res_id
|
||||
|
||||
value = {
|
||||
'view_type': 'form',
|
||||
'view_mode': 'form',
|
||||
'res_model': 'calendar.event.subscribe',
|
||||
'views': [(id2,'form'),(False,'tree'),(False,'calendar'),(False,'graph')],
|
||||
'type': 'ir.actions.act_window',
|
||||
'target': 'new'
|
||||
}
|
||||
return value
|
||||
|
||||
_name = "calendar.event.subscribe"
|
||||
_description = "Event subscribe"
|
||||
_columns = {
|
||||
'url_path': fields.char('Provide path for remote calendar', size=124, required=True),
|
||||
'msg': fields.text('', readonly=True),
|
||||
}
|
||||
_defaults={
|
||||
'msg':lambda *a:'Import Sucessful.'
|
||||
}
|
||||
|
||||
calendar_event_subscribe()
|
||||
|
||||
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||
@@ -0,0 +1,61 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<openerp>
|
||||
<data>
|
||||
<record id="view_calendar_event_subscribe" model="ir.ui.view">
|
||||
<field name="name">calendar.event.subscribe.form</field>
|
||||
<field name="model">calendar.event.subscribe</field>
|
||||
<field name="type">form</field>
|
||||
<field name="arch" type="xml">
|
||||
<form string="Subscribe to Remote Calendar">
|
||||
<group colspan="4" >
|
||||
<separator string="Provide path for Remote Calendar"/>
|
||||
<field name="url_path" colspan="4" width="300" nolabel="1" widget="url"/>
|
||||
</group>
|
||||
<separator string="" colspan="4" />
|
||||
<group colspan="4" col="6">
|
||||
<button icon="gtk-cancel" special="cancel" string="_Cancel"/>
|
||||
<button icon="gtk-ok" name="_process_imp_ics" string="_Subscribe" type="object"/>
|
||||
</group>
|
||||
</form>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="view_calendar_event_subscribe_display" model="ir.ui.view">
|
||||
<field name="name">calendar.event.subscribe.form.display</field>
|
||||
<field name="model">calendar.event.subscribe</field>
|
||||
<field name="type">form</field>
|
||||
<field name="arch" type="xml">
|
||||
<form string="Message...">
|
||||
<group colspan="4" >
|
||||
<field name="msg" colspan="4" width="300" nolabel="1"/>
|
||||
</group>
|
||||
<separator string="" colspan="4" />
|
||||
<group colspan="4">
|
||||
<button icon="gtk-ok" special="cancel" string="Ok"/>
|
||||
</group>
|
||||
</form>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="action_calendar_event_subscribe" model="ir.actions.act_window">
|
||||
<field name="name">Subscribe</field>
|
||||
<field name="res_model">calendar.event.subscribe</field>
|
||||
<field name="view_type">form</field>
|
||||
<field name="view_mode">tree,form</field>
|
||||
<field name="view_id" ref="view_calendar_event_subscribe"/>
|
||||
<field name="target">new</field>
|
||||
<field name="context">{'record_id':active_id}</field>
|
||||
</record>
|
||||
|
||||
<record id="action_calendar_event_subscribe_values" model="ir.values">
|
||||
<field name="model_id" ref="caldav.model_basic_calendar" />
|
||||
<field name="object" eval="1" />
|
||||
<field name="name">Subscribe</field>
|
||||
<field name="key2">client_action_multi</field>
|
||||
<field name="value" eval="'ir.actions.act_window,' + str(ref('action_calendar_event_subscribe'))"/>
|
||||
<field name="key">action</field>
|
||||
<field name="model">basic.calendar</field>
|
||||
</record>
|
||||
|
||||
</data>
|
||||
</openerp>
|
||||
@@ -1,65 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
##############################################################################
|
||||
#
|
||||
# OpenERP, Open Source Management Solution
|
||||
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Affero General Public License as
|
||||
# published by the Free Software Foundation, either version 3 of the
|
||||
# License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Affero General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
import wizard
|
||||
import base64
|
||||
import pooler
|
||||
|
||||
|
||||
class cal_event_export_wizard(wizard.interface):
|
||||
form1 = '''<?xml version="1.0"?>
|
||||
<form string="Export ICS">
|
||||
<field name="name"/>
|
||||
<field name="file_path" colspan="4" width="300"/>
|
||||
</form>'''
|
||||
|
||||
form1_fields = {
|
||||
'file_path': {
|
||||
'string': 'Save ICS file',
|
||||
'type': 'binary',
|
||||
'required': True,
|
||||
'filters': '*.ics'
|
||||
},
|
||||
'name': {
|
||||
'string': 'File name',
|
||||
'type': 'char',
|
||||
'size': 34,
|
||||
'required': True,
|
||||
'help': 'Save in .ics format'},
|
||||
}
|
||||
|
||||
def _process_export_ics(self, cr, uid, data, context):
|
||||
model = data.get('model')
|
||||
model_obj = pooler.get_pool(cr.dbname).get(model)
|
||||
calendar = model_obj.export_cal(cr, uid, data['ids'], context)
|
||||
return {'file_path': base64.encodestring(calendar), \
|
||||
'name': 'OpenERP %s.ics' % (model_obj._description)}
|
||||
|
||||
states = {
|
||||
'init': {
|
||||
'actions': [_process_export_ics],
|
||||
'result': {'type': 'form', 'arch':form1, 'fields':form1_fields, \
|
||||
'state': [('end', '_Cancel', 'gtk-cancel')]}},
|
||||
}
|
||||
|
||||
cal_event_export_wizard('calendar.event.export')
|
||||
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||
@@ -1,88 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
##############################################################################
|
||||
#
|
||||
# OpenERP, Open Source Management Solution
|
||||
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Affero General Public License as
|
||||
# published by the Free Software Foundation, either version 3 of the
|
||||
# License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Affero General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
import wizard
|
||||
import pooler
|
||||
|
||||
|
||||
class cal_event_import_wizard(wizard.interface):
|
||||
form1 = '''<?xml version="1.0"?>
|
||||
<form string="Import ICS">
|
||||
<separator string="Select ICS file"/>
|
||||
<field name="file_path" colspan="4" width="300" nolabel="1"/>
|
||||
</form>'''
|
||||
|
||||
form1_fields = {
|
||||
'file_path': {
|
||||
'string': 'Select ICS file',
|
||||
'type': 'binary',
|
||||
'required': True,
|
||||
'filters': '*.ics'
|
||||
}
|
||||
}
|
||||
display = '''<?xml version="1.0"?>
|
||||
<form string="Import Message">
|
||||
<field name="msg" colspan="4" width="300" nolabel="1"/>
|
||||
</form>'''
|
||||
|
||||
display_fields = {
|
||||
'msg': {
|
||||
'string': '',
|
||||
'type': 'text',
|
||||
'readonly': True,
|
||||
}
|
||||
}
|
||||
|
||||
def _process_imp_ics(self, cr, uid, data, context=None):
|
||||
model = data.get('model')
|
||||
model_obj = pooler.get_pool(cr.dbname).get(model)
|
||||
context.update({'model': model})
|
||||
vals = model_obj.import_cal(cr, uid, data['form']['file_path'], data['id'], context)
|
||||
global cnt
|
||||
cnt = 0
|
||||
if vals:
|
||||
cnt = len(vals)
|
||||
return {}
|
||||
|
||||
def _result_set(self, cr, uid, data, context=None):
|
||||
msg = (cnt and "Imported %s components" % cnt) or 'Import Sucessful'
|
||||
return {'msg': msg}
|
||||
|
||||
states = {
|
||||
'init': {
|
||||
'actions': [],
|
||||
'result': {'type': 'form', 'arch': form1, 'fields': form1_fields, \
|
||||
'state': [('end', '_Cancel', 'gtk-cancel'), ('open', '_Import', 'gtk-ok')]}
|
||||
},
|
||||
'open': {
|
||||
'actions': [],
|
||||
'result': {'type': 'action', 'action': _process_imp_ics, 'state': 'display'}
|
||||
},
|
||||
'display': {
|
||||
'actions': [_result_set],
|
||||
'result': {'type': 'form', 'arch': display, 'fields': display_fields, \
|
||||
'state': [('end', 'Ok', 'gtk-ok')]}
|
||||
},
|
||||
}
|
||||
|
||||
cal_event_import_wizard('calendar.event.import')
|
||||
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||
@@ -1,97 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
##############################################################################
|
||||
#
|
||||
# OpenERP, Open Source Management Solution
|
||||
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Affero General Public License as
|
||||
# published by the Free Software Foundation, either version 3 of the
|
||||
# License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Affero General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
from tools.translate import _
|
||||
import base64
|
||||
import pooler
|
||||
import urllib
|
||||
import wizard
|
||||
|
||||
class cal_event_subscribe_wizard(wizard.interface):
|
||||
form1 = '''<?xml version="1.0"?>
|
||||
<form string="Subscribe to Remote Calendar">
|
||||
<separator string="Provide path for Remote Calendar"/>
|
||||
<field name="url_path" colspan="4" width="300" nolabel="1" widget="url"/>
|
||||
</form>'''
|
||||
|
||||
form1_fields = {
|
||||
'url_path': {
|
||||
'string': 'Provide path for remote calendar',
|
||||
'type': 'char',
|
||||
'required': True,
|
||||
'size': 124
|
||||
}
|
||||
}
|
||||
display = '''<?xml version="1.0"?>
|
||||
<form string="Message...">
|
||||
<field name="msg" colspan="4" width="300" nolabel="1"/>
|
||||
</form>'''
|
||||
|
||||
display_fields = {
|
||||
'msg': {
|
||||
'string': '',
|
||||
'type': 'text',
|
||||
'readonly': True,
|
||||
}
|
||||
}
|
||||
|
||||
def _process_imp_ics(self, cr, uid, data, context=None):
|
||||
global cnt
|
||||
cnt = 0
|
||||
try:
|
||||
f = urllib.urlopen(data['form']['url_path'])
|
||||
caldata = f.fp.read()
|
||||
f.close()
|
||||
except Exception,e:
|
||||
raise wizard.except_wizard(_('Error!'), _('Please provide Proper URL !'))
|
||||
model = data.get('model')
|
||||
model_obj = pooler.get_pool(cr.dbname).get(model)
|
||||
context.update({'url': data['form']['url_path'],
|
||||
'model': data.get('model')})
|
||||
vals = model_obj.import_cal(cr, uid, base64.encodestring(caldata), \
|
||||
data['id'], context)
|
||||
if vals:
|
||||
cnt = vals['count']
|
||||
return {}
|
||||
|
||||
def _result_set(self, cr, uid, data, context=None):
|
||||
return {'msg': 'Import Sucessful.'}
|
||||
|
||||
states = {
|
||||
'init': {
|
||||
'actions': [],
|
||||
'result': {'type': 'form', 'arch': form1, 'fields': form1_fields, \
|
||||
'state': [('end', '_Cancel', 'gtk-cancel'), ('open', '_Subscribe', 'gtk-ok')]}
|
||||
},
|
||||
'open': {
|
||||
'actions': [],
|
||||
'result': {'type': 'action', 'action': _process_imp_ics, 'state': 'display'}
|
||||
},
|
||||
'display': {
|
||||
'actions': [_result_set],
|
||||
'result': {'type': 'form', 'arch': display, 'fields': display_fields, \
|
||||
'state': [('end', 'Ok', 'gtk-ok')]}
|
||||
},
|
||||
}
|
||||
|
||||
cal_event_subscribe_wizard('calendar.event.subscribe')
|
||||
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||
Reference in New Issue
Block a user