Commit e1c4537b by Dave St.Germain

Lookup video by youtube id

parent 22bef6f9
......@@ -32,7 +32,7 @@ from django.core.validators import MinValueValidator, RegexValidator
from django.core.urlresolvers import reverse
url_regex = r'^[a-zA-Z0-9\-]*$'
url_regex = r'^[a-zA-Z0-9\-_]*$'
class Profile(models.Model):
......@@ -60,6 +60,7 @@ class Profile(models.Model):
def __unicode__(self):
return self.profile_name
class Video(models.Model):
"""
Model for a Video group with the same content.
......@@ -87,6 +88,18 @@ class Video(models.Model):
def __str__(self):
return self.edx_video_id
@classmethod
def by_youtube_id(cls, youtube_id):
"""
Look up video by youtube id
"""
url = '://youtu.be/%s' % youtube_id
qset = cls.objects.filter(
encoded_videos__profile__profile_name='youtube',
encoded_videos__url__endswith=url
).prefetch_related('encoded_videos', 'courses', 'subtitles')
return qset
class CourseVideo(models.Model):
"""
......
......@@ -34,5 +34,10 @@ urlpatterns = patterns(
views.CourseVideoList.as_view(),
name="course-video-list"
),
url(
r'^youtube/(?P<youtube_id>[\w]+)$',
views.YoutubeVideoList.as_view(),
name="youtube-video-list"
),
)
......@@ -60,6 +60,9 @@ class VideoList(generics.ListCreateAPIView):
class CourseVideoList(generics.ListAPIView):
"""
GET a list of videos for a course
"""
authentication_classes = (OAuth2Authentication, SessionAuthentication)
permission_classes = (ReadRestrictedDjangoModelPermissions,)
queryset = Video.objects.all().prefetch_related("encoded_videos")
......@@ -70,6 +73,18 @@ class CourseVideoList(generics.ListAPIView):
return self.queryset.filter(courses__course_id=self.kwargs['course_id'])
class YoutubeVideoList(generics.ListAPIView):
"""
Get a list of videos for the given youtube id
"""
permission_classes = (DjangoModelPermissions,)
serializer_class = VideoSerializer
queryset = Video.objects.all()
def get_queryset(self):
return Video.by_youtube_id(self.kwargs['youtube_id'])
class ProfileList(generics.ListCreateAPIView):
"""
GETs or POST video objects
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment