diff options
| author | Thibault Delavallée <tde@openerp.com> | 2012-03-07 16:34:45 +0100 |
|---|---|---|
| committer | Thibault Delavallée <tde@openerp.com> | 2012-03-07 16:34:45 +0100 |
| commit | 4e60bfccc552eaa9247efb0e7be607e7a56be9cf (patch) | |
| tree | 3555fa2b863f5433ee9a603941ed7682dc8a520b | |
| parent | 3b71800294ef102edc1f646ac5f722eec6618485 (diff) | |
[ADD] mail.group: added photo and photo_mini
bzr revid: tde@openerp.com-20120307153445-2nrgdod40fuikldw
| -rw-r--r-- | addons/mail/mail_group.py | 30 | ||||
| -rw-r--r-- | addons/mail/mail_group_view.xml | 18 |
2 files changed, 38 insertions, 10 deletions
diff --git a/addons/mail/mail_group.py b/addons/mail/mail_group.py index 7be931d7e34..217b145e451 100644 --- a/addons/mail/mail_group.py +++ b/addons/mail/mail_group.py @@ -24,6 +24,9 @@ from osv import osv from osv import fields from tools.translate import _ +import io, StringIO +from PIL import Image + class mail_group(osv.osv): """ A mail_group is a collection of users sharing messages in a discussion group. @@ -48,15 +51,36 @@ class mail_group(osv.osv): return True - def action_null(self, cr, uid, ids, 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 _set_photo_mini(self, cr, uid, id, name, value, args, context=None): + self.write(cr, uid, [id], {'photo': value}, context=context) return True _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), - 'public': fields.boolean('Public', help='This group is visible by non members') + 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", + store = { + 'mail.group': (lambda self, cr, uid, ids, c={}: ids, ['photo'], 10), + }), } _defaults = { diff --git a/addons/mail/mail_group_view.xml b/addons/mail/mail_group_view.xml index 741d25c5932..f48ae653bfb 100644 --- a/addons/mail/mail_group_view.xml +++ b/addons/mail/mail_group_view.xml @@ -38,18 +38,22 @@ <field name="priority" eval="10"/> <field name="arch" type="xml"> <form string="Group"> - <field name="name" colspan="2"/> - <field name="responsible_id" colspan="2"/> - <newline/> - <field name="description" colspan="4"/> - <newline/> + <group colspan="4" col="4"> + <group colspan="3" col="4"> + <field name="name" colspan="2"/> + <field name="responsible_id" colspan="2"/> + <newline/> + <field name="description" colspan="4"/> + </group> + <group colspan="1" col="2"> + <field name="photo_mini" widget='image' nolabel="1"/> + </group> + </group> <separator string="Privacy settings" colspan="4"/> <group colspan="2" col="4"> <field name="public" nolabel="1" colspan="1"/> <label string="This group is visible by non members" colspan="2"/> </group> - <separator string="Test actions" colspan="4"/> - <button name="action_null" string="Test2" type="object" icon="gtk-go-forward" colspan="2"/> <field name="message_ids_social" colspan="4" widget="ThreadView" nolabel="1"/> </form> </field> |
