Rename pagination args to pagination_opts

This commit is contained in:
richard-dds 2018-11-12 16:45:55 -05:00
parent 5b0383bde3
commit 4244ecf9b7
4 changed files with 15 additions and 13 deletions

View File

@ -8,9 +8,9 @@ class AuditEventQuery(Query):
model = AuditEvent model = AuditEvent
@classmethod @classmethod
def get_all(cls, pagination): def get_all(cls, pagination_opts):
query = db.session.query(cls.model).order_by(cls.model.time_created.desc()) query = db.session.query(cls.model).order_by(cls.model.time_created.desc())
return cls.paginate(query, pagination) return cls.paginate(query, pagination_opts)
class AuditLog(object): class AuditLog(object):
@ -29,11 +29,11 @@ class AuditLog(object):
return cls._log(resource=resource, action=action) return cls._log(resource=resource, action=action)
@classmethod @classmethod
def get_all_events(cls, user, pagination=None): def get_all_events(cls, user, pagination_opts=None):
Authorization.check_atat_permission( Authorization.check_atat_permission(
user, Permissions.VIEW_AUDIT_LOG, "view audit log" user, Permissions.VIEW_AUDIT_LOG, "view audit log"
) )
return AuditEventQuery.get_all(pagination) return AuditEventQuery.get_all(pagination_opts)
@classmethod @classmethod
def _resource_type(cls, resource): def _resource_type(cls, resource):

View File

@ -18,10 +18,12 @@ class Paginator(object):
self.query_set = query_set self.query_set = query_set
@classmethod @classmethod
def paginate(cls, query, pagination=None): def paginate(cls, query, pagination_opts=None):
if pagination is not None: if pagination_opts is not None:
return cls( return cls(
query.paginate(page=pagination["page"], per_page=pagination["per_page"]) query.paginate(
page=pagination_opts["page"], per_page=pagination_opts["per_page"]
)
) )
else: else:
return query.all() return query.all()
@ -68,5 +70,5 @@ class Query(object):
return resource return resource
@classmethod @classmethod
def paginate(cls, query, pagination): def paginate(cls, query, pagination_opts):
return Paginator.paginate(query, pagination) return Paginator.paginate(query, pagination_opts)

View File

@ -121,7 +121,7 @@ def logout():
return redirect(url_for(".root")) return redirect(url_for(".root"))
def pagination_info(request, default_page=1, default_per_page=50): def get_pagination_opts(request, default_page=1, default_per_page=50):
return { return {
"page": int(request.args.get("page", default_page)), "page": int(request.args.get("page", default_page)),
"per_page": int(request.args.get("per_page", default_per_page)), "per_page": int(request.args.get("per_page", default_per_page)),
@ -130,8 +130,8 @@ def pagination_info(request, default_page=1, default_per_page=50):
@bp.route("/activity-history") @bp.route("/activity-history")
def activity_history(): def activity_history():
pagination = pagination_info(request) pagination_opts = get_pagination_opts(request)
audit_events = AuditLog.get_all_events(g.current_user, pagination) audit_events = AuditLog.get_all_events(g.current_user, pagination_opts)
return render_template("audit_log.html", audit_events=audit_events) return render_template("audit_log.html", audit_events=audit_events)

View File

@ -29,5 +29,5 @@ def test_paginate_audit_log(ccpo):
for _ in range(100): for _ in range(100):
AuditLog.log_system_event(user, action="create") AuditLog.log_system_event(user, action="create")
events = AuditLog.get_all_events(ccpo, pagination={"per_page": 25, "page": 2}) events = AuditLog.get_all_events(ccpo, pagination_opts={"per_page": 25, "page": 2})
assert len(events) == 25 assert len(events) == 25