apps.utils¶
General utilities used across apps
Paginating JSON Responses¶
The paginate_to_json
function handles the generation of JSON responses to
HTTP requests for pagination of data. For example, it can be used in a view as:
1 2 3 4 5 6 7 8 9 10 11 | from django.views.generic import View
from apps.utils import paginate_to_json
class MyView(View):
template = 'myt_template_path.html'
def get(self, request, *args, **kwargs):
data = [{'field1': 'value1'}, {'field1': 'value2'}, ...]
return paginate_to_json(request, data)
|
apps.utils.templatetags.utility_tags¶
The utility_tags
module defines functions for casting between
different data types and formats. These functions are automatically
registered as template tags for use in the Django template engine.
broker_web.apps.utils.templatetags.utility_tags.bytes_to_64utf8 |
Convert bytes data to UTF8 |
broker_web.apps.utils.templatetags.utility_tags.jd_to_readable_date |
Convert a julian date to a human readable string |
broker_web.apps.utils.templatetags.utility_tags.urlparams |
Format keyword arguments as url parameters |
Convert bytes data to UTF8
Parameters: bytes_data (bytes) – Bytes data Returns: A string in UTF-8 format
Convert a julian date to a human readable string
Parameters: jd (float) – Datetime value in julian format Returns: min’ format Return type: String in ‘day mon year hour
Format keyword arguments as url parameters
Returns: A string in the format ‘?<key>=<value>’