Common utilities.
Note
Many of these functions are ad hoc and may change between versions.
Bases: json.encoder.JSONEncoder
JSON encoder that can handle datetime instances
Performs all available aggregations on a queryset
Convert CamelCase names to camel_case style
Return a string to use for a CAPTCHA
Return true if celery is available
Generator that chunks a list lst into sublists of size chunksize
Return the shannon entropy of a list of values.
Parameters: | values – observations that will be processed into a histogram |
---|
compute the per-label reward
Greate a grid of images from a queryset
Greate a grid of images from a list of files
Return the (key, value) with the maximum value. This is the fastest way of doing this: http://stackoverflow.com/questions/268272/getting-key-with-maximum-value-in-dictionary
Return the union of two dictionaries without editing either. If a key exists in both dictionaries, the second value is used.
Create a CSV in the staticfiles of a queryset. Values is a list of fields to grab. Optionally, you may specify a rename a field by specifying a tuple instead of a string as (field_name, csv_name). The path is relative to the staticfiles root. The URL of the file is returned.
postgres really sucks at full table counts, this is a faster version see: http://wiki.postgresql.org/wiki/Slow_Counting and http://chase-seibert.github.com/blog/2012/06/01/djangopostgres-optimize-count-by-replacing-with-an-estimate.html
Detects if working
Return (content type id, object id)
Return the ContentType id associated with instance
Return the foreign keym model for model_class.field_name
Returns the directory used to save obj.attr files
Returns a dictionary mapping { val : [elements such that e.attr = val] }
Return true if model_class has a foreign key with a given name
Import a module by name and return it
Import a list of modules by name and return them
Return a HttpResponse containing the JSON message {"result": "error", "message": error}
Return a HttpResponse containing the JSON message d union {"result": "success"}
Return a HttpResponse containing the JSON message {"message": "success", "result": "success"}
Returns the md5 hash of a file
Pickle and gzip obj to disk with filename fname
Returns an iterator for a list or queryset that renders a progress bar with a countdown timer
Returns an iterator for a queryset that renders a progress bar with a countdown timer
Return a random lowercase string of length N
Recursively exclude a key from a nested dictionary
Recursively sums together numbers contained in x. Supports: int, float, dict, list, tuple, str, unicode, and json-encoded strings.
Convert (r, g, b) in range [0.0, 1.0] to "RRGGBB" hex string.
Run async if celery is online, else run serially
Saves a screenshot to a file field (attr) on a model instance (obj). The filename is a hash of the image contant plus an optional suffix.
Saves a file onto an attribute of an object
Saves a PIL image to a file field (attr) on a model instance (obj). The filename is a hash of the image contant plus an optional suffix.
Return a new dictionary with numeric values multiplied by scale.
Parameters: | exclude – collection of items to exclude. |
---|
Decorator that ensures that a celery task is only run once. Default timeout is 12 hours.
See: http://stackoverflow.com/questions/4095940/running-unique-tasks-with-celery See: http://ask.github.com/celery/cookbook/tasks.html#ensuring-a-task-is-only-executed-one-at-a-time
Note
This only works if all tasks share the same django cache.
Converts a list of numbers to a list of integers that exactly sum to 100.
Renders a placeholder view
Return a unique alpha-numeric string for a model instance (base 62). The name is generated from the current time, the object id (or count if not created), its content type id, and the server MAC address.
Never-ending generator that yields all floats in the range [0, 1], in the order:
0, 1, 1/2, 1/4, 3/4, 1/8, 3/8, 5/8, 7/8, 1/16, 3/16, 5/16, ...
The same value is never returned twice, and eventually all floating point numbers in the range [0, 1] are returned. The point of this generator is to sweep a range, iteratively increasing the density of the sweep, so that if you want to stop the sweep early, you have still swept the majority of the range.
Returns: | floats in the range [0, 1]. |
---|
Unpickle a gzipped file from disk with filename fname