[CLEAN] Cleaned code.
bzr revid: tde@openerp.com-20120402134354-v337jrlygvj2u2mw
This commit is contained in:
parent
a2e5f0b6c1
commit
6a56c8e8e1
|
@ -23,6 +23,7 @@ import datetime as DT
|
|||
import io
|
||||
import openerp
|
||||
import openerp.tools as tools
|
||||
from operator import itemgetter
|
||||
from osv import osv
|
||||
from osv import fields
|
||||
from PIL import Image
|
||||
|
@ -40,12 +41,6 @@ class mail_group(osv.osv):
|
|||
_description = 'Discussion group'
|
||||
_name = 'mail.group'
|
||||
_inherit = ['mail.thread']
|
||||
|
||||
def action_group_join(self, cr, uid, ids, context={}):
|
||||
return self.message_subscribe(cr, uid, ids, context=context);
|
||||
|
||||
def action_group_leave(self, cr, uid, ids, context={}):
|
||||
return self.message_unsubscribe(cr, uid, ids, context=context);
|
||||
|
||||
def onchange_photo(self, cr, uid, ids, value, context=None):
|
||||
if not value:
|
||||
|
@ -80,8 +75,8 @@ class mail_group(osv.osv):
|
|||
for id in ids:
|
||||
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']
|
||||
result[id]['member_count'] = len(result[id]['member_ids'])
|
||||
result[id]['is_subscriber'] = uid in result[id]['member_ids']
|
||||
return result
|
||||
|
||||
def search_member_ids(self, cr, uid, obj, name, args, context=None):
|
||||
|
@ -90,8 +85,7 @@ class mail_group(osv.osv):
|
|||
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)]
|
||||
return [('id', 'in', map(itemgetter('res_id'), subs))]
|
||||
|
||||
def get_last_month_msg_nbr(self, cr, uid, ids, name, args, context=None):
|
||||
result = {}
|
||||
|
@ -109,17 +103,18 @@ class mail_group(osv.osv):
|
|||
'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'),
|
||||
ondelete='set null', required=True, select=1,
|
||||
help="Responsible of the group that has all rights on the record."),
|
||||
'public': fields.boolean('Public', help='This group is visible by non members. Invisible groups can add members through the invite button.'),
|
||||
'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_big'], 10),
|
||||
}, help='Field holding the automatically resized (128x128) PIL-supported and base64 encoded version of the group image.'),
|
||||
'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'),
|
||||
relation='res.users', string='Group members', multi='get_member_ids'),
|
||||
'member_count': fields.function(get_member_ids, type='integer', string='Member count', multi='get_member_ids'),
|
||||
'is_subscriber': 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'),
|
||||
}
|
||||
|
||||
|
@ -128,5 +123,3 @@ class mail_group(osv.osv):
|
|||
'responsible_id': (lambda s, cr, uid, ctx: uid),
|
||||
'photo': _get_default_photo,
|
||||
}
|
||||
|
||||
mail_group()
|
||||
|
|
|
@ -17,18 +17,17 @@
|
|||
</div>
|
||||
</t>
|
||||
<t t-name="kanban-box">
|
||||
<div t-attf-class="{record.is_member.raw_value} oe_group_vignette">
|
||||
<div t-attf-class="{record.is_subscriber.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="is_member"/></span>
|
||||
<span style="display: none;"><field name="is_subscriber"/></span>
|
||||
<ul>
|
||||
<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="member_count"/> members</li>
|
||||
<li t-if="! record.is_subscriber.raw_value"><a name="message_subscribe" string="Join" type="object" class="oe_group_join">Not following</a></li>
|
||||
<li t-if="record.is_subscriber.raw_value"><a name="message_unsubscribe" string="Join" type="object" class="oe_group_leave">Following</a></li>
|
||||
<li><field name="last_month_msg_nbr"/> messages last month</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
@ -97,8 +96,8 @@
|
|||
<field name="priority" eval="10"/>
|
||||
<field name="arch" type="xml">
|
||||
<search string="Search groups">
|
||||
<field name="name" colspan="2"/>
|
||||
<field name="responsible_id" colspan="2"/>
|
||||
<field name="name"/>
|
||||
<field name="responsible_id"/>
|
||||
</search>
|
||||
</field>
|
||||
</record>
|
||||
|
|
Loading…
Reference in New Issue