allura
Revisión | 62b22a6cb94bbf8bac34dff2a627f64542a3dac5 (tree) |
---|---|
Tiempo | 2012-07-18 04:25:22 |
Autor | Yuriy <yuriyarhipovua@yand...> |
Commiter | Cory Johns |
[#4481] ticket:103 Add votes
@@ -668,7 +668,7 @@ class VotableArtifact(MappedClass): | ||
668 | 668 | class __mongometa__: |
669 | 669 | session = main_orm_session |
670 | 670 | name = 'vote' |
671 | - | |
671 | + votes = FieldProperty(int, if_missing=0) | |
672 | 672 | votes_up = FieldProperty(int, if_missing=0) |
673 | 673 | votes_down = FieldProperty(int, if_missing=0) |
674 | 674 | votes_up_users = FieldProperty([str], if_missing=list()) |
@@ -683,6 +683,7 @@ class VotableArtifact(MappedClass): | ||
683 | 683 | self.votes_down = self.votes_down - 1 |
684 | 684 | self.votes_up_users.append(user.username) |
685 | 685 | self.votes_up += 1 |
686 | + self.votes += 1 | |
686 | 687 | |
687 | 688 | def vote_down(self, user): |
688 | 689 | if user.username in self.votes_down_users: |
@@ -693,6 +694,7 @@ class VotableArtifact(MappedClass): | ||
693 | 694 | self.votes_up = self.votes_up - 1 |
694 | 695 | self.votes_down_users.append(user.username) |
695 | 696 | self.votes_down += 1 |
697 | + self.votes -= 1 | |
696 | 698 | |
697 | 699 | def user_voted(self, user): |
698 | 700 | """Check that user voted for this artifact. |
@@ -276,6 +276,7 @@ class Ticket(VersionedArtifact, ActivityObject, VotableArtifact): | ||
276 | 276 | milestone_s=self.milestone, |
277 | 277 | status_s=self.status, |
278 | 278 | text=self.description, |
279 | + votes_i=self.votes, | |
279 | 280 | snippet_s=self.summary) |
280 | 281 | for k,v in self.custom_fields.iteritems(): |
281 | 282 | result[k + '_s'] = unicode(v) |
@@ -575,6 +576,7 @@ class Ticket(VersionedArtifact, ActivityObject, VotableArtifact): | ||
575 | 576 | assigned_to_id=self.assigned_to_id and str(self.assigned_to_id) or None, |
576 | 577 | status=self.status, |
577 | 578 | private=self.private, |
579 | + votes=self.votes, | |
578 | 580 | custom_fields=self.custom_fields) |
579 | 581 | |
580 | 582 | @classmethod |
@@ -604,6 +606,9 @@ class Ticket(VersionedArtifact, ActivityObject, VotableArtifact): | ||
604 | 606 | tickets.append(t) |
605 | 607 | else: |
606 | 608 | count = count -1 |
609 | + if c.app.config.options.get('EnableVoting'): | |
610 | + columns.append(dict(name='votes', sort_name='votes', label='Votes', active=True)) | |
611 | + | |
607 | 612 | return dict( |
608 | 613 | tickets=tickets, |
609 | 614 | count=count, q=json.dumps(query), limit=limit, page=page, sort=sort, |
@@ -324,6 +324,8 @@ def mongo_columns(): | ||
324 | 324 | for field in c.app.globals.sortable_custom_fields_shown_in_search(): |
325 | 325 | columns.append( |
326 | 326 | dict(name=field['name'], sort_name=field['name'], label=field['label'], active=True)) |
327 | + if c.app.config.options.get('EnableVoting'): | |
328 | + columns.append(dict(name='votes', sort_name='votes', label='Votes', active=True)) | |
327 | 329 | return columns |
328 | 330 | |
329 | 331 | def solr_columns(): |
@@ -334,6 +336,8 @@ def solr_columns(): | ||
334 | 336 | dict(name='assigned_to', sort_name='assigned_to_s', label='Owner', active=True)] |
335 | 337 | for field in c.app.globals.sortable_custom_fields_shown_in_search(): |
336 | 338 | columns.append(dict(name=field['name'], sort_name=field['sortable_name'], label=field['label'], active=True)) |
339 | + if c.app.config.options.get('EnableVoting'): | |
340 | + columns.append(dict(name='votes', sort_name='votes_i', label='Votes', active=True)) | |
337 | 341 | return columns |
338 | 342 | |
339 | 343 | class RootController(BaseController): |