Returns a wrapper which takes a function as its only argument and sets the key/value pairs passed in with kwargs as attributes on that function. This can be used as a decorator.
>>> from philo.utils import fattr >>> @fattr(short_description="Hello World!") ... def x(): ... pass ... >>> x.short_description 'Hello World!'
Can be used to limit the choices for a ForeignKey or ManyToManyField to the ContentTypes which have been registered with this limiter.
Registers a model class with this limiter.
Unregisters a model class from this limiter.
Can be used to limit the choices for a ForeignKey or ManyToManyField to the ContentTypes for all non-abstract models which subclass the class passed in on instantiation.
Given a list of objects, return a (paginator, page, objects) tuple.
(paginator, page, objects) where paginator is a django.core.paginator.Paginator instance, page is the result of calling Paginator.page() with page_number, and objects is page.objects. Any of the return values which can’t be calculated will be returned as None.
Given an Entity subclass instance, this class allows dictionary-style access to the Entity‘s Attributes. In order to prevent unnecessary queries, the AttributeMapper will cache all Attributes and the associated python values when it is first accessed.
|Parameters:||entity – The Entity subclass instance whose Attributes will be made accessible.|
Returns the Attribute instance with the given key from the cache, populating the cache if necessary, or default if no such attribute is found.
Returns the keys from the cache, first populating the cache if necessary.
Returns the items from the cache, first populating the cache if necessary.
Returns the values from the cache, first populating the cache if necessary.
Clears the cache.
The TreeEntity class allows the inheritance of Attributes down the tree. This mapper will return the most recently declared Attribute among the TreeEntity‘s ancestors or set an attribute on the Entity it is attached to.
Given an iterable of Entities, this mapper will fetch an AttributeMapper for each one. Lookups will return the value from the first AttributeMapper which has an entry for a given key. Assignments will be made to the first Entity in the iterable.
|Parameters:||entities – An iterable of Entity subclass instances.|
In some cases, it may be that only one attribute value needs to be fetched. In this case, it is more efficient to avoid populating the cache whenever possible. This mixin overrides the __getitem__() and get_attribute() methods to prevent their populating the cache. If the cache has been populated (i.e. through keys(), values(), etc.), then the value or attribute will simply be returned from the cache.