[IMP] caldav wizard for synchronizing calendar

bzr revid: jam@tinyerp.com-20101227095609-nofn0cw0wr3oxdfw
This commit is contained in:
atp-openerp, jam-openerp 2010-12-27 15:26:09 +05:30 committed by jam-openerp
parent 3ff7c550fc
commit de7223c48b
6 changed files with 196 additions and 2 deletions

View File

@ -56,6 +56,7 @@
'wizard/calendar_event_export_view.xml',
'wizard/calendar_event_import_view.xml',
'wizard/calendar_event_subscribe_view.xml',
'wizard/caldav_browse_view.xml',
'caldav_view.xml',
'caldav_setup.xml'
],

View File

@ -22,5 +22,5 @@
import calendar_event_export
import calendar_event_import
import calendar_event_subscribe
import caldav_browse
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

View File

@ -0,0 +1,123 @@
# -*- 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 osv, fields
from tools import config
import base64
import addons
class caldav_browse(osv.osv_memory):
_name = 'caldav.browse'
_description = 'Caldav Browse'
_columns = {
'url' : fields.char('Caldav Server', size=264, required=True),
'caldav_doc_file':fields.binary('Caldav Document', readonly=True, help="Caldav Document ile."),
'description':fields.text('Description', readonly=True)
}
def default_get(self, cr, uid, fields, context=None):
res = {}
host = ''
port = ''
prefix = 'http://'
if not config.get('xmlrpc'):
if not config.get('netrpc'):
prefix = 'https://'
host = config.get('xmlrpcs_interface', None)
port = config.get('xmlrpcs_port', 8071)
else:
host = config.get('netrpc_interface', None)
port = config.get('netrpc_port',8070)
else:
host = config.get('xmlrpc_interface', None)
port = config.get('xmlrpc_port',8069)
if host == '' or None:
host = 'localhost'
port = 8069
if not config.get_misc('webdav','enable',True):
raise Exception("WebDAV is disabled, cannot continue")
user_pool = self.pool.get('res.users')
current_user = user_pool.browse(cr, uid, uid, context=context)
pref_obj = self.pool.get('user.preference')
pref_ids = pref_obj.browse(cr, uid ,context.get('rec_id',False), context=context)
if pref_ids:
pref_ids = pref_ids[0]
url = host + ':' + str(port) + '/'+ pref_ids.service + '/' + cr.dbname + '/'+'calendar/'+ 'users/'+ current_user.login + '/'+ pref_ids.collection.name+ '/'+ pref_ids.calendar.name
file = open(addons.get_module_resource('caldav','doc', 'Caldav_doc.pdf'),'rb')
res['caldav_doc_file'] = base64.encodestring(file.read())
res['description'] = """
* Webdav server that provides remote access to calendar
* Synchronisation of calendar using WebDAV
* Customize calendar event and todo attribute with any of OpenERP model
* Provides iCal Import/Export functionality
To access Calendars using CalDAV clients, point them to:
http://HOSTNAME:PORT/webdav/DATABASE_NAME/calendars/users/USERNAME/c
To access OpenERP Calendar using WebCal to remote site use the URL like:
http://HOSTNAME:PORT/webdav/DATABASE_NAME/Calendars/CALENDAR_NAME.ics
Where,
HOSTNAME: Host on which OpenERP server(With webdav) is running
PORT : Port on which OpenERP server is running (By Default : 8069)
DATABASE_NAME: Name of database on which OpenERP Calendar is created
CALENDAR_NAME: Name of calendar to access
"""
res['url'] = prefix+url
return res
def browse_caldav(self, cr, uid, ids, context):
return {}
caldav_browse()
class user_preference(osv.osv_memory):
_name = 'user.preference'
_description = 'User preference FOrm'
_columns = {
'collection' :fields.many2one('document.directory', "Calendar Collection", required=True, domain = [('calendar_collection', '=', True)]),
'calendar' :fields.many2one('basic.calendar', 'Calendar', required=True),
'service': fields.selection([('webdav','WEBDAV'),('vdir','VDIR')], "Services")
}
_defaults={
'service': lambda *a: 'webdav'
}
def open_window(self, cr, uid, ids, context=None):
obj_model = self.pool.get('ir.model.data')
model_data_ids = obj_model.search(cr,uid,[('model','=','ir.ui.view'),('name','=','caldav_Browse')])
resource_id = obj_model.read(cr, uid, model_data_ids, fields=['res_id'])
context.update({'rec_id': ids})
return {
'view_type': 'form',
'view_mode': 'form',
'res_model': 'caldav.browse',
'views': [(resource_id,'form')],
'type': 'ir.actions.act_window',
'target': 'new',
'context': context,
}
user_preference()

View File

@ -0,0 +1,58 @@
<?xml version="1.0"?>
<openerp>
<data>
<record id="caldav_browse_form" model="ir.ui.view">
<field name="name">caldav_Browse</field>
<field name="model">caldav.browse</field>
<field name="type">form</field>
<field name="arch" type="xml">
<form string="Browse caldav" >
<group colspan="4" width="700" height="500">
<separator string="Browse caldav" colspan="4"/>
<field name="url" colspan="4" />
<field name="caldav_doc_file" colspan="4" />
<separator string="Description" colspan="4"/>
<field name="description" colspan="4" nolabel="1"/>
<separator colspan="4"/>
<group col="4" colspan="4">
<label string="" colspan="2"/>
<button special="cancel" string="_Cancel" icon="gtk-cancel"/>
<button name="browse_caldav" string="_ok" type="object" icon="gtk-ok"/>
</group>
</group>
</form>
</field>
</record>
<record id="user_prefernce_form" model="ir.ui.view">
<field name="name">user_preference</field>
<field name="model">user.preference</field>
<field name="type">form</field>
<field name="arch" type="xml">
<form string="User Preference">
<separator string="" colspan="4"/>
<field name="service" colspan="4" width="250"/>
<field name="collection" colspan="4" width="250"/>
<field name="calendar" colspan="4" width="250" domain="[('collection_id','=', collection)]"/>
<separator colspan="4"/>
<group col="4" colspan="4">
<label string="" colspan="2"/>
<button special="cancel" string="_Cancel" icon="gtk-cancel"/>
<button name="open_window" string="_Open" type="object" icon="gtk-ok"/>
</group>
</form>
</field>
</record>
<record id="action_caldav_browse" model="ir.actions.act_window">
<field name="name">Caldav Browse</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">user.preference</field>
<field name="view_id" ref="user_prefernce_form"/>
<field name="view_type">form</field>
<field name="view_mode">form</field>
<field name="target">new</field>
</record>
</data>
</openerp>

View File

@ -1,3 +1,4 @@
# -*- coding: utf-8 -*-
##############################################################################
#
@ -36,7 +37,7 @@
'crm_caldav_setup.xml',
],
'update_xml': [],
'update_xml': ['crm_caldav_view.xml'],
'demo_xml': [],
'installable': True,
'active': False,

View File

@ -0,0 +1,11 @@
<?xml version="1.0"?>
<openerp>
<data>
<menuitem
name="Synchronyze this calendar"
action="caldav.action_caldav_browse"
id="menu_caldav_browse"
icon="STOCK_EXECUTE"
parent="crm.menu_meeting_sale" sequence="1"/>
</data>
</openerp>