Skip to content
This repository has been archived by the owner on Oct 28, 2020. It is now read-only.

Commit

Permalink
[fix bug 1173175] Do not assign action items to people who already vo…
Browse files Browse the repository at this point in the history
…ted.
  • Loading branch information
akatsoulas committed Jun 10, 2015
1 parent a5219c4 commit f44a27e
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
18 changes: 18 additions & 0 deletions remo/dashboard/tests/test_models.py
Expand Up @@ -403,6 +403,24 @@ def test_update_valid_groups(self):
for user in council.user_set.all():
ok_(not items.filter(user=user).exists())

def test_user_has_already_voted(self):
model = ContentType.objects.get_for_model(Poll)
items = ActionItem.objects.filter(content_type=model)
ok_(not items.exists())

council = Group.objects.get(name='Admin')
user = UserFactory.create(groups=['Admin'])

start = now() - timedelta(hours=3)
poll = PollFactory.create(valid_groups=council,
end=now() - timedelta(days=1),
start=start)
VoteFactory.create(poll=poll, user=user)
create_poll_action_items()

items = ActionItem.objects.filter(content_type=model)
eq_(items.count(), 0)


class EventActionItems(RemoTestCase):
def test_post_event_metrics(self):
Expand Down
8 changes: 6 additions & 2 deletions remo/voting/models.py
Expand Up @@ -124,7 +124,11 @@ def get_action_items(self):
name = u'{0} {1}'.format(VOTE_ACTION, self.name)
priority = ActionItem.NORMAL

for user in User.objects.filter(groups=self.valid_groups):
# Exclude the users that already have voted
users = (User.objects.filter(groups=self.valid_groups)
.exclude(pk__in=self.vote_set.values_list('user',
flat=True)))
for user in users:
action_item = Item(name, user, priority, due_date)
action_items.append(action_item)

Expand All @@ -133,7 +137,7 @@ def get_action_items(self):

class Vote(models.Model):
"""Vote model."""
user = models.ForeignKey(User)
user = models.ForeignKey(User, related_name='votes')
poll = models.ForeignKey(Poll)
date_voted = models.DateField(auto_now_add=True)

Expand Down

0 comments on commit f44a27e

Please sign in to comment.