def recent(request): """List all videos, by recency.""" show_pagination = False # Handle search and filtering search_form = SearchForm(request.GET) if search_form.is_valid(): videos = search_form.videos() else: videos = Video.objects.filter(state='complete').order_by('-id') pagination_limit = getattr(settings, 'PAGINATION_LIMIT_FULL', 9) paginator = Paginator(videos, pagination_limit) page = request.GET.get('page', 1) try: videos = paginator.page(page) except PageNotAnInteger: videos = paginator.page(1) except EmptyPage: videos = paginator.page(paginator.num_pages) if paginator.count > pagination_limit: show_pagination = True d = dict(search_form=search_form, search=False, videos=videos.object_list, video_pages=videos, show_pagination=show_pagination, page_type='secondary recent') return render(request, 'videos/recent.html', d)
def _videos(self, **kwargs): params = { 'search': '', 'category': 'all', 'region': 'all' } params.update(kwargs) f = SearchForm(params) return f.videos()
def details(request, user_id=None): """User profile page.""" if request.user.id == user_id: user = request.user page_type = 'profile secondary user-details' else: user = get_object_or_404(User, id=user_id) page_type = 'secondary user-details' profile = get_object_or_404(UserProfile, user=user) show_pagination = False # Handle search and filtering search_form = SearchForm(request.GET) if search_form.is_valid(): videos = search_form.videos().filter(user_id=user_id) else: videos = (Video.objects .filter(state='complete', user__id=user_id) .order_by('-id')) pagination_limit = getattr(settings, 'PAGINATION_LIMIT_FULL', 9) paginator = Paginator(videos, pagination_limit) page = request.GET.get('page', 1) try: videos = paginator.page(page) except PageNotAnInteger: videos = paginator.page(1) except EmptyPage: videos = paginator.page(paginator.num_pages) if paginator.count > pagination_limit: show_pagination = True d = dict(videos=videos.object_list, video_pages=videos, show_pagination=show_pagination, page_type=page_type, search_form=search_form, user=user, profile=profile) return render(request, 'users/details.html', d)