Poll Token Service
Services related to tokens generations and management.
PollTokenService
Service class for poll tokens management
Source code in apps/polls_management/services/poll_token_service.py
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 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 | |
available_token_list(poll)
staticmethod
Return a list of available tokens.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
poll |
PollModel
|
the poll the tokens belong to. |
required |
Returns:
| Type | Description |
|---|---|
List[PollTokens]
|
List of available token links. |
Source code in apps/polls_management/services/poll_token_service.py
120 121 122 123 124 125 126 127 128 129 130 131 132 133 | |
check_majority_option(token)
staticmethod
Make token for majority option as already used.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
token |
PollTokens
|
token model with all necessary information. |
required |
Source code in apps/polls_management/services/poll_token_service.py
109 110 111 112 113 114 115 116 117 118 | |
check_single_option(token)
staticmethod
Make token for single option as already used.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
token |
PollTokens
|
token model with all necessary information. |
required |
Source code in apps/polls_management/services/poll_token_service.py
98 99 100 101 102 103 104 105 106 107 | |
create_google_record(user, poll)
staticmethod
Creates an object PollTokens used to record a vote for a Google auth user.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user |
User
|
the user whose vote has to be recorded. |
required |
poll |
PollModel
|
the poll the tokens belong to. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
google_vote |
PollTokens
|
the token representing the user's vote with Google email. |
Source code in apps/polls_management/services/poll_token_service.py
164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 | |
create_tokens(token_number, poll)
staticmethod
Create tokens for the poll and store them in the database.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
token_number |
int
|
number of tokens to create. |
required |
poll |
PollModel
|
poll to assign tokens created. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
tokens |
List[PollTokens]
|
list of tokens created. |
Source code in apps/polls_management/services/poll_token_service.py
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 | |
delete_tokens(poll)
Delete tokens and related phantom users for the specified list.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
poll |
PollModel
|
the poll the tokens belong to. |
required |
Source code in apps/polls_management/services/poll_token_service.py
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 | |
get_poll_token_by_user(user)
staticmethod
Get a poll token by its user.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user |
User
|
user whom the token is assigned to. |
required |
Raises:
| Type | Description |
|---|---|
TokenDoesNotExistException
|
raised when you retrieve a non-existent token. |
Returns:
| Name | Type | Description |
|---|---|---|
poll_token |
PollTokens
|
token associated with the user. |
Source code in apps/polls_management/services/poll_token_service.py
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 | |
is_majority_token_used(token)
staticmethod
Check if a token is used for a majority poll.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
token |
PollTokens
|
token model with all necessary information. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
Bool indicating if token is used for a majority judgment poll or not. |
Source code in apps/polls_management/services/poll_token_service.py
83 84 85 86 87 88 89 90 91 92 93 94 95 96 | |
is_single_option_token_used(token)
staticmethod
Check if a token is used for a single option poll.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
token |
PollTokens
|
token model with all necessary information. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
Bool indicating if token is used for a single option poll or not. |
Source code in apps/polls_management/services/poll_token_service.py
68 69 70 71 72 73 74 75 76 77 78 79 80 81 | |
unavailable_token_list(poll)
staticmethod
Return a list of unavailable token links.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
poll |
PollModel
|
the poll the tokens belong to. |
required |
Returns:
| Type | Description |
|---|---|
List[PollTokens]
|
List of unavailable token links. |
Source code in apps/polls_management/services/poll_token_service.py
152 153 154 155 156 157 158 159 160 161 162 | |