diff --git a/addons/mail/mail_group.py b/addons/mail/mail_group.py index a213a6249d9..40c63268704 100644 --- a/addons/mail/mail_group.py +++ b/addons/mail/mail_group.py @@ -19,13 +19,16 @@ # ############################################################################## -import tools +import datetime as DT +import io +import openerp +import openerp.tools as tools from osv import osv from osv import fields -from tools.translate import _ - -import io, StringIO from PIL import Image +import StringIO +import tools +from tools.translate import _ class mail_group(osv.osv): """ @@ -43,28 +46,30 @@ class mail_group(osv.osv): def action_group_leave(self, cr, uid, ids, context={}): return self.message_unsubscribe(cr, uid, ids, context=context); - def onchange_photo_mini(self, cr, uid, ids, value, context=None): - return {'value': {'photo': value, 'photo_mini': self._photo_resize(cr, uid, value) } } + def onchange_photo(self, cr, uid, ids, value, context=None): + if not value: + return {'value': {'avatar_big': value, 'avatar': value} } + return {'value': {'photo_big': value, 'photo': self._photo_resize(cr, uid, value) } } - def _set_photo_mini(self, cr, uid, id, name, value, args, context=None): - self.write(cr, uid, [id], {'photo': value}, context=context) - return True + def _set_photo(self, cr, uid, id, name, value, args, context=None): + if value: + return self.write(cr, uid, [id], {'photo_big': value}, context=context) + else: + return self.write(cr, uid, [id], {'photo_big': value}, context=context) - def _photo_resize(self, cr, uid, photo, context=None): + def _photo_resize(self, cr, uid, photo, width=128, height=128, context=None): image_stream = io.BytesIO(photo.decode('base64')) img = Image.open(image_stream) - img.thumbnail((120, 100), Image.ANTIALIAS) + img.thumbnail((width, height), Image.ANTIALIAS) img_stream = StringIO.StringIO() img.save(img_stream, "JPEG") return img_stream.getvalue().encode('base64') - def _get_photo_mini(self, cr, uid, ids, name, args, context=None): - result = {} + def _get_photo(self, cr, uid, ids, name, args, context=None): + result = dict.fromkeys(ids, False) for group in self.browse(cr, uid, ids, context=context): - if not group.photo: - result[group.id] = False - else: - result[group.id] = self._photo_resize(cr, uid, group.photo, context=context) + if group.photo_big: + result[group.id] = self._photo_resize(cr, uid, group.photo_big, context=context) return result def is_subscriber(self, cr, uid, ids, name, args, context=None): @@ -73,16 +78,12 @@ class mail_group(osv.osv): result[id] = self.message_is_subscriber(cr, uid, [id], context=context) return result - def get_messages_nbr(self, cr, uid, ids, name, args, context=None): + def get_last_month_msg_nbr(self, cr, uid, ids, name, args, context=None): result = {} + message_obj = self.pool.get('mail.message') for id in ids: - result[id] = self.message_get_messages_nbr(cr, uid, [id], context=context) - return result - - def get_discussions_nbr(self, cr, uid, ids, name, args, context=None): - result = {} - for id in ids: - result[id] = self.message_get_discussions_nbr(cr, uid, [id], context=context) + lower_date = (DT.datetime.now() - DT.timedelta(days=30)).strftime(tools.DEFAULT_SERVER_DATE_FORMAT) + result[id] = message_obj.search(cr, uid, ['&', '&', ('model', '=', self._name), ('res_id', 'in', ids), ('date', '>=', lower_date)], count=True, context=context) return result def get_members_nbr(self, cr, uid, ids, name, args, context=None): @@ -90,27 +91,31 @@ class mail_group(osv.osv): for id in ids: result[id] = len(self.message_get_subscribers_ids(cr, uid, [id], context=context)) return result - + + def _get_default_photo(self, cr, uid, context=None): + avatar_path = openerp.modules.get_module_resource('mail', 'static/src/img', 'groupdefault.png') + return self._photo_resize(cr, uid, open(avatar_path, 'rb').read().encode('base64'), context=context) + _columns = { 'name': fields.char('Name', size=64, required=True), 'description': fields.text('Description'), 'responsible_id': fields.many2one('res.users', string='Responsible', ondelete='set null', required=True, select=1), 'public': fields.boolean('Public', help='This group is visible by non members'), - 'photo': fields.binary('Photo'), - 'photo_mini': fields.function(_get_photo_mini, fnct_inv=_set_photo_mini, string='Photo Mini', type="binary", + 'photo_big': fields.binary('Full-size photo', help='Field holding the full-sized PIL-supported and base64 encoded version of the group image. The photo field is used as an interface for this field.'), + 'photo': fields.function(_get_photo, fnct_inv=_set_photo, string='Photo', type="binary", store = { - 'mail.group': (lambda self, cr, uid, ids, c={}: ids, ['photo'], 10), - }), + 'mail.group': (lambda self, cr, uid, ids, c={}: ids, ['photo_big'], 10), + }, help='Field holding the automatically resized (128x128) PIL-supported and base64 encoded version of the group image.'), 'joined': fields.function(is_subscriber, type='boolean', string='Joined'), - 'messages_nbr': fields.function(get_messages_nbr, type='integer', string='Messages count'), - 'discussions_nbr': fields.function(get_discussions_nbr, type='integer', string='Discussions count'), + 'last_month_msg_nbr': fields.function(get_last_month_msg_nbr, type='integer', string='Messages count for last month'), 'members_nbr': fields.function(get_members_nbr, type='integer', string='Members count'), } _defaults = { 'public': True, 'responsible_id': (lambda s, cr, uid, ctx: uid), + 'photo': _get_default_photo, } mail_group() diff --git a/addons/mail/mail_group_view.xml b/addons/mail/mail_group_view.xml index 170b4765bde..975b3cfd9ac 100644 --- a/addons/mail/mail_group_view.xml +++ b/addons/mail/mail_group_view.xml @@ -26,15 +26,16 @@ @@ -60,7 +61,7 @@ - + diff --git a/addons/mail/static/src/css/mail_group.css b/addons/mail/static/src/css/mail_group.css index fad7b1a865d..90261499753 100644 --- a/addons/mail/static/src/css/mail_group.css +++ b/addons/mail/static/src/css/mail_group.css @@ -27,7 +27,7 @@ .oe_group_photo { width: 100px; height: auto; - clip: rect(10px, 100px, 110px, 0px); + clip: rect(0px, 100px, 100px, 0px); } .oe_group_photo_wide { @@ -44,6 +44,11 @@ min-height: 120px; } +.oe_group_details a, .oe_group_details a:hover { + font-weight: bold; + color: #4c4c4c; +} + .oe_group_details h4 { margin: 0; font-size: 13px; diff --git a/addons/mail/static/src/img/groupdefault.png b/addons/mail/static/src/img/groupdefault.png new file mode 100644 index 00000000000..fd826837266 Binary files /dev/null and b/addons/mail/static/src/img/groupdefault.png differ diff --git a/addons/mail/static/src/js/mail.js b/addons/mail/static/src/js/mail.js index d8792df0eda..a888f092fdc 100644 --- a/addons/mail/static/src/js/mail.js +++ b/addons/mail/static/src/js/mail.js @@ -549,6 +549,7 @@ openerp.mail = function(session) { /* DataSets */ this.ds_msg = new session.web.DataSet(this, 'mail.message'); this.ds_thread = new session.web.DataSet(this, 'mail.thread'); + this.ds_groups = new session.web.DataSet(this, 'mail.group'); this.ds_users = new session.web.DataSet(this, 'res.users'); }, @@ -749,7 +750,8 @@ openerp.mail = function(session) { */ do_comment: function () { var body_text = this.$element.find('textarea.oe_mail_wall_action_textarea').val(); - return this.ds_users.call('message_append_note', [[this.session.uid], 'Tweet', body_text, false, 'comment']).then(this.init_comments()); + return this.ds_thread.call('message_append_note', [[], 'Tweet', body_text, false, 'comment']).then(this.init_comments()); + //return this.ds_users.call('message_append_note', [[this.session.uid], 'Tweet', body_text, false, 'comment']).then(this.init_comments()); }, /**