[CLEAN] mail: vote: cleaned before merging.
bzr revid: tde@openerp.com-20120918150544-2pgwh1mhi5yyqi22
This commit is contained in:
parent
2ae49751eb
commit
2183358164
|
@ -130,7 +130,8 @@ class mail_message(osv.Model):
|
|||
'unread': fields.function(_get_unread, fnct_search=_search_unread,
|
||||
type='boolean', string='Unread',
|
||||
help='Functional field to search for unread messages linked to uid'),
|
||||
'vote_user_ids': fields.many2many('res.users', 'mail_vote', 'message_id', 'user_id', 'Votes'),
|
||||
'vote_user_ids': fields.many2many('res.users', 'mail_vote', 'message_id', 'user_id', string='Votes',
|
||||
help='Users that voted for this message'),
|
||||
}
|
||||
|
||||
def _needaction_domain_get(self, cr, uid, context=None):
|
||||
|
@ -153,19 +154,16 @@ class mail_message(osv.Model):
|
|||
#------------------------------------------------------
|
||||
|
||||
def vote_toggle(self, cr, uid, ids, user_ids=None, context=None):
|
||||
'''
|
||||
Toggles when Comment is liked or unlike.
|
||||
create vote entries if current user like comment..
|
||||
'''
|
||||
''' Toggles voting '''
|
||||
if not user_ids:
|
||||
user_ids = [uid]
|
||||
for message in self.read(cr, uid, ids, ['vote_user_ids'], context=context):
|
||||
for user_id in user_ids:
|
||||
has_voted = user_id in message['vote_user_ids']
|
||||
has_voted = user_id in message.get('vote_user_ids')
|
||||
if not has_voted:
|
||||
self.write(cr, uid, ids, {'vote_user_ids': [(4, user_id)]}, context=context)
|
||||
self.write(cr, uid, message.get('id'), {'vote_user_ids': [(4, user_id)]}, context=context)
|
||||
else:
|
||||
self.write(cr, uid, ids, {'vote_user_ids': [(3, user_id)]}, context=context)
|
||||
self.write(cr, uid, message.get('id'), {'vote_user_ids': [(3, user_id)]}, context=context)
|
||||
return True
|
||||
|
||||
#------------------------------------------------------
|
||||
|
@ -174,11 +172,10 @@ class mail_message(osv.Model):
|
|||
|
||||
def _message_dict_get(self, cr, uid, msg, context=None):
|
||||
""" Return a dict representation of the message browse record. """
|
||||
vote_pool = self.pool.get('mail.vote')
|
||||
has_voted = False
|
||||
vote_ids = self.pool.get('res.users').name_get(cr, uid, [user.id for user in msg.vote_user_ids], context=context)
|
||||
for user_id in msg.vote_user_ids:
|
||||
if (user_id.id == uid):
|
||||
for vote in vote_ids:
|
||||
if vote[0] == uid:
|
||||
has_voted = True
|
||||
break
|
||||
attachment_ids = [{'id': attach[0], 'name': attach[1]} for attach in self.pool.get('ir.attachment').name_get(cr, uid, [x.id for x in msg.attachment_ids], context=context)]
|
||||
|
|
|
@ -30,10 +30,10 @@ class mail_vote(osv.Model):
|
|||
_name = 'mail.vote'
|
||||
_description = 'Mail Vote'
|
||||
_columns = {
|
||||
'message_id': fields.many2one('mail.message', 'Message', required=True,
|
||||
select=1),
|
||||
'user_id': fields.many2one('res.users', 'User', required=True,
|
||||
select=1),
|
||||
'message_id': fields.many2one('mail.message', 'Message', select=1,
|
||||
ondelete='cascade', required=True),
|
||||
'user_id': fields.many2one('res.users', 'User', select=1,
|
||||
ondelete='cascade', required=True),
|
||||
}
|
||||
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||
|
|
Binary file not shown.
Before Width: | Height: | Size: 892 B |
|
@ -529,7 +529,7 @@ openerp.mail = function(session) {
|
|||
record.vote_user_ids.splice(idx, 1);
|
||||
}
|
||||
else {
|
||||
record.vote_user_ids.push([this.session.uid, 'Current user']);
|
||||
record.vote_user_ids.push([this.session.uid, 'You']);
|
||||
}
|
||||
record.has_voted = ! record.has_voted;
|
||||
var vote_element = session.web.qweb.render('mail.thread.message.vote', {'record': record});
|
||||
|
|
Loading…
Reference in New Issue