forked from randomknowledge/django-webvideo
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
307080f
commit f78c2dd
Showing
6 changed files
with
80 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
# coding=utf-8 | ||
from tastypie.cache import SimpleCache | ||
from tastypie.exceptions import Unauthorized | ||
from tastypie.resources import ModelResource | ||
from tastypie import fields | ||
from tastypie.authentication import SessionAuthentication | ||
from tastypie.authorization import DjangoAuthorization | ||
from tastypie.serializers import Serializer | ||
from tastypie.throttle import CacheThrottle | ||
from django_webvideo.models import WebVideo, ConvertedVideo | ||
|
||
|
||
class WebVideoAuthorization(DjangoAuthorization): | ||
pass | ||
|
||
|
||
class MultipartResource(object): | ||
def deserialize(self, request, data, format=None): | ||
if not format: | ||
format = request.META.get('CONTENT_TYPE', 'application/json') | ||
if format == 'application/x-www-form-urlencoded': | ||
return request.POST | ||
if format.startswith('multipart'): | ||
data = request.POST.copy() | ||
data.update(request.FILES) | ||
return data | ||
return super(MultipartResource, self).deserialize(request, data, format) | ||
|
||
def put_detail(self, request, **kwargs): | ||
if not hasattr(request, '_body'): | ||
request._body = '' | ||
return super(MultipartResource, self).put_detail(request, **kwargs) | ||
|
||
|
||
class ConvertedVideoResource(ModelResource): | ||
class Meta: | ||
queryset = ConvertedVideo.objects.all() | ||
resource_name = 'converted' | ||
excludes = ['status', ] | ||
|
||
|
||
class WebVideoResource(MultipartResource, ModelResource): | ||
video = fields.FileField(attribute="video") | ||
versions = fields.OneToManyField(ConvertedVideoResource, 'converted', full=True, null=True, blank=True) | ||
|
||
class Meta: | ||
queryset = WebVideo.objects.all() | ||
resource_name = 'video' | ||
fields = ['id', 'versions', 'duration', 'video', ] | ||
allowed_methods = ['get', 'post', ] | ||
|
||
filtering = { | ||
'duration': ['exact', 'gt', 'gte', 'lt', 'lte', 'range'], | ||
} | ||
|
||
authentication = SessionAuthentication() | ||
authorization = WebVideoAuthorization() | ||
cache = SimpleCache(timeout=300) | ||
throttle = CacheThrottle(throttle_at=50, timeframe=60) | ||
serializer = Serializer(formats=['json',]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -87,6 +87,7 @@ | |
'django.contrib.staticfiles', | ||
'south', | ||
|
||
'tastypie', | ||
'easy_thumbnails', | ||
'django_webvideo', | ||
] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,4 +2,5 @@ Django==1.5 | |
South==0.7.6 | ||
PIL==1.1.7 | ||
easy-thumbnails==1.2 | ||
rq==0.3.7 | ||
rq==0.3.7 | ||
django-tastypie==0.9.12 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
-r requirements.txt | ||
gunicorn | ||
raven | ||
django-redis-cache |