Files
@ d4f4312178cd
Branch filter:
Location: symposion_app/registrasion/controllers/for_id.py - annotation
d4f4312178cd
796 B
text/x-python
Adds cancellation fee implementation and tests
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
|