mirror of
https://github.com/GSA/notifications-api.git
synced 2025-12-23 00:41:35 -05:00
Includes:
- [x] https://github.com/alphagov/notifications-utils/pull/94 (breaking
changes which are responsible for all the changes to the API in
this PR)
The test for `get_sms_fragment_count` has been removed because this
method is already tested in utils here:
ac20f7e99e/tests/test_base_template.py (L140-L159)
29 lines
1.0 KiB
Python
29 lines
1.0 KiB
Python
from flask import url_for
|
|
from app.models import SMS_TYPE, EMAIL_TYPE
|
|
from notifications_utils.template import SMSMessageTemplate, PlainTextEmailTemplate
|
|
|
|
|
|
def pagination_links(pagination, endpoint, **kwargs):
|
|
if 'page' in kwargs:
|
|
kwargs.pop('page', None)
|
|
links = {}
|
|
if pagination.has_prev:
|
|
links['prev'] = url_for(endpoint, page=pagination.prev_num, **kwargs)
|
|
if pagination.has_next:
|
|
links['next'] = url_for(endpoint, page=pagination.next_num, **kwargs)
|
|
links['last'] = url_for(endpoint, page=pagination.pages, **kwargs)
|
|
return links
|
|
|
|
|
|
def url_with_token(data, url, config):
|
|
from notifications_utils.url_safe_token import generate_token
|
|
token = generate_token(data, config['SECRET_KEY'], config['DANGEROUS_SALT'])
|
|
base_url = config['ADMIN_BASE_URL'] + url
|
|
return base_url + token
|
|
|
|
|
|
def get_template_instance(template, values):
|
|
return {
|
|
SMS_TYPE: SMSMessageTemplate, EMAIL_TYPE: PlainTextEmailTemplate
|
|
}[template['template_type']](template, values)
|