def myPinnedPost(request): sections = Section.objects.all() post_num = Post.objects.count() user_num = User.objects.filter(is_active=True).count() user_extend = None if request.user.is_authenticated(): user_extend = UserExtend.objects.get(user=request.user) query = user_extend.pin_post.all() page = request.GET.get('page', 1) paginator = Paginator(query, 20, body=5) try: pin_post_list = paginator.page(page) except PageNotAnInteger: # If page is not an integer, deliver first page. pin_post_list = paginator.page(1) except EmptyPage: # If page is out of range (e.g. 9999), deliver last page of results. pin_post_list = paginator.page(paginator.num_pages) return render( request, 'main/myPinnedPost.html', { 'pin_post_list': pin_post_list, 'sections': sections, 'post_num': post_num, 'user_num': user_num, 'user_extend': user_extend, 'today': datetime.datetime.now(), }, )
def trending(request): sections = Section.objects.all() post_num = Post.objects.count() user_num = User.objects.filter(is_active=True).count() user_extend = None if request.user.is_authenticated(): user_extend = UserExtend.objects.get(user=request.user) query = Post.objects.exclude(status__exact='t').order_by('-comment_count') page = request.GET.get('page', 1) paginator = Paginator(query, 20, body=5) try: trending = paginator.page(page) except PageNotAnInteger: # If page is not an integer, deliver first page. trending = paginator.page(1) except EmptyPage: # If page is out of range (e.g. 9999), deliver last page of results. trending = paginator.page(paginator.num_pages) return render( request, 'main/trending_list.html', { 'trending': trending, 'sections': sections, 'post_num': post_num, 'user_num': user_num, 'user_extend': user_extend, }, )
def MyMention(request): sections = Section.objects.all() post_num = Post.objects.count() user_num = User.objects.filter(is_active=True).count() user_extend = None if request.GET.has_key('search'): form = SearchForm(request.GET) else: return render( request, 'main/my_mention.html', { 'sections': sections, 'post_num': post_num, 'user_num': user_num, 'err': 'error' }, ) if form.is_valid(): user_extend = form.cleaned_data['search'] query = Comment.objects.exclude(post__status='t').filter( \ Q(this_comment_quote__comment_by__user__username__iexact=user_extend) | \ Q(comment_made__icontains=user_extend) ).order_by('-id') page = request.GET.get('page', 1) paginator = Paginator(query, 20, body=5) try: allcomment = paginator.page(page) except PageNotAnInteger: # If page is not an integer, deliver first page. allcomment = paginator.page(1) except EmptyPage: # If page is out of range (e.g. 9999), deliver last page of results. allcomment = paginator.page(paginator.num_pages) return render( request, 'main/my_mention.html', { 'allcomment': allcomment, 'sections': sections, 'post_num': post_num, 'user_num': user_num, 'post_owner': user_extend, }, ) else: return render( request, 'main/my_mention.html', { 'sections': sections, 'post_num': post_num, 'user_num': user_num, }, )
def popular(request, slug): slug = slug.strip() sections = Section.objects.all() post_num = Post.objects.count() user_num = User.objects.filter(is_active=True).count() user_extend = None try: sec_query = Section.objects.get(name=slug) except Section.DoesNotExist: return render( request, 'main/popular_section.html', { 'sections': sections, 'post_num': post_num, 'user_num': user_num, 'err': 'error' }, ) if request.user.is_authenticated(): user_extend = UserExtend.objects.get(user=request.user) if sec_query: query = sec_query.post_set.exclude( status__exact='t').order_by('-comment_count') page = request.GET.get('page', 1) paginator = Paginator(query, 20, body=5) try: section = paginator.page(page) except PageNotAnInteger: # If page is not an integer, deliver first page. section = paginator.page(1) except EmptyPage: # If page is out of range (e.g. 9999), deliver last page of results. section = paginator.page(paginator.num_pages) return render( request, 'main/popular_section.html', { 'section_name': sec_query, 'section_list': section, 'sections': sections, 'post_num': post_num, 'user_num': user_num, 'user_extend': user_extend, }, )
def index(request): keyword = request.GET.get('kw') wanted_tag = u'求购' if keyword: post_list = Post.objects.filter(title__contains=keyword).order_by('-last_updated_at') wanted_post_list = Post.objects.filter(title__contains=keyword, tag=wanted_tag).order_by('-last_updated_at') else: post_list = Post.objects.all().order_by('-last_updated_at') wanted_post_list = Post.objects.filter(tag=wanted_tag).order_by('-last_updated_at') paginator = DiggPaginator(post_list, 17, body=5) # Show 17 posts per page wanted_paginator = DiggPaginator(wanted_post_list, 17, body=5) # Show 17 posts per page page = request.GET.get('page') wpage = request.GET.get('wpage') try: if not page: posts = paginator.page(1) else: posts = paginator.page(page) if not wpage: wanted_posts = wanted_paginator.page(1) else: wanted_posts = wanted_paginator.page(wpage) except PageNotAnInteger: # If page is not an integer, deliver first page. posts = paginator.page(1) wanted_posts = wanted_paginator.page(1) except EmptyPage: # If page is out of range (e.g. 9999), deliver last page of results. posts = paginator.page(paginator.num_pages) wanted_posts = wanted_paginator.page(wanted_paginator.num_pages) return render_to_response('listing/index.html', {"posts": posts, "wanted_posts": wanted_posts}, context_instance=get_common_context(request))
def allMyComment(request, slug): slug = slug.strip() sections = Section.objects.all() post_num = Post.objects.count() user_num = User.objects.filter(is_active=True).count() user_extend = None try: queryu = User.objects.get(username=slug) except User.DoesNotExist: return render( request, 'main/allmycomment.html', context={ 'sections': sections, 'post_num': post_num, 'user_num': user_num, }, ) if request.user.is_authenticated(): user_extend = UserExtend.objects.get(user=request.user) query = Comment.objects.exclude(post__status='t').filter( comment_by__user=queryu).order_by('-id') page = request.GET.get('page', 1) paginator = Paginator(query, 20, body=5) try: allcomment = paginator.page(page) except PageNotAnInteger: # If page is not an integer, deliver first page. allcomment = paginator.page(1) except EmptyPage: # If page is out of range (e.g. 9999), deliver last page of results. allcomment = paginator.page(paginator.num_pages) return render( request, 'main/allmycomment.html', { 'allcomment': allcomment, 'sections': sections, 'post_num': post_num, 'user_num': user_num, 'user_extend': user_extend, 'post_owner': queryu, }, )
def get(self, request): type = request.GET.get('cat') page = request.GET.get('page', 1) sort = request.GET.get('sort', "popular") toplist = apigrabber.getToplist(type, page, sort) # print(len(toplist)) paginator = DiggPaginator(toplist, 24, body=6) try: movies = DiggPaginator.page(paginator, number=page) except PageNotAnInteger: movies = DiggPaginator.page(paginator, number=1) except EmptyPage: movies = DiggPaginator.page(paginator, number=DiggPaginator.num_pages) return render(request, 'gui/toplist.html', {"posts": movies, "type": type, "page": int(page), "pagename": "Browse Top List"})
def record(request, memberpid, pageno): try: q = member.objects.get(pid=memberpid) except member.DoesNotExist: raise Http404("Member does not exist.") qs = basehansard.objects.filter( pid=memberpid).order_by('-speechdate').all() paginator = DiggPaginator(qs, 5, body=5, tail=2, padding=2) thedate = datetime.datetime.now().date() baseurl = "/members/record/" + memberpid + '/' ridings = constituency.objects.filter( pid=memberpid).order_by('startdate').distinct( ) # this handles duplicates (for now) which need to be culled properly ridings_reverse = constituency.objects.filter( pid=memberpid).order_by('-startdate').all() try: lastparty = ridings_reverse[0].partyid except: lastparty = party.objects.get(partyid=31) try: lastconstituency = ridings_reverse[0] except: lastconstituency = None return render_to_response( 'members/member.html', { 'member': q, 'latest': qs, 'ridings': ridings, 'lastparty': lastparty, 'baseurl': baseurl, 'paginator': paginator, 'page': paginator.page(pageno), 'pageno': pageno, 'lastconstituency': lastconstituency })
def get(self, request, filter_by='all'): """docstring Note: Do not include the `self` parameter in the ``Args`` section. Args: param1: The first parameter. param2: The second parameter. Returns: True if successful, False otherwise. """ # todo Finish docstring if not request.user.is_authenticated(): return render(request, 'music/auth/login.html') else: page = request.GET.get('page', 1) try: song_ids = [] for album in Album.objects.filter(user=request.user): for song in album.song_set.all(): song_ids.append(song.pk) user_songs = Song.objects.filter(pk__in=song_ids) if filter_by == 'favorites': user_songs = user_songs.filter(fav=True) paginate_songs = Paginator(user_songs, 20, body=3, margin=1, tail=1) try: user_songs = paginate_songs.page(page) except PageNotAnInteger: user_songs = paginate_songs.page(1) except EmptyPage: user_songs = paginate_songs.page(paginate_songs.num_pages) except Album.DoesNotExist: user_songs = [] return render(request, 'music/song/songs.html', { 'song_list': user_songs, 'filter_by': filter_by, })
def get(self, request, filter_by='all'): """docstring Note: Do not include the `self` parameter in the ``Args`` section. Args: param1: The first parameter. param2: The second parameter. Returns: True if successful, False otherwise. """ # todo Finish docstring if not request.user.is_authenticated(): return render(request, 'music/auth/login.html') else: page = request.GET.get('page', 1) try: label_ids = [] labels = [] for label in Label.objects.all(): label_ids.append(label.pk) labels = Label.objects.filter(pk__in=label_ids) if filter_by == 'favorites': labels = labels.filter(fav=True) paginate_labels = Paginator(labels, 20, body=3, margin=1, tail=1) try: labels = paginate_labels.page(page) except PageNotAnInteger: labels = paginate_labels.page(1) except EmptyPage: labels = paginate_labels.page(paginate_labels.num_pages) except Label.DoesNotExist: labels = [] return render(request, 'music/label/labels.html', { 'label_list': labels, 'filter_by': filter_by, })
def home(request): keyword = request.GET.get('kw') if keyword: post_list = Post.objects.filter( title__contains=keyword).order_by('-last_updated_at') else: post_list = Post.objects.all().order_by('-last_updated_at') paginator = DiggPaginator(post_list, 17, body=5) # Show 17 posts per page page = request.GET.get('page') try: if not page: posts = paginator.page(1) else: posts = paginator.page(page) except PageNotAnInteger: # If page is not an integer, deliver first page. posts = paginator.page(1) except EmptyPage: # If page is out of range (e.g. 9999), deliver last page of results. posts = paginator.page(paginator.num_pages) return render_to_response('listing/home.html', {"posts": posts}, context_instance=RequestContext(request))
def build_page(self): try: page_no = int(self.request.GET.get('page', 1)) except (TypeError, ValueError): raise Http404("Not a valid number for page.") if page_no < 1: raise Http404("Pages should be 1 or greater.") paginator = DiggPaginator(self.results, 20, body=5, tail=2, padding=2) try: page = paginator.page(page_no) except InvalidPage: raise Http404("Problem with search results (no such page)!") return (paginator, page)
def page(request, pk, topic): sections = Section.objects.all() post_num = Post.objects.count() user_num = User.objects.filter(is_active=True).count() try: post_query = Post.objects.get(pk=pk) except Post.DoesNotExist: return render( request, 'main/post_detail.html', { 'sections': sections, 'post_num': post_num, 'user_num': user_num, }, ) if slugify(topic) != slugify(post_query.title[0:50]): return render( request, 'main/post_detail.html', { 'sections': sections, 'post_num': post_num, 'user_num': user_num, }, ) if post_query: if request.user.is_authenticated(): hit_count = HitCount.objects.get_for_object(post_query) hit_count_response = HitCountMixin.hit_count(request, hit_count) userextend_user = UserExtend.objects.get(user=request.user) userextend_user.last_seen = timezone.now() userextend_user.save(update_fields=['last_seen']) query = post_query.comment_set.all() page = request.GET.get('page', 1) paginator = Paginator(query, 20, body=5) try: comment = paginator.page(page) except PageNotAnInteger: # If page is not an integer, deliver first page. comment = paginator.page(1) except EmptyPage: # If page is out of range (e.g. 9999), deliver last page of results. comment = paginator.page(paginator.num_pages) return render( request, 'main/post_detail.html', { 'post': post_query, 'comment_list': comment, 'sections': sections, 'post_num': post_num, 'user_num': user_num, }, )
def record(request, memberpid, pageno): try: q = member.objects.get(pid=memberpid) except member.DoesNotExist: raise Http404("Member does not exist.") qs = basehansard.objects.filter(pid=memberpid).order_by('-speechdate').all() paginator = DiggPaginator(qs, 5, body=5, tail=2, padding=2) thedate = datetime.datetime.now().date() baseurl = "/members/record/"+memberpid+'/' ridings = constituency.objects.filter(pid=memberpid).order_by('startdate').distinct() # this handles duplicates (for now) which need to be culled properly ridings_reverse = constituency.objects.filter(pid=memberpid).order_by('-startdate').all() try: lastparty = ridings_reverse[0].partyid except: lastparty = party.objects.get(partyid=31) try: lastconstituency = ridings_reverse[0] except: lastconstituency = None return render_to_response('members/member.html', {'member':q, 'latest':qs, 'ridings':ridings, 'lastparty':lastparty, 'baseurl':baseurl,'paginator': paginator, 'page':paginator.page(pageno), 'pageno':pageno, 'lastconstituency':lastconstituency})
def hansard_view(request, year, month, day, pageno): y=int(year) m=int(month) d=int(day) dateobj = datetime.date(y,m,d) # qs = basehansard.objects.raw("select * from dilipadsite_basehansard where speechdate = %s order by basepk", [dateobj]) qs = basehansard.objects.filter(speechdate=dateobj).order_by('basepk') # need to add select_related to speed up rendering # but first basehansard needs foreignkeys to be added! qscount = len(qs) # use len() now so there's a cached verson for paginator ## this is horrible ## def items_count(): ## cursor = connection.cursor() ## cursor.execute("select count(*) from dilipadsite_basehansard where speechdate = %s", [dateobj]) ## row = cursor.fetchone() ## return row[0] paginator = DiggPaginator(qs, 20, body=5, tail=2, padding=2) paginator._count = qscount # items_count() datenavobject = datenav.objects.get(hansarddate=dateobj) storage = messages.get_messages(request) baseurl=("/full/"+str(year)+"/"+str(month)+"/"+str(day)+"/") if len(storage) == 0: try: context = {'year':year, 'baseurl':baseurl, 'month':month, 'day':day, 'hansard':qs[1], 'next':datenavobject.get_next_day_link(), 'paginator': paginator, 'page':paginator.page(pageno), 'pageno':pageno, 'previous':datenavobject.get_previous_day_link()} except InvalidPage: raise Http404("Page does not exist") else: refer_pk = None for m in storage: refer_pk = m.message break try: context = {'year':year, 'month':month, 'baseurl':baseurl, 'day':day, 'hansard':qs[1], 'next':datenavobject.get_next_day_link(), 'paginator': paginator, 'page':paginator.page(pageno), 'pageno':pageno, 'previous':datenavobject.get_previous_day_link(), 'refer_pk':refer_pk} except InvalidPage: raise Http404("Page does not exist") return render_to_response('full/hansard.html', context, context_instance=RequestContext(request))
def hansard_view(request, year, month, day, pageno): y = int(year) m = int(month) d = int(day) dateobj = datetime.date(y, m, d) # qs = basehansard.objects.raw("select * from dilipadsite_basehansard where speechdate = %s order by basepk", [dateobj]) qs = basehansard.objects.filter(speechdate=dateobj).order_by('basepk') # need to add select_related to speed up rendering # but first basehansard needs foreignkeys to be added! qscount = len(qs) # use len() now so there's a cached verson for paginator ## this is horrible ## def items_count(): ## cursor = connection.cursor() ## cursor.execute("select count(*) from dilipadsite_basehansard where speechdate = %s", [dateobj]) ## row = cursor.fetchone() ## return row[0] paginator = DiggPaginator(qs, 20, body=5, tail=2, padding=2) paginator._count = qscount # items_count() datenavobject = datenav.objects.get(hansarddate=dateobj) storage = messages.get_messages(request) baseurl = ("/full/" + str(year) + "/" + str(month) + "/" + str(day) + "/") if len(storage) == 0: try: context = { 'year': year, 'baseurl': baseurl, 'month': month, 'day': day, 'hansard': qs[1], 'next': datenavobject.get_next_day_link(), 'paginator': paginator, 'page': paginator.page(pageno), 'pageno': pageno, 'previous': datenavobject.get_previous_day_link() } except InvalidPage: raise Http404("Page does not exist") else: refer_pk = None for m in storage: refer_pk = m.message break try: context = { 'year': year, 'month': month, 'baseurl': baseurl, 'day': day, 'hansard': qs[1], 'next': datenavobject.get_next_day_link(), 'paginator': paginator, 'page': paginator.page(pageno), 'pageno': pageno, 'previous': datenavobject.get_previous_day_link(), 'refer_pk': refer_pk } except InvalidPage: raise Http404("Page does not exist") return render_to_response('full/hansard.html', context, context_instance=RequestContext(request))
def _item_s_pagination(self): paginator = DiggPaginator(self.search_set, self.PAGE_COUNT) self.page = paginator.page(self.params_storage['page'] or 1)