Rename pagination args to pagination_opts
This commit is contained in:
parent
5b0383bde3
commit
4244ecf9b7
@ -8,9 +8,9 @@ class AuditEventQuery(Query):
|
||||
model = AuditEvent
|
||||
|
||||
@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())
|
||||
return cls.paginate(query, pagination)
|
||||
return cls.paginate(query, pagination_opts)
|
||||
|
||||
|
||||
class AuditLog(object):
|
||||
@ -29,11 +29,11 @@ class AuditLog(object):
|
||||
return cls._log(resource=resource, action=action)
|
||||
|
||||
@classmethod
|
||||
def get_all_events(cls, user, pagination=None):
|
||||
def get_all_events(cls, user, pagination_opts=None):
|
||||
Authorization.check_atat_permission(
|
||||
user, Permissions.VIEW_AUDIT_LOG, "view audit log"
|
||||
)
|
||||
return AuditEventQuery.get_all(pagination)
|
||||
return AuditEventQuery.get_all(pagination_opts)
|
||||
|
||||
@classmethod
|
||||
def _resource_type(cls, resource):
|
||||
|
@ -18,10 +18,12 @@ class Paginator(object):
|
||||
self.query_set = query_set
|
||||
|
||||
@classmethod
|
||||
def paginate(cls, query, pagination=None):
|
||||
if pagination is not None:
|
||||
def paginate(cls, query, pagination_opts=None):
|
||||
if pagination_opts is not None:
|
||||
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:
|
||||
return query.all()
|
||||
@ -68,5 +70,5 @@ class Query(object):
|
||||
return resource
|
||||
|
||||
@classmethod
|
||||
def paginate(cls, query, pagination):
|
||||
return Paginator.paginate(query, pagination)
|
||||
def paginate(cls, query, pagination_opts):
|
||||
return Paginator.paginate(query, pagination_opts)
|
||||
|
@ -121,7 +121,7 @@ def logout():
|
||||
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 {
|
||||
"page": int(request.args.get("page", default_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")
|
||||
def activity_history():
|
||||
pagination = pagination_info(request)
|
||||
audit_events = AuditLog.get_all_events(g.current_user, pagination)
|
||||
pagination_opts = get_pagination_opts(request)
|
||||
audit_events = AuditLog.get_all_events(g.current_user, pagination_opts)
|
||||
return render_template("audit_log.html", audit_events=audit_events)
|
||||
|
||||
|
||||
|
@ -29,5 +29,5 @@ def test_paginate_audit_log(ccpo):
|
||||
for _ in range(100):
|
||||
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
|
||||
|
Loading…
x
Reference in New Issue
Block a user