Services
pagination_links(pagination, resource, **args)
The pagination_links function generates links for the pagination of a resource. It takes in a Pagination object and returns a dictionary with the keys "self", "first", "prev", "next" and "last". The values are links to the current page, the first page, the previous page if one exists, next page if it exists and last page respectively. If there is no previous or next page then None is returned.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
pagination |
Determine the number of items to show per page |
required | |
resource |
Determine the resource that is being paginated |
required | |
**args |
Allow the pagination_links function to accept any number of other parameters |
{}
|
Returns:
Type | Description |
---|---|
A dictionary of links that are used to navigate through a list of items |
Source code in services/pagination_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 |
|
pagination_meta(pagination)
The pagination_meta function takes a pagination object and returns a dictionary with the meta information about the pagination. The meta information includes: has_prev, has_next, page, total_pages, items_per_page and total.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
pagination |
Get the pagination object from the |
required |
Returns:
Type | Description |
---|---|
A dictionary containing the following data: |
Source code in services/pagination_service.py
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
|
send_async_email(app, msg)
The send_async_email function is a helper function that sends an email asynchronously. It takes in the application instance and the message to be sent, then uses the flask_mail library to send it.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
app |
Access the application instance for the |
required | |
msg |
Pass in the message that we want to send to our mail server |
required |
Returns:
Type | Description |
---|---|
None |
Source code in services/mail_service.py
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
|
send_email(subject, sender, recipients, text_body, html_body)
The send_email function sends an email to the specified recipients. It takes in a subject, sender, recipients (a list of strings), text_body and html_body.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
subject |
Set the subject of the email |
required | |
sender |
Specify the sender of the email |
required | |
recipients |
Specify the recipients of the email |
required | |
text_body |
Set the text body of the email, and html_body is used to set the html content of the email |
required | |
html_body |
Send html emails |
required |
Returns:
Type | Description |
---|---|
None |
Source code in services/mail_service.py
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
|