Files
dss/spa/api/v1/ShowResource.py
2014-05-12 19:32:43 +01:00

36 lines
1.1 KiB
Python

from tastypie import fields
from tastypie.authorization import Authorization
from tastypie.exceptions import ImmediateHttpResponse
from tastypie.http import HttpBadRequest
from spa.api.v1.BackboneCompatibleResource import BackboneCompatibleResource
from spa.models import Show
from spa.models.show import ShowOverlapException
DATE_FORMAT = '%d/%m/%Y %H:%M:%S'
class ShowResource(BackboneCompatibleResource):
mix = fields.ToOneField('spa.api.v1.MixResource.MixResource',
'mix', null=False, full=False)
class Meta:
queryset = Show.objects.all()
authorization = Authorization()
resource_name = 'show'
always_return_data = True
def obj_create(self, bundle, **kwargs):
try:
return super(ShowResource, self).obj_create(bundle, **kwargs)
except ShowOverlapException:
raise ImmediateHttpResponse(
HttpBadRequest("This event overlaps with an existing event")
)
except Exception, ex:
raise ImmediateHttpResponse(
HttpBadRequest(ex.message)
)