[TYPO] PEP7 - Module calendar (no E501)
bzr revid: jke@openerp.com-20140224220222-dp26lvbv2bfljxvt
This commit is contained in:
parent
bfaa40266d
commit
2907c8dd66
|
@ -37,8 +37,6 @@ from openerp.tools.translate import _
|
|||
from openerp.http import request
|
||||
from operator import itemgetter
|
||||
|
||||
from werkzeug.exceptions import BadRequest
|
||||
|
||||
import logging
|
||||
_logger = logging.getLogger(__name__)
|
||||
|
||||
|
@ -63,6 +61,7 @@ def calendar_id2real_id(calendar_id=None, with_date=False):
|
|||
return int(real_id)
|
||||
return calendar_id and int(calendar_id) or calendar_id
|
||||
|
||||
|
||||
def get_real_ids(ids):
|
||||
if isinstance(ids, (str, int, long)):
|
||||
return calendar_id2real_id(ids)
|
||||
|
@ -76,6 +75,7 @@ class calendar_attendee(osv.Model):
|
|||
Calendar Attendee Information
|
||||
"""
|
||||
_name = 'calendar.attendee'
|
||||
_rec_name = 'cn'
|
||||
_description = 'Attendee information'
|
||||
|
||||
def _compute_data(self, cr, uid, ids, name, arg, context=None):
|
||||
|
@ -388,14 +388,12 @@ class calendar_alarm_manager(osv.AbstractModel):
|
|||
SELECT
|
||||
*
|
||||
FROM (
|
||||
"""
|
||||
+ base_request
|
||||
+ """
|
||||
%s
|
||||
) AS ALL_EVENTS
|
||||
WHERE
|
||||
ALL_EVENTS.first_alarm < (now() at time zone 'utc' + interval '%s' second )
|
||||
AND ALL_EVENTS.last_alarm > (now() at time zone 'utc' - interval '%s' second )
|
||||
""", tuple_params)
|
||||
""" % base_request, tuple_params)
|
||||
|
||||
for event_id, first_alarm, last_alarm, first_meeting, last_meeting, min_duration, max_duration, rule in cr.fetchall():
|
||||
res[event_id].update({
|
||||
|
@ -433,7 +431,6 @@ class calendar_alarm_manager(osv.AbstractModel):
|
|||
res.append(alert)
|
||||
return res
|
||||
|
||||
|
||||
def get_next_mail(self, cr, uid, context=None):
|
||||
cron = self.pool.get('ir.cron').search(cr, uid, [('model', 'ilike', self._name)], context=context)
|
||||
if cron and len(cron) == 1:
|
||||
|
@ -458,13 +455,13 @@ class calendar_alarm_manager(osv.AbstractModel):
|
|||
all_events = self.get_next_potential_limit_alarm(cr, uid, cron_interval, notif=False, context=context)
|
||||
|
||||
for event in all_events: # .values()
|
||||
max_delta = all_events[event]['max_duration'];
|
||||
max_delta = all_events[event]['max_duration']
|
||||
curEvent = self.pool.get('calendar.event').browse(cr, uid, event, context=context)
|
||||
if curEvent.recurrency:
|
||||
bFound = False
|
||||
LastFound = False
|
||||
for one_date in self.pool.get('calendar.event').get_recurrent_date_by_event(cr, uid, curEvent, context=context):
|
||||
in_date_format = datetime.strptime(one_date, '%Y-%m-%d %H:%M:%S');
|
||||
in_date_format = datetime.strptime(one_date, '%Y-%m-%d %H:%M:%S')
|
||||
LastFound = self.do_check_alarm_for_one_date(cr, uid, in_date_format, curEvent, max_delta, cron_interval, notif=False, context=context)
|
||||
if LastFound:
|
||||
for alert in LastFound:
|
||||
|
@ -475,7 +472,7 @@ class calendar_alarm_manager(osv.AbstractModel):
|
|||
if bFound and not LastFound: # if the precedent event had an alarm but not this one, we can stop the search for this event
|
||||
break
|
||||
else:
|
||||
in_date_format = datetime.strptime(curEvent.date, '%Y-%m-%d %H:%M:%S');
|
||||
in_date_format = datetime.strptime(curEvent.date, '%Y-%m-%d %H:%M:%S')
|
||||
LastFound = self.do_check_alarm_for_one_date(cr, uid, in_date_format, curEvent, max_delta, cron_interval, notif=False, context=context)
|
||||
if LastFound:
|
||||
for alert in LastFound:
|
||||
|
@ -486,19 +483,19 @@ class calendar_alarm_manager(osv.AbstractModel):
|
|||
partner = self.pool.get('res.users').browse(cr, uid, uid, context=context).partner_id
|
||||
all_notif = []
|
||||
|
||||
if not partner or not partner.id: # If user is disconnected
|
||||
if not partner:
|
||||
return []
|
||||
|
||||
all_events = self.get_next_potential_limit_alarm(cr, uid, ajax_check_every_seconds, partner_id=partner.id, mail=False, context=context)
|
||||
|
||||
for event in all_events: # .values()
|
||||
max_delta = all_events[event]['max_duration'];
|
||||
max_delta = all_events[event]['max_duration']
|
||||
curEvent = self.pool.get('calendar.event').browse(cr, uid, event, context=context)
|
||||
if curEvent.recurrency:
|
||||
bFound = False
|
||||
LastFound = False
|
||||
for one_date in self.pool.get("calendar.event").get_recurrent_date_by_event(cr, uid, curEvent, context=context):
|
||||
in_date_format = datetime.strptime(one_date, '%Y-%m-%d %H:%M:%S');
|
||||
in_date_format = datetime.strptime(one_date, '%Y-%m-%d %H:%M:%S')
|
||||
LastFound = self.do_check_alarm_for_one_date(cr, uid, in_date_format, curEvent, max_delta, ajax_check_every_seconds, after=partner.cal_last_notif, mail=False, context=context)
|
||||
if LastFound:
|
||||
for alert in LastFound:
|
||||
|
@ -508,7 +505,7 @@ class calendar_alarm_manager(osv.AbstractModel):
|
|||
if bFound and not LastFound: # if the precedent event had alarm but not this one, we can stop the search fot this event
|
||||
break
|
||||
else:
|
||||
in_date_format = datetime.strptime(curEvent.date, '%Y-%m-%d %H:%M:%S');
|
||||
in_date_format = datetime.strptime(curEvent.date, '%Y-%m-%d %H:%M:%S')
|
||||
LastFound = self.do_check_alarm_for_one_date(cr, uid, in_date_format, curEvent, max_delta, ajax_check_every_seconds, partner.cal_last_notif, mail=False, context=context)
|
||||
if LastFound:
|
||||
for alert in LastFound:
|
||||
|
@ -1093,7 +1090,6 @@ class calendar_event(osv.Model):
|
|||
else:
|
||||
return ids
|
||||
|
||||
|
||||
def compute_rule_string(self, data):
|
||||
"""
|
||||
Compute rule string according to value type RECUR of iCalendar from the values given.
|
||||
|
@ -1242,7 +1238,6 @@ class calendar_event(osv.Model):
|
|||
first_occurence = list(rrule.rrulestr(str_rrule + ";COUNT=1", dtstart=datetime.strptime(date, "%Y-%m-%d %H:%M:%S"), forceset=True))[0]
|
||||
return {'value': {'date': first_occurence.strftime("%Y-%m-%d") + ' 00:00:00'}}
|
||||
|
||||
|
||||
def check_partners_email(self, cr, uid, partner_ids, context=None):
|
||||
""" Verify that selected partner_ids have an email_address defined.
|
||||
Otherwise throw a warning. """
|
||||
|
@ -1255,12 +1250,10 @@ class calendar_event(osv.Model):
|
|||
warning_msg = _('The following contacts have no email address :')
|
||||
for partner in partner_wo_email_lst:
|
||||
warning_msg += '\n- %s' % (partner.name)
|
||||
return {'warning':
|
||||
{
|
||||
return {'warning': {
|
||||
'title': _('Email addresses not found'),
|
||||
'message': warning_msg,
|
||||
}
|
||||
}
|
||||
}}
|
||||
|
||||
# ----------------------------------------
|
||||
# OpenChatter
|
||||
|
@ -1369,8 +1362,7 @@ class calendar_event(osv.Model):
|
|||
rrule_type=False,
|
||||
rrule='',
|
||||
recurrency=False,
|
||||
end_date = datetime.strptime(values.get('date', False) or data.get('date'),"%Y-%m-%d %H:%M:%S")
|
||||
+ timedelta(hours=values.get('duration', False) or data.get('duration'))
|
||||
end_date=datetime.strptime(values.get('date', False) or data.get('date'), "%Y-%m-%d %H:%M:%S") + timedelta(hours=values.get('duration', False) or data.get('duration'))
|
||||
)
|
||||
|
||||
#do not copy the id
|
||||
|
@ -1393,9 +1385,6 @@ class calendar_event(osv.Model):
|
|||
'flags': {'form': {'action_buttons': True, 'options': {'mode': 'edit'}}}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
def write(self, cr, uid, ids, values, context=None):
|
||||
def _only_changes_to_apply_on_real_ids(field_names):
|
||||
''' return True if changes are only to be made on the real ids'''
|
||||
|
@ -1406,7 +1395,6 @@ class calendar_event(osv.Model):
|
|||
|
||||
context = context or {}
|
||||
|
||||
|
||||
if isinstance(ids, (str, int, long)):
|
||||
if len(str(ids).split('-')) == 1:
|
||||
ids = [int(ids)]
|
||||
|
@ -1643,6 +1631,7 @@ class ir_http(osv.AbstractModel):
|
|||
raise BadRequest(error_message)
|
||||
return True
|
||||
|
||||
|
||||
class invite_wizard(osv.osv_memory):
|
||||
_inherit = 'mail.wizard.invite'
|
||||
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
<record id="calendar_event_1" model="calendar.event">
|
||||
<field eval="1" name="active"/>
|
||||
<field name="user_id" ref="base.user_root"/>
|
||||
<field name="partner_ids" eval="[(6,0,[ref('base.partner_root'),ref('base.res_partner_1'),ref('base.res_partner_6')])]"/>
|
||||
<field name="partner_ids" eval="[(6,0,[ref('base.res_partner_6')])]"/>
|
||||
<field name="name">Follow-up for Project proposal</field>
|
||||
<field name="description">Meeting to discuss project plan and hash out the details of implementation.</field>
|
||||
<field eval="time.strftime('%Y-%m-03 10:20:00')" name="date"/>
|
||||
|
|
|
@ -1,10 +1,13 @@
|
|||
openerp.calendar = function(instance) {
|
||||
var _t = instance.web._t;
|
||||
var QWeb = instance.web.qweb;
|
||||
|
||||
instance.calendar = {};
|
||||
|
||||
|
||||
instance.web.WebClient = instance.web.WebClient.extend({
|
||||
|
||||
|
||||
get_notif_box: function(me) {
|
||||
return $(me).closest(".ui-notify-message-style");
|
||||
},
|
||||
|
@ -55,7 +58,7 @@ openerp.calendar = function(instance) {
|
|||
check_notifications: function() {
|
||||
var self= this;
|
||||
self.get_next_notif();
|
||||
setInterval(function(){
|
||||
self.intervalNotif = setInterval(function(){
|
||||
self.get_next_notif();
|
||||
}, 5 * 60 * 1000 );
|
||||
},
|
||||
|
@ -65,6 +68,11 @@ openerp.calendar = function(instance) {
|
|||
this._super();
|
||||
this.check_notifications();
|
||||
},
|
||||
//Override addons/web/static/src/js/chrome.js
|
||||
on_logout: function() {
|
||||
this._super();
|
||||
clearInterval(self.intervalNotif);
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
|
|
|
@ -23,9 +23,7 @@ from openerp.osv import fields, osv
|
|||
import logging
|
||||
_logger = logging.getLogger(__name__)
|
||||
|
||||
#
|
||||
# calendar.event is defined in module calendar
|
||||
#
|
||||
|
||||
class calendar_event(osv.Model):
|
||||
""" Model for Calendar Event """
|
||||
_inherit = 'calendar.event'
|
||||
|
|
|
@ -21,23 +21,15 @@
|
|||
|
||||
import operator
|
||||
import simplejson
|
||||
import re
|
||||
import urllib
|
||||
import warnings
|
||||
|
||||
from openerp import tools
|
||||
from openerp import SUPERUSER_ID
|
||||
from openerp.tools.translate import _
|
||||
|
||||
from openerp.addons.web.http import request
|
||||
import werkzeug.utils
|
||||
|
||||
from datetime import datetime, timedelta, date
|
||||
from datetime import datetime, timedelta
|
||||
from dateutil import parser
|
||||
import pytz
|
||||
from openerp.osv import fields, osv
|
||||
from openerp.osv import osv
|
||||
from collections import namedtuple
|
||||
|
||||
import logging
|
||||
_logger = logging.getLogger(__name__)
|
||||
|
@ -63,9 +55,11 @@ class Meta(type):
|
|||
methods['__getitem__'] = getattr
|
||||
return type.__new__(typ, name, parents, methods)
|
||||
|
||||
|
||||
class Struct(object):
|
||||
__metaclass__ = Meta
|
||||
|
||||
|
||||
class OpenerpEvent(Struct):
|
||||
event = False
|
||||
found = False
|
||||
|
@ -77,6 +71,7 @@ class OpenerpEvent(Struct):
|
|||
attendee_id = False
|
||||
synchro = False
|
||||
|
||||
|
||||
class GmailEvent(Struct):
|
||||
event = False
|
||||
found = False
|
||||
|
@ -85,6 +80,7 @@ class GmailEvent(Struct):
|
|||
update = False
|
||||
status = False
|
||||
|
||||
|
||||
class SyncEvent(object):
|
||||
def __init__(self):
|
||||
self.OE = OpenerpEvent()
|
||||
|
@ -110,7 +106,6 @@ class SyncEvent(object):
|
|||
tmpSrc = 'OE'
|
||||
assert tmpSrc in ['GG', 'OE']
|
||||
|
||||
|
||||
#if self.OP.action == None:
|
||||
if self[tmpSrc].isRecurrence:
|
||||
if self[tmpSrc].status:
|
||||
|
@ -119,11 +114,9 @@ class SyncEvent(object):
|
|||
self.OP = Exclude(tmpSrc, 'Need to Exclude (Me = First event from recurrence) from recurrence')
|
||||
|
||||
elif self[tmpSrc].isInstance:
|
||||
self.OP= Update(tmpSrc, 'Only need to update, because already an exclu');
|
||||
self.OP = Update(tmpSrc, 'Only need to update, because already an exclu')
|
||||
else:
|
||||
self.OP = Update(tmpSrc, 'Simply Update... I\'m a single event');
|
||||
#end-if self.OP.action == None:
|
||||
|
||||
self.OP = Update(tmpSrc, 'Simply Update... I\'m a single event')
|
||||
else:
|
||||
if not self.OE.synchro or self.OE.synchro.split('.')[0] < self.OE.update.split('.')[0]:
|
||||
self.OP = Update('OE', 'Event already updated by another user, but not synchro with my google calendar')
|
||||
|
@ -131,7 +124,7 @@ class SyncEvent(object):
|
|||
else:
|
||||
self.OP = NothingToDo("", 'Not update needed')
|
||||
else:
|
||||
self.OP = NothingToDo("", "Both are already deleted");
|
||||
self.OP = NothingToDo("", "Both are already deleted")
|
||||
|
||||
# New in openERP... Create on create_events of synchronize function
|
||||
elif self.OE.found and not self.GG.found:
|
||||
|
@ -189,14 +182,23 @@ class SyncOperation(object):
|
|||
def __str__(self):
|
||||
return 'in__STR__'
|
||||
|
||||
|
||||
class Create(SyncOperation):
|
||||
pass
|
||||
|
||||
|
||||
class Update(SyncOperation):
|
||||
pass
|
||||
|
||||
|
||||
class Delete(SyncOperation):
|
||||
pass
|
||||
|
||||
|
||||
class NothingToDo(SyncOperation):
|
||||
pass
|
||||
|
||||
|
||||
class Exclude(SyncOperation):
|
||||
pass
|
||||
|
||||
|
@ -285,7 +287,6 @@ class google_calendar(osv.AbstractModel):
|
|||
'access_token': token,
|
||||
'maxResults': 1000,
|
||||
'timeMin': self.get_start_time_to_synchro(cr, uid, context=context).strftime("%Y-%m-%dT%H:%M:%S.%fz"),
|
||||
|
||||
}
|
||||
headers = {'Content-type': 'application/json', 'Accept': 'text/plain'}
|
||||
|
||||
|
@ -439,14 +440,9 @@ class google_calendar(osv.AbstractModel):
|
|||
return res
|
||||
|
||||
def synchronize_events(self, cr, uid, ids, context=None):
|
||||
gc_obj = self.pool['google.calendar']
|
||||
|
||||
# Create all new events from OpenERP into Gmail, if that is not recurrent event
|
||||
self.create_new_events(cr, uid, context=context)
|
||||
|
||||
self.bind_recurring_events_to_google(cr, uid, context)
|
||||
|
||||
|
||||
res = self.update_events(cr, uid, context)
|
||||
|
||||
return {
|
||||
|
@ -455,7 +451,6 @@ class google_calendar(osv.AbstractModel):
|
|||
}
|
||||
|
||||
def create_new_events(self, cr, uid, context=None):
|
||||
gc_pool = self.pool['google.calendar']
|
||||
ev_obj = self.pool['calendar.event']
|
||||
att_obj = self.pool['calendar.attendee']
|
||||
user_obj = self.pool['res.users']
|
||||
|
@ -505,7 +500,7 @@ class google_calendar(osv.AbstractModel):
|
|||
|
||||
if new_google_internal_event_id:
|
||||
#TODO WARNING, NEED TO CHECK THAT EVENT and ALL instance NOT DELETE IN GMAIL BEFORE !
|
||||
res = self.update_recurrent_event_exclu(cr, uid,new_google_internal_event_id, source_attendee_record.google_internal_event_id,att.event_id, context=context)
|
||||
self.update_recurrent_event_exclu(cr, uid, new_google_internal_event_id, source_attendee_record.google_internal_event_id, att.event_id, context=context)
|
||||
att_obj.write(cr, uid, [att.id], {'google_internal_event_id': new_google_internal_event_id}, context=context)
|
||||
cr.commit()
|
||||
|
||||
|
@ -583,7 +578,6 @@ class google_calendar(osv.AbstractModel):
|
|||
for current_event in event_to_synchronize[base_event]:
|
||||
event_to_synchronize[base_event][current_event].compute_OP()
|
||||
#print event_to_synchronize[base_event]
|
||||
#print "========================================================"
|
||||
|
||||
######################
|
||||
# DO ACTION #
|
||||
|
@ -593,13 +587,9 @@ class google_calendar(osv.AbstractModel):
|
|||
for current_event in event_to_synchronize[base_event]:
|
||||
cr.commit()
|
||||
event = current_event[1] # event is an Sync Event !
|
||||
|
||||
actToDo = event.OP
|
||||
actSrc = event.OP.src
|
||||
|
||||
# if not isinstance(actToDo, NothingToDo):
|
||||
# print event
|
||||
|
||||
context['curr_attendee'] = event.OE.attendee_id
|
||||
|
||||
if isinstance(actToDo, NothingToDo):
|
||||
|
@ -647,7 +637,6 @@ class google_calendar(osv.AbstractModel):
|
|||
calendar_event.unlink(cr, uid, event.OE.event_id, unlink_level=0, context=context)
|
||||
return True
|
||||
|
||||
|
||||
def check_and_sync(self, cr, uid, oe_event, google_event, context):
|
||||
if datetime.strptime(oe_event.oe_update_date, "%Y-%m-%d %H:%M:%S.%f") > datetime.strptime(google_event['updated'], "%Y-%m-%dT%H:%M:%S.%fz"):
|
||||
self.update_to_google(cr, uid, oe_event, google_event, context)
|
||||
|
@ -685,7 +674,6 @@ class google_calendar(osv.AbstractModel):
|
|||
current_user = self.pool['res.users'].browse(cr, uid, uid, context=context)
|
||||
gs_pool = self.pool['google.service']
|
||||
|
||||
refresh = current_user.google_calendar_rtoken
|
||||
all_token = gs_pool._refresh_google_token_json(cr, uid, current_user.google_calendar_rtoken, self.STR_SERVICE, context=context)
|
||||
|
||||
vals = {}
|
||||
|
@ -696,7 +684,7 @@ class google_calendar(osv.AbstractModel):
|
|||
|
||||
def need_authorize(self, cr, uid, context=None):
|
||||
current_user = self.pool['res.users'].browse(cr, uid, uid, context=context)
|
||||
return current_user.google_calendar_rtoken == False
|
||||
return current_user.google_calendar_rtoken is False
|
||||
|
||||
def get_calendar_scope(self, RO=False):
|
||||
readonly = RO and '.readonly' or ''
|
||||
|
@ -728,6 +716,7 @@ class google_calendar(osv.AbstractModel):
|
|||
# WILL BE AN IR CONFIG PARAMETER - beginning from SAAS4
|
||||
return True
|
||||
|
||||
|
||||
class res_users(osv.Model):
|
||||
_inherit = 'res.users'
|
||||
|
||||
|
@ -773,7 +762,6 @@ class calendar_attendee(osv.Model):
|
|||
'google_internal_event_id': fields.char('Google Calendar Event Id', size=256),
|
||||
'oe_synchro_date': fields.datetime('OpenERP Synchro Date'),
|
||||
}
|
||||
|
||||
_sql_constraints = [('google_id_uniq', 'unique(google_internal_event_id,partner_id,event_id)', 'Google ID should be unique!')]
|
||||
|
||||
def write(self, cr, uid, ids, vals, context=None):
|
||||
|
@ -787,5 +775,4 @@ class calendar_attendee(osv.Model):
|
|||
# Except if it come from an update_from_google
|
||||
if not context.get('curr_attendee', False) and not context.get('NewMeeting', False):
|
||||
self.pool['calendar.event'].write(cr, uid, ref, {'oe_update_date': datetime.now()}, context)
|
||||
|
||||
return super(calendar_attendee, self).write(cr, uid, ids, vals, context=context)
|
Loading…
Reference in New Issue