コード例 #1
0
 def test_get_page(self):
     """ TODO: make into loop """
     item_list = [
         0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 18, 19,
         20
     ]
     page_1 = [0, 1, 2, 3, 4, 5, 6]
     page_2 = [7, 8, 9, 10, 11, 12, 13]
     page_3 = [14, 15, 16, 18, 19, 20]
     # First page is returned
     page = get_page(page_num=None, item_list=item_list, items_per_page=7)
     self.assertEqual(page.object_list, page_1)
     self.assertEqual(page.number, 1)
     page = get_page(page_num=1, item_list=item_list, items_per_page=7)
     self.assertEqual(page.object_list, page_1)
     self.assertEqual(page.number, 1)
     # Second page is returned
     page = get_page(page_num=2, item_list=item_list, items_per_page=7)
     self.assertEqual(page.object_list, page_2)
     self.assertEqual(page.number, 2)
     # Last Page is returned
     page = get_page(page_num=3, item_list=item_list, items_per_page=7)
     self.assertEqual(page.object_list, page_3)
     self.assertEqual(page.number, 3)
     page = get_page(page_num=999, item_list=item_list, items_per_page=7)
     self.assertEqual(page.object_list, page_3)
     self.assertEqual(page.number, 3)
コード例 #2
0
 def get_context_data(self, **kwargs):
     context = super(PublicApplicationsView, self).get_context_data(**kwargs)
     page_num = self.request.GET.get('page')
     applications = Application.objects.filter(applicant=self.request.user)
     context['applications'] = get_page(page_num, applications, 15)
     context['is_applications'] = True
     return context
コード例 #3
0
def search(request, template_name='search/search.html',
           ajax_template='autocomplete/search.html'):

    q = request.GET.get('q', '')
    context = {'q': q}

    if request.is_ajax():
        template_name = ajax_template
        queries = {}
        queries['artists'] = ArtistProfile.objects.filter(name__icontains=q)[:3]
        queries['venues'] = VenueProfile.objects.filter(name__icontains=q)[:3]
        queries['fans'] = FanProfile.objects.filter(
            Q(profile__user__first_name__icontains=q) |
            Q(profile__user__last_name__icontains=q)
        )[:3]
        context.update(queries)
    else:
        profiles = Profile.objects.filter(
            Q(artist_profile__name__icontains=q) |
            Q(venueProfile__name__icontains=q) |
            Q(user__first_name__icontains=q) |
            Q(user__last_name__icontains=q)
        )
        page_num = request.GET.get('page')
        context['profiles'] = get_page(page_num, profiles, 5)


    return render(request, template_name, context)
コード例 #4
0
 def get_context_data(self, **kwargs):
     context = super(PublicRequestView, self).get_context_data(**kwargs)
     page_num = self.request.GET.get('page')
     requests = PublicRequest.objects.filter(requester=self.request.user)
     context['requests'] = get_page(page_num, requests, 15)
     context['is_requests'] = True
     return context
コード例 #5
0
ファイル: updates.py プロジェクト: TimBest/ComposersCouch
 def get_context_data(self, **kwargs):
     context = super(AllViewAuth, self).get_context_data(**kwargs)
     context.update(self.get_scope())
     page_num = self.request.GET.get('page')
     context['object_list'] = get_page(
         page_num,
         Post.objects.all().order_by('-created_at'), 15)
     return context
コード例 #6
0
ファイル: views.py プロジェクト: TimBest/ComposersCouch
 def get_context_data(self, **kwargs):
     context = super(ImageFormMixin, self).get_context_data(**kwargs)
     try:
         page_num = self.request.GET.get('page')
         images = Image.objects.filter(user=self.request.user)
         context['images'] = get_page(page_num, images, self.images_on_page)
     except:
         pass
     return context
コード例 #7
0
ファイル: updates.py プロジェクト: TimBest/ComposersCouch
 def get_context_data(self, **kwargs):
     context = super(FollowingView, self).get_context_data(**kwargs)
     page_num = self.request.GET.get('page')
     feed = feedly.get_feeds(self.request.user.id)['normal']
     activities = list(feed[:15])
     activities = get_page(page_num, activities, 15)
     context['activities'] = enrich_activities(activities)
     context['location'] = get_location(self.request,
                                        self.kwargs.get('zipcode'), 'code')
     return context
コード例 #8
0
    def get_context_data(self, **kwargs):
        context = super(FeedMixin, self).get_context_data(**kwargs)
        context.update(self.get_scope())
        context['feedType'] = self.feedType
        context['order'] = self.kwargs.get('order', self.default_order)
        page_num = self.request.GET.get('page')
        queryset = self.get_queryset()
        if context.get('genres') and queryset:
            queryset = self.filter_by_genre(context['genres'], queryset)
        context['object_list'] = get_page(page_num, queryset, self.paginate_by)

        return context
コード例 #9
0
 def get_context_data(self, **kwargs):
     context = super(SentPrivateRequestsView, self).get_context_data(**kwargs)
     page_num = self.request.GET.get('page')
     context['sent'] = True
     participants = Participant.objects.filter(
         user=self.request.user,
         replied_at__isnull=False,
         deleted_at__isnull=True,
         thread__request__isnull=False,
     )
     context['participants'] = get_page(page_num, participants, 15)
     return context
コード例 #10
0
 def get_context_data(self, **kwargs):
     context = super(PrivateRequestView, self).get_context_data(**kwargs)
     page_num = self.request.GET.get('page')
     context['inbox'] = True
     participants = Participant.objects.filter(
         user=self.request.user,
         deleted_at__isnull=True,
         thread__request__isnull=False,
     ).exclude(
         thread__creator=self.request.user,
     )
     context['participants'] = get_page(page_num, participants, 15)
     return context
コード例 #11
0
 def get_context_data(self, **kwargs):
     context = super(PhotosMixin, self).get_context_data(**kwargs)
     page_num = self.request.GET.get('page')
     images = self.user.images.all()
     context['images'] = get_page(page_num, images, 24)
     return context