From e312be45e91a7f7bb169c5c500c4ccf5c1570a4f Mon Sep 17 00:00:00 2001 From: "Ujjvala Collins (OpenERP)" Date: Fri, 11 Mar 2011 16:58:18 +0530 Subject: [PATCH] [REF] sync_google_calendar: Added an option for all calendars' all events. bzr revid: uco@tinyerp.com-20110311112818-rpx3axlcjk23lg01 --- addons/sync_google_calendar/__init__.py | 1 + .../sync_google_calendar.py | 35 ++++++++++ .../wizard/wizard_import_calendar_events.py | 66 +++++++++++-------- 3 files changed, 76 insertions(+), 26 deletions(-) create mode 100644 addons/sync_google_calendar/sync_google_calendar.py diff --git a/addons/sync_google_calendar/__init__.py b/addons/sync_google_calendar/__init__.py index f8a7a810426..0827cfd7278 100644 --- a/addons/sync_google_calendar/__init__.py +++ b/addons/sync_google_calendar/__init__.py @@ -19,6 +19,7 @@ # ############################################################################## +import sync_google_calendar import wizard # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/addons/sync_google_calendar/sync_google_calendar.py b/addons/sync_google_calendar/sync_google_calendar.py new file mode 100644 index 00000000000..31eb52dcea0 --- /dev/null +++ b/addons/sync_google_calendar/sync_google_calendar.py @@ -0,0 +1,35 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# Copyright (C) 2004-2010 Tiny SPRL (). +# +# 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 . +# +############################################################################## + +from osv import osv + +class crm_meeting(osv.osv): + _inherit = "crm.meeting" + + def unlink(self, cr, uid, ids, context=None): + model_obj = self.pool.get('ir.model.data') + model_ids = model_obj.search(cr, uid, [('res_id','in',ids),('model','=','crm.meeting'),('module','=','sync_google_calendar')], context=context) + model_obj.unlink(cr, uid, model_ids, context=context) + return super(crm_meeting, self).unlink(cr, uid, ids, context=context) + +crm_meeting() + +# vim:expandtab:smartindent:toabstop=4:softtabstop=4:shiftwidth=4: diff --git a/addons/sync_google_calendar/wizard/wizard_import_calendar_events.py b/addons/sync_google_calendar/wizard/wizard_import_calendar_events.py index eea086f7b63..6912e1f358c 100644 --- a/addons/sync_google_calendar/wizard/wizard_import_calendar_events.py +++ b/addons/sync_google_calendar/wizard/wizard_import_calendar_events.py @@ -87,7 +87,7 @@ class synchronize_google_calendar_events(osv.osv_memory): calendars = gd_client.GetAllCalendarsFeed() for cal in calendars.entry: res.append((cal.id.text, cal.title.text)) - res.append(('default','Default Calendar')) + res.append(('all','All Calendars')) return res _columns = { @@ -95,34 +95,12 @@ class synchronize_google_calendar_events(osv.osv_memory): } _defaults = { - 'calendar_name': 'default', + 'calendar_name': 'all', } - def import_calendar_events(self, cr, uid, ids, context=None): - obj = self.browse(cr, uid, ids, context=context)[0] - if not ids: - return { 'type': 'ir.actions.act_window_close' } - - user_obj = self.pool.get('res.users').browse(cr, uid, uid) + def get_events(self, cr, uid, event_feed, context=None): meeting_obj = self.pool.get('crm.meeting') model_obj = self.pool.get('ir.model.data') - gmail_user = user_obj.gmail_user - gamil_pwd = user_obj.gmail_password - - google = self.pool.get('google.login') - gd_client = google.google_login(cr, uid, gmail_user, gamil_pwd, type='calendar') - - if not gmail_user or not gamil_pwd: - raise osv.except_osv(_('Error'), _("Please specify the user and password !")) - - if obj.calendar_name != 'default': - events_query = gdata.calendar.service.CalendarEventQuery(user=urllib.unquote(obj.calendar_name.split('/')[~0])) - events_query.start_index = 1 - events_query.max_results = 1000 - event_feed = gd_client.GetCalendarEventFeed(events_query.ToUri()) - else: - event_feed = gd_client.GetCalendarEventFeed() - meeting_ids = [] for feed in event_feed.entry: google_id = feed.id.text @@ -146,6 +124,42 @@ class synchronize_google_calendar_events(osv.osv_memory): meeting_ids.append(res_id) model_data.update({'res_id': res_id}) model_obj.create(cr, uid, model_data, context=context) + return meeting_ids + + def import_calendar_events(self, cr, uid, ids, context=None): + obj = self.browse(cr, uid, ids, context=context)[0] + if not ids: + return { 'type': 'ir.actions.act_window_close' } + + user_obj = self.pool.get('res.users').browse(cr, uid, uid) + gmail_user = user_obj.gmail_user + gamil_pwd = user_obj.gmail_password + + google = self.pool.get('google.login') + gd_client = google.google_login(cr, uid, gmail_user, gamil_pwd, type='calendar') + + if not gmail_user or not gamil_pwd: + raise osv.except_osv(_('Error'), _("Please specify the user and password !")) + + meetings = [] + if obj.calendar_name != 'all': + events_query = gdata.calendar.service.CalendarEventQuery(user=urllib.unquote(obj.calendar_name.split('/')[~0])) + events_query.start_index = 1 + events_query.max_results = 1000 + event_feed = gd_client.GetCalendarEventFeed(events_query.ToUri()) + meetings.append(self.get_events(cr, uid, event_feed, context=context)) + else: + calendars = map(lambda x:x[0], [cal for cal in self._get_calendars(cr, uid, context) if cal[0] != 'all']) + for cal in calendars: + events_query = gdata.calendar.service.CalendarEventQuery(user=urllib.unquote(cal.split('/')[~0])) + events_query.start_index = 1 + events_query.max_results = 1000 + event_feed = gd_client.GetCalendarEventFeed(events_query.ToUri()) + meetings.append(self.get_events(cr, uid, event_feed, context=context)) + + meeting_ids = [] + for meeting in meetings: + meeting_ids += meeting return { 'name': _('Meetings'), @@ -157,7 +171,7 @@ class synchronize_google_calendar_events(osv.osv_memory): 'views': [(False, 'calendar'),(False, 'tree'),(False, 'form')], 'type': 'ir.actions.act_window', } - + synchronize_google_calendar_events() # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: