privex.helpers.django

This module file contains Django-specific helper functions, to help save time when developing with the Django framework.

  • handle_error - Redirects normal web page requests with a session error, outputs JSON with a status code for API queries.

  • is_database_synchronized - Check if all migrations have been ran before running code.

  • model_to_dict - Extract an individual Django model instance into a dict (with display names)

  • to_json - Convert a model Queryset into a plain string JSON array with display names

Copyright:

    +===================================================+
    |                 © 2019 Privex Inc.                |
    |               https://www.privex.io               |
    +===================================================+
    |                                                   |
    |        Originally Developed by Privex Inc.        |
    |        License: X11 / MIT                         |
    |                                                   |
    |        Core Developer(s):                         |
    |                                                   |
    |          (+)  Chris (@someguy123) [Privex]        |
    |          (+)  Kale (@kryogenic) [Privex]          |
    |                                                   |
    +===================================================+

Copyright 2019     Privex Inc.   ( https://www.privex.io )

Functions

handle_error(request, err, rdr[, status])

Output an error as either a Django session message + redirect, or a JSON response based on whether the request was for the API readable version (?format=json) or not.

is_database_synchronized(database)

Check if all migrations have been ran.

model_to_dict(model)

1 dimensional json-ifyer for any Model

to_json(query_set)

Iterate a Django query set and dump to json str