Changed the get_number_query() method to the get_query_number() function, so that it is shared by different view classes.
This commit is contained in:
parent
967c51075c
commit
37cddf478c
@ -133,25 +133,27 @@ ORDER BY
|
|||||||
self.kwargs["subject_code"] + "%"])
|
self.kwargs["subject_code"] + "%"])
|
||||||
pagination = Pagination(
|
pagination = Pagination(
|
||||||
len(records),
|
len(records),
|
||||||
self.get_number_query("page"),
|
get_query_number(self.request, "page"),
|
||||||
self.get_number_query("page-size"),
|
get_query_number(self.request, "page-size"),
|
||||||
True)
|
True)
|
||||||
start_no = pagination.page_size * (pagination.page_no - 1)
|
start_no = pagination.page_size * (pagination.page_no - 1)
|
||||||
return records[start_no:start_no + pagination.page_size]
|
return records[start_no:start_no + pagination.page_size]
|
||||||
|
|
||||||
def get_number_query(self, name):
|
|
||||||
"""Returns a positive number query parameter.
|
|
||||||
|
|
||||||
Args:
|
def get_query_number(request, name):
|
||||||
name (str): The name of the query parameter
|
"""Returns a positive number query parameter.
|
||||||
|
|
||||||
Returns:
|
Args:
|
||||||
The parameter value, or None if this parameter does not
|
request (HttpRequest): The HTTP request
|
||||||
exist or is not a positive number
|
name (str): The name of the query parameter
|
||||||
"""
|
|
||||||
if name not in self.request.GET:
|
Returns:
|
||||||
return None
|
The parameter value, or None if this parameter does not
|
||||||
elif not re.match("^[1-9][0-9]*$", self.request.GET[name]):
|
exist or is not a positive number
|
||||||
return None
|
"""
|
||||||
else:
|
if name not in request.GET:
|
||||||
return int(self.request.GET)
|
return None
|
||||||
|
elif not re.match("^[1-9][0-9]*$", request.GET[name]):
|
||||||
|
return None
|
||||||
|
else:
|
||||||
|
return int(request.GET)
|
||||||
|
Loading…
Reference in New Issue
Block a user