[IMP] Updated group model and views: now has member_ids, is_member and member_nbr functional fields linked to one get function; necessary to use record rules later.
bzr revid: tde@openerp.com-20120329161000-084vqwoh05cxbvnb
This commit is contained in:
+22
-11
@@ -37,6 +37,7 @@ class mail_group(osv.osv):
|
||||
subscription/follow mechanism of OpenSocial.
|
||||
"""
|
||||
|
||||
_description = 'Discussion group'
|
||||
_name = 'mail.group'
|
||||
_inherit = ['mail.thread']
|
||||
|
||||
@@ -72,12 +73,26 @@ class mail_group(osv.osv):
|
||||
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):
|
||||
result = {}
|
||||
def get_member_ids(self, cr, uid, ids, field_names, args, context=None):
|
||||
if context is None:
|
||||
context = {}
|
||||
result = dict.fromkeys(ids)
|
||||
for id in ids:
|
||||
result[id] = self.message_is_subscriber(cr, uid, [id], context=context)
|
||||
result[id] = {}
|
||||
result[id]['member_ids'] = self.message_get_subscribers_ids(cr, uid, [id], context=context)
|
||||
result[id]['member_nbr'] = len(result[id]['member_ids'])
|
||||
result[id]['is_member'] = uid in result[id]['member_ids']
|
||||
return result
|
||||
|
||||
def search_member_ids(self, cr, uid, obj, name, args, context=None):
|
||||
if context is None:
|
||||
context = {}
|
||||
sub_obj = self.pool.get('mail.subscription')
|
||||
sub_ids = sub_obj.search(cr, uid, ['&', ('res_model', '=', obj._name), ('user_id', '=', args[0][2])], context=context)
|
||||
subs = sub_obj.read(cr, uid, sub_ids, context=context)
|
||||
obj_ids = [sub['res_id'] for sub in subs]
|
||||
return [('id', 'in', obj_ids)]
|
||||
|
||||
def get_last_month_msg_nbr(self, cr, uid, ids, name, args, context=None):
|
||||
result = {}
|
||||
message_obj = self.pool.get('mail.message')
|
||||
@@ -86,12 +101,6 @@ class mail_group(osv.osv):
|
||||
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):
|
||||
result = {}
|
||||
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)
|
||||
@@ -107,9 +116,11 @@ class mail_group(osv.osv):
|
||||
store = {
|
||||
'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'),
|
||||
'member_ids': fields.function(get_member_ids, fnct_search=search_member_ids, type='many2many',
|
||||
relation='res.users', string='Members', multi='get_member_ids'),
|
||||
'member_nbr': fields.function(get_member_ids, type='integer', string='Member count', multi='get_member_ids'),
|
||||
'is_member': fields.function(get_member_ids, type='boolean', string='Joined', multi='get_member_ids'),
|
||||
'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 = {
|
||||
|
||||
@@ -17,17 +17,18 @@
|
||||
</div>
|
||||
</t>
|
||||
<t t-name="kanban-box">
|
||||
<div t-attf-class="{record.joined.raw_value} oe_group_vignette">
|
||||
<div t-attf-class="{record.is_member.raw_value} oe_group_vignette">
|
||||
<div class="oe_group_image">
|
||||
<a type="edit"><img t-att-src="kanban_image('mail.group', 'photo', record.id.value)" class="oe_group_photo" tooltip="kanban-description"/></a>
|
||||
</div>
|
||||
<div class="oe_group_details">
|
||||
<h4><a type="edit"><field name="name"/></a></h4>
|
||||
<span style="display: none;"><field name="joined"/></span>
|
||||
<span style="display: none;"><field name="is_member"/></span>
|
||||
<ul>
|
||||
<li><field name="members_nbr"/> members</li>
|
||||
<li t-if="! record.joined.raw_value"><a name="action_group_join" string="Join" type="object" class="oe_group_join">Not following</a></li>
|
||||
<li t-if="record.joined.raw_value"><a name="action_group_leave" string="Join" type="object" class="oe_group_leave">Following</a></li>
|
||||
<li><field name="member_nbr"/> members</li>
|
||||
<li><t t-esc="record.is_member"></t></li>
|
||||
<li t-if="! record.is_member.raw_value"><a name="action_group_join" string="Join" type="object" class="oe_group_join">Not following</a></li>
|
||||
<li t-if="record.is_member.raw_value"><a name="action_group_leave" string="Join" type="object" class="oe_group_leave">Following</a></li>
|
||||
<li><field name="last_month_msg_nbr"/> messages last month</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user