mirror of
https://github.com/fergalmoran/dss.git
synced 2025-12-22 09:38:18 +00:00
36 lines
1.1 KiB
Python
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)
|
|
)
|
|
|