Files
@ eb29e7cd0977
Branch filter:
Location: symposion_app/registrasion/controllers/for_id.py - annotation
eb29e7cd0977
796 B
text/x-python
Adds test cases for basic batch cacheing behaviour
ca8f67c2f396 ca8f67c2f396 ca8f67c2f396 ca8f67c2f396 ca8f67c2f396 ca8f67c2f396 ca8f67c2f396 ca8f67c2f396 ca8f67c2f396 ca8f67c2f396 ca8f67c2f396 ca8f67c2f396 ca8f67c2f396 ca8f67c2f396 ca8f67c2f396 ca8f67c2f396 ca8f67c2f396 ca8f67c2f396 ca8f67c2f396 ca8f67c2f396 ca8f67c2f396 ca8f67c2f396 ca8f67c2f396 ca8f67c2f396 | from django.core.exceptions import ObjectDoesNotExist
from django.http import Http404
class ForId(object):
''' Mixin class that gives you new classmethods: for_id for_id_or_404.
These let you retrieve an instance of the class by specifying the model ID.
Your subclass must define __MODEL__ as a class attribute. This will be the
model class that we wrap. There must also be a constructor that takes a
single argument: the instance of the model that we are controlling. '''
@classmethod
def for_id(cls, id_):
id_ = int(id_)
obj = cls.__MODEL__.objects.get(pk=id_)
return cls(obj)
@classmethod
def for_id_or_404(cls, id_):
try:
return cls.for_id(id_)
except ObjectDoesNotExist:
return Http404
|