Poll service (get all, delete)
Other CRUD options on polls.
PollService
Class to handle all poll related operations
Source code in apps/polls_management/services/poll_service.py
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 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 | |
close_poll(id)
staticmethod
Close a poll by id. If a poll has already been closed, it can't be closed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
id |
str
|
Id of the poll to close. The poll can be a majority poll or a single option poll. |
required |
Raises:
| Type | Description |
|---|---|
PollDoesNotExistException
|
If the poll not exist. |
PollIsCloseException
|
If the poll is already close. |
Returns:
| Name | Type | Description |
|---|---|---|
poll | the closed poll. |
Source code in apps/polls_management/services/poll_service.py
173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 | |
create(name, question, options, user)
staticmethod
Creates a new poll.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name |
str
|
Name of the poll. It has to be at least 1 characters long. |
required |
question |
str
|
Question of the poll. It has to be at least 1 characters long. |
required |
options |
List[str]
|
List of options for the poll. It has to have at least 1 option. |
required |
Raises:
| Type | Description |
|---|---|
PollNotValidCreationException
|
Is raised when the poll is not valid. When the input params not meet the requirements. |
Returns:
| Name | Type | Description |
|---|---|---|
new_poll |
PollModel
|
The created poll. |
Source code in apps/polls_management/services/poll_service.py
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | |
delete_poll(id)
staticmethod
Delete a poll by id. If a poll has already been opened, it can't be deleted.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
id |
str
|
Id of the poll to delete. The poll can be a majority poll or a single option poll. |
required |
Raises:
| Type | Description |
|---|---|
PollDoesNotExistException
|
If the poll not exist. |
PollIsOpenException
|
If the poll is open. |
Returns:
| Name | Type | Description |
|---|---|---|
Tuple | A tuple with first element the total number of deletions made |
|
and the second element a dict with the relative details about deletion from the model perspective. |
Example
{3, {'polls.PollModel': 1, 'polls.PollOptionModel': 2}}
Source code in apps/polls_management/services/poll_service.py
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 | |
get_paginated_polls(page_size=10)
staticmethod
Get a paginated list of polls. The page size is 10 by default.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
page_size |
int
|
Number of polls per page. It has to be al least 1. By default is 10. |
10
|
Raises:
| Type | Description |
|---|---|
PaginatorPageSizeException
|
raised when the page size is not valid. When the page size is less than 1. |
Returns:
| Name | Type | Description |
|---|---|---|
paginator |
Paginator
|
A paginator object with the polls. |
Source code in apps/polls_management/services/poll_service.py
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 | |
get_poll_by_id(id)
staticmethod
Get a poll by id.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
id |
str
|
Id of the poll. |
required |
Raises:
| Type | Description |
|---|---|
PollDoesNotExistException
|
raised when you retrieve a non-existent poll. |
Returns:
| Name | Type | Description |
|---|---|---|
poll |
PollModel
|
poll object. |
Source code in apps/polls_management/services/poll_service.py
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 | |
open_poll(id)
staticmethod
Open a poll by id. If a poll has already been opened, it can't be opened.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
id |
str
|
Id of the poll to open. The poll can be a majority poll or a single option poll. |
required |
Raises:
| Type | Description |
|---|---|
PollDoesNotExistException
|
If the poll not exist. |
PollIsOpenException
|
If the poll is already open. |
PollCannotBeOpenedException
|
If the poll open and close time is not valid. |
Returns:
| Name | Type | Description |
|---|---|---|
poll | the opened poll. |
Source code in apps/polls_management/services/poll_service.py
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 | |
user_polls(user)
staticmethod
Method used to return a list of user polls.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user |
User
|
the user who is the author of the polls. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
user_poll_list |
List[PollModel]
|
list of user polls. |
Source code in apps/polls_management/services/poll_service.py
144 145 146 147 148 149 150 151 152 153 154 155 156 157 | |
votable_or_closed_polls()
staticmethod
Returns a list of votable or closed polls. The polls retuned are public by default.
Returns:
| Type | Description |
|---|---|
List[PollModel]
|
List of votable/closed polls. |
Source code in apps/polls_management/services/poll_service.py
159 160 161 162 163 164 165 166 167 168 169 170 171 | |