Created
April 12, 2015 23:03
-
-
Save mcm/18700e5a055aa12e2df3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from urllib.parse import parse_qs | |
import filtration | |
def validate(req, resp, **kwargs): | |
... | |
def access_log(req, resp, **kwargs): | |
... | |
def filter_queryset(req): | |
if "id" not in req.params: | |
req.context["filter"] = filtration.Expression.parseQsString() | |
def paginate_queryset(req): | |
querystring = parse_qs(req.query_string) | |
queryset = req.context["queryset"] | |
if "per_page" in querystring: | |
# Pagination | |
req.context["pagination"] = { | |
"page": int(querystring.get("page", 1)), | |
"per_page": int(querystring.get("per_page", 25)), | |
} | |
if "sort_by" in querystring: | |
req.context["pagination"].update({ | |
"sort_by": querystring["sort_by"], | |
"order": int(querystring.get("order", -1)), | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment