def get_context_data(self, **kwargs): context = super(IndexView, self).get_context_data(**kwargs) featured_form = SearchForm({'sort': 'featured'}) popular_form = SearchForm({'sort': 'popular'}) new_form = SearchForm({'sort': 'newest'}) video_pks = Video.objects.filter(site=settings.SITE_ID, status=Video.ACTIVE).values_list( 'pk', flat=True) recent_comments = comments.get_model().objects.filter( site=settings.SITE_ID, content_type=ContentType.objects.get_for_model(Video), object_pk__in=video_pks, is_removed=False, is_public=True).order_by('-submit_date') context.update({ 'featured_videos': NormalizedVideoList(featured_form.search()), 'popular_videos': NormalizedVideoList(popular_form.search()), 'new_videos': NormalizedVideoList(new_form.search()), 'comments': recent_comments }) return context
def get_context_data(self, **kwargs): context = super(IndexView, self).get_context_data(**kwargs) featured_form = SearchForm({"sort": "featured"}) popular_form = SearchForm({"sort": "popular"}) new_form = SearchForm({"sort": "newest"}) video_pks = Video.objects.filter(site=settings.SITE_ID, status=Video.ACTIVE).values_list("pk", flat=True) recent_comments = ( comments.get_model() .objects.filter( site=settings.SITE_ID, content_type=ContentType.objects.get_for_model(Video), object_pk__in=video_pks, is_removed=False, is_public=True, ) .order_by("-submit_date") ) context.update( { "featured_videos": NormalizedVideoList(featured_form.search()), "popular_videos": NormalizedVideoList(popular_form.search()), "new_videos": NormalizedVideoList(new_form.search()), "comments": recent_comments, } ) return context
def get_context_data(self, **kwargs): context = super(IndexView, self).get_context_data(**kwargs) featured_videos = Video.objects.get_featured_videos() form = SearchForm({'sort': 'popular'}) popular_videos = form.search() new_videos = Video.objects.get_latest_videos() site_settings_videos = Video.objects.get_site_settings_videos() recent_comments = comments.get_model().objects.filter( site=settings.SITE_ID, content_type=ContentType.objects.get_for_model(Video), object_pk__in=site_settings_videos.values_list('pk', flat=True), is_removed=False, is_public=True).order_by('-submit_date') context.update({ 'featured_videos': featured_videos, 'popular_videos': NormalizedVideoList(popular_videos), 'new_videos': new_videos, 'comments': recent_comments }) return context
def get_context_data(self, **kwargs): context = super(VideoView, self).get_context_data(**kwargs) context.update({ 'sidebar_modules': self.get_sidebar_modules(), # set edit_video_form to True if the user is an admin for # backwards-compatibility 'edit_video_form': self.request.user_is_admin(), }) site_settings = SiteSettings.objects.get_current() # Data for generating popular videos list. popular_form_data = {'sort': 'popular'} try: category_obj = self.object.categories.all()[0] except IndexError: pass else: # If there are categories, prefer the category that the user # just came from the list view of. referrer = self.request.META.get('HTTP_REFERER') host = self.request.META.get('HTTP_HOST') if referrer and host: if referrer.startswith('http://') or \ referrer.startswith('https://'): referrer = referrer[referrer.index('://') + 3:] if referrer.startswith(host): referrer = referrer[len(host):] try: view, args, kwargs = resolve(referrer) except Resolver404: pass else: from localtv.urls import category_videos if view == category_videos: try: category_obj = self.object.categories.get( slug=kwargs['slug'], site=site_settings.site) except Category.DoesNotExist: pass context['category'] = category_obj popular_form_data['category'] = [category_obj] form = SearchForm(popular_form_data) popular_videos = form.search() context['popular_videos'] = NormalizedVideoList(popular_videos) if site_settings.playlists_enabled: # showing playlists if self.request.user.is_authenticated(): if self.request.user_is_admin() or \ site_settings.playlists_enabled == 1: # user can add videos to playlists context['playlists'] = Playlist.objects.filter( user=self.request.user) playlistitem_qs = self.object.playlistitem_set.all() if self.request.user_is_admin(): # show all playlists pass elif self.request.user.is_authenticated(): # public playlists or my playlists playlistitem_qs = playlistitem_qs.filter( Q(playlist__status=Playlist.PUBLIC) | Q(playlist__user=self.request.user)) else: # just public playlists playlistitem_qs = playlistitem_qs.filter( playlist__status=Playlist.PUBLIC) context['playlistitem_set'] = playlistitem_qs if 'playlist' in self.request.GET: try: playlist = Playlist.objects.get( pk=self.request.GET['playlist']) except (Playlist.DoesNotExist, ValueError): pass else: if (playlist.is_public() or self.request.user_is_admin() or (self.request.user.is_authenticated() and playlist.user_id == self.request.user.pk)): try: context['playlistitem'] = ( self.object.playlistitem_set.get( playlist=playlist)) except PlaylistItem.DoesNotExist: pass return context
def get_context_data(self, **kwargs): context = super(VideoView, self).get_context_data(**kwargs) context.update({ 'sidebar_modules': self.get_sidebar_modules(), # set edit_video_form to True if the user is an admin for # backwards-compatibility 'edit_video_form': self.request.user_is_admin(), }) site_settings = SiteSettings.objects.get_current() # Data for generating popular videos list. popular_form_data = {'sort': 'popular'} try: category_obj = self.object.categories.all()[0] except IndexError: pass else: # If there are categories, prefer the category that the user # just came from the list view of. referrer = self.request.META.get('HTTP_REFERER') host = self.request.META.get('HTTP_HOST') if referrer and host: if referrer.startswith('http://') or \ referrer.startswith('https://'): referrer = referrer[referrer.index('://')+3:] if referrer.startswith(host): referrer = referrer[len(host):] try: view, args, kwargs = resolve(referrer) except Resolver404: pass else: from localtv.urls import category_videos if view == category_videos: try: category_obj = self.object.categories.get( slug=kwargs['slug'], site=site_settings.site) except Category.DoesNotExist: pass context['category'] = category_obj popular_form_data['category'] = [category_obj] form = SearchForm(popular_form_data) popular_videos = form.search() context['popular_videos'] = NormalizedVideoList(popular_videos) if site_settings.playlists_enabled: # showing playlists if self.request.user.is_authenticated(): if self.request.user_is_admin() or \ site_settings.playlists_enabled == 1: # user can add videos to playlists context['playlists'] = Playlist.objects.filter( user=self.request.user) playlistitem_qs = self.object.playlistitem_set.all() if self.request.user_is_admin(): # show all playlists pass elif self.request.user.is_authenticated(): # public playlists or my playlists playlistitem_qs = playlistitem_qs.filter( Q(playlist__status=Playlist.PUBLIC) | Q(playlist__user=self.request.user)) else: # just public playlists playlistitem_qs = playlistitem_qs.filter( playlist__status=Playlist.PUBLIC) context['playlistitem_set'] = playlistitem_qs if 'playlist' in self.request.GET: try: playlist = Playlist.objects.get( pk=self.request.GET['playlist']) except (Playlist.DoesNotExist, ValueError): pass else: if (playlist.is_public() or self.request.user_is_admin() or (self.request.user.is_authenticated() and playlist.user_id == self.request.user.pk)): try: context['playlistitem'] = ( self.object.playlistitem_set.get( playlist=playlist)) except PlaylistItem.DoesNotExist: pass return context