Ejemplo n.º 1
0
 def one_category_with_weight_multiple_votes_and_teams_test(self):
     from datetime import datetime
     from votingmachine.views import results_view
     from votingmachine.models import VotingBooth
     from votingmachine.models import TeamFolder
     from votingmachine.models import Team
     request = testing.DummyRequest()
     context = VotingBooth(
         'Test Voting Booth',
         datetime(2011, 10, 5, 19, 0, 15, 0),
         datetime(2011, 10, 6, 19, 0, 15, 0),
         [{'vote_category': 'One Category', 'weight': '0.5'}],
     )
     context['teams'] = TeamFolder()
     context['teams'].add_team(Team('Team Zero'))
     context['teams'].add_team(Team('Team One'))
     context.results = {
         'foo': [
             {'team_hidden': '0', 'rankings': {'One Category': '3'}},
             {'team_hidden': '1', 'rankings': {'One Category': '1'}},
         ],
     }
     results = results_view(context, request)
     tools.assert_equal(len(results['scores']), 2)
     tools.assert_equal(results['scores'][0][0].title, 'Team Zero')
     tools.assert_equal(results['scores'][0][1], 1.5)
     tools.assert_equal(results['scores'][1][0].title, 'Team One')
     tools.assert_equal(results['scores'][1][1], 0.5)
Ejemplo n.º 2
0
 def multiple_categories_multiple_votes_test(self):
     from datetime import datetime
     from votingmachine.views import results_view
     from votingmachine.models import VotingBooth
     from votingmachine.models import TeamFolder
     from votingmachine.models import Team
     request = testing.DummyRequest()
     context = VotingBooth(
         'Test Voting Booth',
         datetime(2011, 10, 5, 19, 0, 15, 0),
         datetime(2011, 10, 6, 19, 0, 15, 0),
         [
             {'vote_category': 'One Category', 'weight': '1.0'},
             {'vote_category': 'Two Category', 'weight': '0.5'},
         ],
     )
     context['teams'] = TeamFolder()
     context['teams'].add_team(Team('Team Zero'))
     context.results = {
         'foo': [{'team_hidden': '0', 'rankings': {
             'One Category': '3', 'Two Category': '2'}},
         ],
         'foo1': [{'team_hidden': '0', 'rankings': {
             'One Category': '2', 'Two Category': '2'}},
         ],
         'foo2': [{'team_hidden': '0', 'rankings': {
             'One Category': '1', 'Two Category': '1'}},
         ]
     }
     results = results_view(context, request)
     tools.assert_equal(results['scores'][0][0].title, 'Team Zero')
     # Three votes total
     tools.assert_equal(results['scores'][0][1], 8.5 / 3)
Ejemplo n.º 3
0
def add_voting_booth(context, request):
    logged_in = authenticated_userid(request)
    schema = VotingBoothSchema()
    form = Form(schema, buttons=("submit",))
    css_resources, js_resources = _form_resources(form)
    if "submit" in request.POST:
        controls = request.POST.items()
        try:
            form.validate(controls)
        except (ValidationFailure,), e:
            return {
                "form": e.render(),
                "css_resources": css_resources,
                "js_resources": js_resources,
                "logged_in": logged_in,
            }
        values = parse(request.params.items())
        start, end = _process_dates(values)
        voting_booth = VotingBooth(title=values["title"], start=start, end=end, categories=values["categories"])
        voting_booth.__parent__ = context
        # maybe this should be done in the team add view?
        team_folder = TeamFolder()
        team_folder.__parent__ = voting_booth
        team_folder.__name__ = "teams"
        voting_booth["teams"] = team_folder
        context.add_booth(voting_booth)
        return HTTPFound(location=request.resource_url(voting_booth))