techu.libraries.generic

techu.libraries.generic.E(code=500, **kwargs)

Return an HttpResponse with error code.

techu.libraries.generic.R(data, request=None, **kwargs)
Return a successful, normal HttpResponse (status code 200).
Serializes by default any object passed.
Passing the GET/POST parameter pretty=1 will result in pretty-printed output.
class techu.libraries.generic.Serializer(skipkeys=False, ensure_ascii=True, check_circular=True, allow_nan=True, sort_keys=False, indent=None, separators=None, encoding='utf-8', default=None)

JSON serializer for list, dict and QuerySet objects.

default(o)

Default serializer method. Enables QuerySet & datetime support.

techu.libraries.generic.cursorfetchall(cursor)

Returns all rows from a DB cursor as a dictionary

techu.libraries.generic.debug(r)

Raise exception so that passes through the Exception logging middleware.

techu.libraries.generic.filter_list(r, fields)
Filter conditions from a request and create an appropriate dictionary which is passed to filter as kwargs.
Example:

filter_list(r, { ‘name’ : ‘startswith’, ‘section’ : None })

Passing None will use __exact as an operator.
techu.libraries.generic.identq(s)

Quote an SQL identifier.

techu.libraries.generic.is_model(o)

Check if a variable is instance of Model. Returns Boolean.

techu.libraries.generic.is_queryset(o)

Check if a variable is QuerySet. Returns Boolean.

techu.libraries.generic.is_queued(request)

Check if a request requires operation queueing. Returns Boolean.

techu.libraries.generic.model_fields(model, r)
Filter values from dictionary parameter r which are fields of the model parameter model.
Returns dictionary with the model field values and fields as keys.
techu.libraries.generic.model_to_dict(instance, fields_only=[])
Convert a model instance to dictionary.
Use fields_only parameter to narrow down the returned field values.
techu.libraries.generic.redis_client()

Return a Redis 2.6 client instance

techu.libraries.generic.regex_check(s, r='[^a-zA-Z0-9\\-_]+')

Regex check for ASCII letters & digits, dash & underscore

techu.libraries.generic.request_data(req)
Combine GET & POST dictionaries. POST has higher priority.
If request contains data parameter then it is unserialized from JSON format and the result is returned.

Previous topic

techu.libraries.caching

Next topic

techu.libraries.middleware

This Page