diff --git a/addons/base_calendar/controllers/main.py b/addons/base_calendar/controllers/main.py index 846d004c8c5..e115def3cb1 100644 --- a/addons/base_calendar/controllers/main.py +++ b/addons/base_calendar/controllers/main.py @@ -4,41 +4,50 @@ import openerp import openerp.addons.web.http as http from openerp.addons.web.http import request import openerp.addons.web.controllers.main as webmain -SUPERUSER_ID = 1 +import json class meetting_invitation(http.Controller): - + @http.route('/meeting_invitation/accept', type='http', auth="none") def accept(self, db, token, action, id): - # http://hostname:8069/meeting_invitation/accept/id=1&token=&db= + # http://hostname:8069/meeting_invitation/accept?db=#token=&action=&id= registry = openerp.modules.registry.RegistryManager.get(db) attendee_pool = registry.get('calendar.attendee') with registry.cursor() as cr: - attendee_ids = attendee_pool.search(cr, SUPERUSER_ID, [('access_token','=',token)]) - attendee_pool.do_accept(cr, SUPERUSER_ID, attendee_ids) - return self.view(db, action, id, view='form') - - + attendee_id = attendee_pool.search(cr, openerp.SUPERUSER_ID, [('access_token','=',token)]) + if attendee_id: + attendee_pool.do_accept(cr, openerp.SUPERUSER_ID, attendee_id) + return self.view(db, token, action, id, view='form') + @http.route('/meeting_invitation/decline', type='http', auth="none") def declined(self, db, token, action, id): - # http://hostname:8069/meeting_invitation/accept/id=1&token=&db= + # http://hostname:8069/meeting_invitation/decline?db=#token=&action=&id= registry = openerp.modules.registry.RegistryManager.get(db) attendee_pool = registry.get('calendar.attendee') with registry.cursor() as cr: - attendee_ids = attendee_pool.search(cr, SUPERUSER_ID, [('access_token','=',token)]) - attendee_pool.do_decline(cr, SUPERUSER_ID, attendee_ids) - return self.view(db, action, id, view='form') - + attendee_id = attendee_pool.search(cr, openerp.SUPERUSER_ID, [('access_token','=',token)]) + if attendee_id: + attendee_pool.do_decline(cr, openerp.SUPERUSER_ID, attendee_id) + return self.view(db, token, action, id, view='form') + @http.route('/meeting_invitation/view', type='http', auth="none") - def view(self, db, action, id, view='calendar'): - # http://hostname:8069/meeting_invitation/view/id=1&token=&db=&view= + def view(self, db, token, action, id, view='calendar'): + # http://hostname:8069/meeting_invitation/view?db=#token=&action=&id= + registry = openerp.modules.registry.RegistryManager.get(db) + meeting_pool = registry.get('crm.meeting') + attendee_pool = registry.get('calendar.attendee') + with registry.cursor() as cr: + attendee_data = meeting_pool.get_attendee(cr, openerp.SUPERUSER_ID, id); + attendee = attendee_pool.search_read(cr, openerp.SUPERUSER_ID, [('access_token','=',token)],[]) + if attendee: + attendee_data['current_attendee'] = attendee[0] js = "\n ".join('' % i for i in webmain.manifest_list('js', db=db)) css = "\n ".join('' % i for i in webmain.manifest_list('css',db=db)) return webmain.html_template % { 'js': js, 'css': css, 'modules': simplejson.dumps(webmain.module_boot(db)), - 'init': 's.base_calendar.event("%s", "%s", "%s", "%s");' % (db, action, id, view), + 'init': "s.base_calendar.event('%s', '%s', '%s', '%s' , '%s');" % (db, action, id, view, json.dumps(attendee_data)), } diff --git a/addons/base_calendar/crm_meeting.py b/addons/base_calendar/crm_meeting.py index d04e6fc5cbe..222abb8c890 100644 --- a/addons/base_calendar/crm_meeting.py +++ b/addons/base_calendar/crm_meeting.py @@ -28,6 +28,7 @@ from base_calendar import get_real_ids, base_calendar_id2real_id from datetime import datetime, timedelta, date import pytz from openerp import tools +import openerp # # crm.meeting is defined here so that it may be used by modules other than crm, @@ -192,35 +193,20 @@ class crm_meeting(osv.Model): del context['default_date'] return super(crm_meeting, self).message_post(cr, uid, thread_id, body=body, subject=subject, type=type, subtype=subtype, parent_id=parent_id, attachments=attachments, context=context, **kwargs) - def do_decline(self, cr, uid, ids, context=None): - attendee_pool = self.pool.get('calendar.attendee') - for meeting_id in ids: - attendee = self._find_user_attendee(cr, uid, meeting_id, context) - if attendee: - if attendee.state != 'declined': - self.message_post(cr, uid, meeting_id, body=_(("%s has declined invitation") % (attendee.cn)), context=context) - attendee_pool.write(cr, uid, attendee.id, {'state': 'declined'}, context) - return True - - def do_accept(self, cr, uid, ids, context=None): - attendee_pool = self.pool.get('calendar.attendee') - for meeting_id in ids: - attendee = self._find_user_attendee(cr, uid, meeting_id, context) - if attendee: - if attendee.state != 'accepted': - self.message_post(cr, uid, meeting_id, body=_(("%s has accepted invitation") % (attendee.cn)), context=context) - attendee_pool.write(cr, uid, attendee.id, {'state': 'accepted'}, context) - return True - def get_attendee(self, cr, uid, meeting_id, context=None): att = [] + invitation = {'meeting': {}, 'attendee': []} attendee_pool = self.pool.get('calendar.attendee') - for attendee in self.browse(cr,uid,int(meeting_id),context).attendee_ids: + invitation['logo'] = self.pool.get('res.users').browse(cr, uid, uid, context=context).company_id.logo.replace('\n','\\n') + meeting = self.browse(cr, uid, int(meeting_id), context) + invitation['meeting'] = {'event':meeting.name,'organizer': meeting.organizer, 'where': meeting.location,'when':meeting.event_time} + for attendee in meeting.attendee_ids: att.append({'name':attendee.cn,'status': attendee.state}) - return att + invitation['attendee'] = att + return invitation def get_day(self, cr, uid, ids, time= None, context=None): - rec = self.browse(cr, uid, ids,context=context)[0] + rec = self.browse(cr, uid, ids, context=context)[0] date = datetime.strptime(rec.date,'%Y-%m-%d %H:%M:%S') if time == 'day': res = str(date.day) diff --git a/addons/base_calendar/crm_meeting_data.xml b/addons/base_calendar/crm_meeting_data.xml index 725dc08d934..61d17828e7f 100644 --- a/addons/base_calendar/crm_meeting_data.xml +++ b/addons/base_calendar/crm_meeting_data.xml @@ -119,7 +119,7 @@ Decline