[IMP] make post_ids field as function field in Tag object, store vote_count and user_vote in post.
bzr revid: tpa@tinyerp.com-20140311092517-om8d1bgt76b82al5
This commit is contained in:
parent
99de16334c
commit
777a5a3c8f
|
@ -293,35 +293,5 @@ Thank you in advance</field>
|
|||
<field name="parent_id" ref="question_13" />
|
||||
</record>
|
||||
|
||||
|
||||
<record id="tags_0" model="website.forum.tag">
|
||||
<field name="post_ids" eval="[(4,ref('website_forum.question_0'))]"/>
|
||||
</record>
|
||||
|
||||
<record id="tags_1" model="website.forum.tag">
|
||||
<field name="post_ids" eval="[(4,ref('website_forum.question_10')), (4,ref('website_forum.question_9'))]"/>
|
||||
</record>
|
||||
|
||||
<record id="tags_2" model="website.forum.tag">
|
||||
<field name="post_ids" eval="[(4,ref('website_forum.question_9'))]"/>
|
||||
</record>
|
||||
|
||||
<record id="tags_3" model="website.forum.tag">
|
||||
<field name="post_ids" eval="[(4,ref('website_forum.question_0'))]"/>
|
||||
</record>
|
||||
|
||||
<record id="tags_4" model="website.forum.tag">
|
||||
<field name="post_ids" eval="[(4,ref('website_forum.question_0'))]"/>
|
||||
</record>
|
||||
|
||||
<record id="tags_5" model="website.forum.tag">
|
||||
<field name="post_ids" eval="[(4,ref('website_forum.question_2'))]"/>
|
||||
</record>
|
||||
|
||||
<record id="tags_6" model="website.forum.tag">
|
||||
<field name="post_ids" eval="[(4,ref('website_forum.question_13'))]"/>
|
||||
</record>
|
||||
|
||||
|
||||
</data>
|
||||
</openerp>
|
||||
|
|
|
@ -88,6 +88,12 @@ class Post(osv.Model):
|
|||
res[post.id] -= 1
|
||||
return res
|
||||
|
||||
def _get_vote(self, cr, uid, ids, context=None):
|
||||
result = {}
|
||||
for vote in self.pool.get('website.forum.post.vote').browse(cr, uid, ids, context=context):
|
||||
result[vote.post_id.id] = True
|
||||
return result.keys()
|
||||
|
||||
_columns = {
|
||||
'name': fields.char('Title', size=128),
|
||||
'forum_id': fields.many2one('website.forum', 'Forum', required=True),
|
||||
|
@ -120,14 +126,23 @@ class Post(osv.Model):
|
|||
help="Comments on forum post",
|
||||
),
|
||||
|
||||
# TODO: add a store={} on those two fields. Why is it a boolean?
|
||||
'user_vote':fields.function(_get_votes, string="My Vote", type='boolean'),
|
||||
'user_vote':fields.function(_get_votes, string="My Vote", type='boolean',
|
||||
store={
|
||||
'website.forum.post': (lambda self, cr, uid, ids, c={}: ids, ['vote_ids'], 10),
|
||||
'website.forum.post.vote': (_get_vote, [], 10),
|
||||
}
|
||||
),
|
||||
|
||||
# TODO: add a store={} on those two fields
|
||||
'vote_count':fields.function(_get_vote_count, string="Votes", type='integer'),
|
||||
'vote_count':fields.function(_get_vote_count, string="Votes", type='integer',
|
||||
store={
|
||||
'website.forum.post': (lambda self, cr, uid, ids, c={}: ids, ['vote_ids'], 10),
|
||||
'website.forum.post.vote': (_get_vote, [], 10),
|
||||
}
|
||||
),
|
||||
}
|
||||
_defaults = {
|
||||
'state': 'active',
|
||||
'vote_count': 0,
|
||||
'active': True
|
||||
}
|
||||
|
||||
|
@ -296,8 +311,18 @@ class Tags(osv.Model):
|
|||
_name = "website.forum.tag"
|
||||
_description = "Tag"
|
||||
_inherit = ['website.seo.metadata']
|
||||
|
||||
def _get_questions(self, cr, uid, ids, field_name, arg, context=None):
|
||||
result = {}
|
||||
Post = self.pool['website.forum.post']
|
||||
for tag in ids:
|
||||
question_ids = Post.search(cr, uid , [('tags.id', '=', tag)], context=context)
|
||||
result[tag] = question_ids
|
||||
return result
|
||||
|
||||
_columns = {
|
||||
'name': fields.char('Name', size=64, required=True),
|
||||
'post_ids': fields.many2many('website.forum.post', 'forum_tag_que_rel', 'tag_id', 'forum_id', 'Questions', readonly=True),
|
||||
'forum_id': fields.many2one('website.forum', 'Forum', required=True)
|
||||
'forum_id': fields.many2one('website.forum', 'Forum', required=True),
|
||||
'post_ids': fields.function(_get_questions, type='many2many', relation="website.forum.post", string="Questions",
|
||||
),
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue