mirror of
https://github.com/GSA/notifications-api.git
synced 2025-12-23 08:51:30 -05:00
Move get_prev_next_pagination_links to utils
This will mean it can later be reused whereever we want
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
import itertools
|
import itertools
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
from flask import Blueprint, current_app, jsonify, request, url_for
|
from flask import Blueprint, current_app, jsonify, request
|
||||||
from notifications_utils.letter_timings import (
|
from notifications_utils.letter_timings import (
|
||||||
letter_can_be_cancelled,
|
letter_can_be_cancelled,
|
||||||
too_late_to_cancel_letter,
|
too_late_to_cancel_letter,
|
||||||
@@ -148,6 +148,7 @@ from app.user.users_schema import post_set_permissions_schema
|
|||||||
from app.utils import (
|
from app.utils import (
|
||||||
DATE_FORMAT,
|
DATE_FORMAT,
|
||||||
DATETIME_FORMAT_NO_TIMEZONE,
|
DATETIME_FORMAT_NO_TIMEZONE,
|
||||||
|
get_prev_next_pagination_links,
|
||||||
midnight_n_days_ago,
|
midnight_n_days_ago,
|
||||||
pagination_links,
|
pagination_links,
|
||||||
)
|
)
|
||||||
@@ -463,16 +464,6 @@ def get_all_notifications_for_service(service_id):
|
|||||||
error_out=False # False so that if there are no results, it doesn't end in aborting with a 404
|
error_out=False # False so that if there are no results, it doesn't end in aborting with a 404
|
||||||
)
|
)
|
||||||
|
|
||||||
def get_prev_next_pagination_links(current_page, next_page_exists, endpoint, **kwargs):
|
|
||||||
if 'page' in kwargs:
|
|
||||||
kwargs.pop('page', None)
|
|
||||||
links = {}
|
|
||||||
if page > 1:
|
|
||||||
links['prev'] = url_for(endpoint, page=page - 1, **kwargs)
|
|
||||||
if next_page_exists:
|
|
||||||
links['next'] = url_for(endpoint, page=page + 1, **kwargs)
|
|
||||||
return links
|
|
||||||
|
|
||||||
return jsonify(
|
return jsonify(
|
||||||
notifications=notifications,
|
notifications=notifications,
|
||||||
page_size=page_size,
|
page_size=page_size,
|
||||||
|
|||||||
11
app/utils.py
11
app/utils.py
@@ -29,6 +29,17 @@ def pagination_links(pagination, endpoint, **kwargs):
|
|||||||
return links
|
return links
|
||||||
|
|
||||||
|
|
||||||
|
def get_prev_next_pagination_links(current_page, next_page_exists, endpoint, **kwargs):
|
||||||
|
if 'page' in kwargs:
|
||||||
|
kwargs.pop('page', None)
|
||||||
|
links = {}
|
||||||
|
if current_page > 1:
|
||||||
|
links['prev'] = url_for(endpoint, page=current_page - 1, **kwargs)
|
||||||
|
if next_page_exists:
|
||||||
|
links['next'] = url_for(endpoint, page=current_page + 1, **kwargs)
|
||||||
|
return links
|
||||||
|
|
||||||
|
|
||||||
def url_with_token(data, url, config, base_url=None):
|
def url_with_token(data, url, config, base_url=None):
|
||||||
from notifications_utils.url_safe_token import generate_token
|
from notifications_utils.url_safe_token import generate_token
|
||||||
token = generate_token(data, config['SECRET_KEY'], config['DANGEROUS_SALT'])
|
token = generate_token(data, config['SECRET_KEY'], config['DANGEROUS_SALT'])
|
||||||
|
|||||||
Reference in New Issue
Block a user