Example #1
0
 def get_object(self):
     try:
         video = (Video.objects.select_related('teamvideo').get(
             video_id=self.kwargs['video_id']))
     except Video.DoesNotExist:
         if self.request.user.is_staff:
             raise http.Http404
         else:
             raise PermissionDenied()
     workflow = video.get_workflow()
     if not workflow.user_can_view_video(self.request.user):
         raise PermissionDenied()
     SubtitleLanguage.bulk_has_public_version(
         video.all_subtitle_languages())
     return video
Example #2
0
    def to_representation(self, qs):
        # Do some optimizations to reduce the number of queries before passing
        # the result to the default to_representation() method

        # Note: we have to use prefetch_related the teamvideo attributes,
        # otherwise it will filter out non-team videos.  I think this is a
        # django 1.4 bug.
        qs = (qs.select_related('teamvideo').prefetch_related(
            'teamvideo__team', 'teamvideo__project', 'newsubtitlelanguage_set',
            'videourl_set'))
        # run bulk_has_public_version(), otherwise we have a query for each
        # language of each video
        videos = list(qs)
        all_languages = []
        for v in videos:
            all_languages.extend(v.all_subtitle_languages())
        SubtitleLanguage.bulk_has_public_version(all_languages)
        return super(VideoListSerializer, self).to_representation(videos)