Single Option Services
Single Option services related to vote.
SingleOptionVoteService
Handle vote procedures like:
- perform a vote on a simple poll (one choice)
- calculate results on a simple poll
Source code in apps/votes_results/services/single_option_vote_service.py
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 | |
calculate_result(poll_id, user=None)
staticmethod
Calculate result of a poll.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
poll_id |
str
|
id of poll you want to calculate results |
required |
Raises:
| Type | Description |
|---|---|
PollDoesNotExistException
|
you tried to calculate results on a non-existent poll |
ResultsNotAvailableException
|
you tried to access results on a poll that are not available |
Returns:
| Name | Type | Description |
|---|---|---|
PollResult |
PollResult
|
results of the poll specified by id |
Source code in apps/votes_results/services/single_option_vote_service.py
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 | |
get_vote_by_id(vote_id)
staticmethod
Retrieve a vote by its ID
(temporary method! In future we will wanna use
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
vote_id |
str
|
id of the vote object you want to retrieve |
required |
Raises:
| Type | Description |
|---|---|
VoteDoesNotExistException
|
if vote does not exists |
Returns:
| Name | Type | Description |
|---|---|---|
VoteModel |
VoteModel
|
the vote object by the specified id |
Source code in apps/votes_results/services/single_option_vote_service.py
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 | |
perform_vote(poll_id, poll_choice_id)
staticmethod
Perform a vote on a survey.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
poll_id |
str
|
id of poll you want to vote |
required |
poll_choice_id |
str
|
the voted option |
required |
Raises:
| Type | Description |
|---|---|
PollDoesNotExistException
|
you tried to vote a not existent poll |
PollOptionUnvalidException
|
you tried to vote an unvalid option (id doesn't exists or it doesn't belong to this poll) |
Returns:
| Name | Type | Description |
|---|---|---|
vote |
VoteModel
|
the vote model of the result |
Source code in apps/votes_results/services/single_option_vote_service.py
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | |