From 69904e2036bcb30730f19ae871841a5e08004f26 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Tue, 13 Mar 2012 17:19:02 +0100 Subject: [PATCH] [IMP] mail.group: cleaned code; added user as default responsible when creating a group. bzr revid: tde@openerp.com-20120313161902-dwxzjy68bcuj39kk --- addons/mail/mail_group.py | 44 +++++++++++++++++++-------------- addons/mail/mail_group_view.xml | 2 +- 2 files changed, 26 insertions(+), 20 deletions(-) diff --git a/addons/mail/mail_group.py b/addons/mail/mail_group.py index 649701ff702..a213a6249d9 100644 --- a/addons/mail/mail_group.py +++ b/addons/mail/mail_group.py @@ -2,7 +2,7 @@ ############################################################################## # # OpenERP, Open Source Management Solution -# Copyright (C) 2010-2011 OpenERP SA () +# Copyright (C) 2010-today OpenERP SA () # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as @@ -29,9 +29,9 @@ from PIL import Image class mail_group(osv.osv): """ - A mail_group is a collection of users sharing messages in a discussion group. - Mail groups are different from user groups because they don't have a specific field holding users. - Group users are users that follow the mail group, using the subscription/follow mechanism of OpenChatter. + A mail_group is a collection of users sharing messages in a discussion + group. Group users are users that follow the mail group, using the + subscription/follow mechanism of OpenSocial. """ _name = 'mail.group' @@ -42,26 +42,31 @@ class mail_group(osv.osv): def action_group_leave(self, cr, uid, ids, context={}): return self.message_unsubscribe(cr, uid, ids, context=context); - - def _get_photo_mini(self, cr, uid, ids, name, args, context=None): - result = {} - for obj in self.browse(cr, uid, ids, context=context): - if not obj.photo: - result[obj.id] = False - continue - image_stream = io.BytesIO(obj.photo.decode('base64')) - img = Image.open(image_stream) - img.thumbnail((120, 100), Image.ANTIALIAS) - img_stream = StringIO.StringIO() - img.save(img_stream, "JPEG") - result[obj.id] = img_stream.getvalue().encode('base64') - return result + def onchange_photo_mini(self, cr, uid, ids, value, context=None): + return {'value': {'photo': value, 'photo_mini': 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 _photo_resize(self, cr, uid, photo, context=None): + image_stream = io.BytesIO(photo.decode('base64')) + img = Image.open(image_stream) + img.thumbnail((120, 100), 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 = {} + 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) + return result + def is_subscriber(self, cr, uid, ids, name, args, context=None): result = {} for id in ids: @@ -83,7 +88,7 @@ class mail_group(osv.osv): def get_members_nbr(self, cr, uid, ids, name, args, context=None): result = {} for id in ids: - result[id] = len(self._message_get_subscribers_ids(cr, uid, [id], context=context)) + result[id] = len(self.message_get_subscribers_ids(cr, uid, [id], context=context)) return result _columns = { @@ -105,6 +110,7 @@ class mail_group(osv.osv): _defaults = { 'public': True, + 'responsible_id': (lambda s, cr, uid, ctx: uid), } mail_group() diff --git a/addons/mail/mail_group_view.xml b/addons/mail/mail_group_view.xml index ce6c3b9eeef..59efecc97cf 100644 --- a/addons/mail/mail_group_view.xml +++ b/addons/mail/mail_group_view.xml @@ -60,7 +60,7 @@ - +