diff options
| author | Kersten Jeremy <jke@openerp.com> | 2014-05-14 10:28:10 +0200 |
|---|---|---|
| committer | Kersten Jeremy <jke@openerp.com> | 2014-05-14 10:28:10 +0200 |
| commit | 02be7aa65cb2fa06ab2d1fcd250a419015f3c674 (patch) | |
| tree | 67e78104efd0cbb0dac42e4f8c771b24a2110c45 /addons/google_calendar/controllers | |
| parent | 7564f528e0ba959807e995ff5134ec0b04e4cb3f (diff) | |
[IMP] Improve Calendar synchronization
- Use the new fields from calendar (renamed in 9398.1.7 trunk-cal-v8-jke)
- Manage some google excpetions about token expiration
- Manage some google excpetions about token revokation
- Manage some google excpetions about 410 - Gone from google
- Detect / Allow user to change the calendar and remove all old reference.
- Use by default the since_modified for synchronization and not always a full (updatedTime in google)
- Add some key for ir_parameters :
'calendar.week_synchro' : number of week to synchornize when we are in full mode
'calendar.block_synchro_attendee' : need to synchronize the attendees between google and openerp (creation of partner)
'calendar.block_since_synchro' : Always use the full synchro. (Can be forced in "one time" removing the last synchro from res_users form)
'calendar.debug_print' : _logger is more verbose
- Pep 8
- Change behaviour of do_request to return a tuple with status raquest and response
- Add field from token and synchro date in res_users view form
Diffstat (limited to 'addons/google_calendar/controllers')
| -rw-r--r-- | addons/google_calendar/controllers/main.py | 73 |
1 files changed, 41 insertions, 32 deletions
diff --git a/addons/google_calendar/controllers/main.py b/addons/google_calendar/controllers/main.py index 49083a79bfc..1f307133ea0 100644 --- a/addons/google_calendar/controllers/main.py +++ b/addons/google_calendar/controllers/main.py @@ -1,51 +1,60 @@ -import simplejson -import urllib -import openerp import openerp.addons.web.http as http from openerp.addons.web.http import request -import openerp.addons.web.controllers.main as webmain -from openerp.addons.web.http import SessionExpiredException -from werkzeug.exceptions import BadRequest -import werkzeug.utils + class google_calendar_controller(http.Controller): - + @http.route('/google_calendar/sync_data', type='json', auth='user') - def sync_data(self, arch, fields, model,**kw): - """ + def sync_data(self, arch, fields, model, **kw): + """ This route/function is called when we want to synchronize openERP calendar with Google Calendar Function return a dictionary with the status : need_config_from_admin, need_auth, need_refresh, success if not calendar_event - The dictionary may contains an url, to allow OpenERP Client to redirect user on this URL for authorization for example + The dictionary may contains an url, to allow OpenERP Client to redirect user on this URL for authorization for example """ - + if model == 'calendar.event': gs_obj = request.registry['google.service'] gc_obj = request.registry['google.calendar'] - + # Checking that admin have already configured Google API for google synchronization ! - client_id = gs_obj.get_client_id(request.cr, request.uid,'calendar',context=kw.get('local_context')) + client_id = gs_obj.get_client_id(request.cr, request.uid, 'calendar', context=kw.get('local_context')) if not client_id or client_id == '': action = '' - if gc_obj.can_authorize_google(request.cr,request.uid): - dummy, action = request.registry.get('ir.model.data').get_object_reference(request.cr, request.uid, 'google_calendar', 'action_config_settings_google_calendar') - + if gc_obj.can_authorize_google(request.cr, request.uid): + dummy, action = request.registry.get('ir.model.data').get_object_reference(request.cr, request.uid, + 'google_calendar', 'action_config_settings_google_calendar') + return { - "status" : "need_config_from_admin", - "url" : '', - "action" : action - } - + "status": "need_config_from_admin", + "url": '', + "action": action + } + # Checking that user have already accepted OpenERP to access his calendar ! - if gc_obj.need_authorize(request.cr, request.uid,context=kw.get('local_context')): - url = gc_obj.authorize_google_uri(request.cr, request.uid, from_url=kw.get('fromurl'), context=kw.get('local_context')) + if gc_obj.need_authorize(request.cr, request.uid, context=kw.get('local_context')): + url = gc_obj.authorize_google_uri(request.cr, request.uid, from_url=kw.get('fromurl'), context=kw.get('local_context')) return { - "status" : "need_auth", - "url" : url - } - + "status": "need_auth", + "url": url + } + # If App authorized, and user access accepted, We launch the synchronization - return gc_obj.synchronize_events(request.cr, request.uid, [], kw.get('local_context')) - - return { "status" : "success" } - + return gc_obj.synchronize_events(request.cr, request.uid, [], context=kw.get('local_context')) + + return {"status": "success"} + + @http.route('/google_calendar/remove_references', type='json', auth='user') + def remove_references(self, model, **kw): + """ + This route/function is called when we want to remove all the references between one calendar OpenERP and one Google Calendar + """ + status = "NOP" + if model == 'calendar.event': + gc_obj = request.registry['google.calendar'] + # Checking that user have already accepted OpenERP to access his calendar ! + if gc_obj.remove_references(request.cr, request.uid, context=kw.get('local_context')): + status = "OK" + else: + status = "KO" + return {"status": status} |
