Beispiel #1
0
    def test_tag_list_omits_if_requested(self):
        self.only_publishable.tags.set('tag1', 'tag2', 'tag3')
        t1 = Tag.objects.get(name='tag1')
        t2 = Tag.objects.get(name='tag2')
        t3 = Tag.objects.get(name='tag3')

        tools.assert_equals(list(tag_list([self.only_publishable])), [t3, t2, t1])
        tools.assert_equals(list(tag_list([self.only_publishable], omit=t1)), [t3, t2])
Beispiel #2
0
    def test_tag_list_returns_items_in_order_of_occurence_count(self):
        self.pub = Article.objects.create(
            title=u'taglist2',
            slug=u'taglist2',
            description=u'taglist',
            category=self.category_nested,
            publish_from=datetime(2008, 1, 1),
            published=True
        )
        self.only_pub = self.pub.publishable_ptr

        self.pub2 = Article.objects.create(
            title=u'taglist3',
            slug=u'taglist3',
            description=u'taglist',
            category=self.category_nested,
            publish_from=datetime(2008, 5, 1),
            published=True
        )
        self.only_pub2 = self.pub2.publishable_ptr

        self.only_publishable.tags.set('tag1', 'tag2', 'tag3')
        self.only_pub.tags.set('tag1', 'tag2')
        self.only_pub2.tags.set('tag1')

        t1 = Tag.objects.get(name='tag1')
        t2 = Tag.objects.get(name='tag2')
        t3 = Tag.objects.get(name='tag3')

        tools.assert_equals(tag_list([self.only_publishable,
                                      self.only_pub,
                                      self.only_pub2]),
                                      [t1, t2, t3])
Beispiel #3
0
    def get_context_data(self, **kwargs):
        context = super(TaggedPublishablesView, self).get_context_data(**kwargs)
        if context['is_paginated']:
            context['page'] = context['page_obj']
            context['results_per_page'] = self.paginate_by

        context['tag'] = self.tag
        context['related_tags'] = tag_list(self.object_list,
                                           threshold=self.relation_occ_threshold,
                                           count=self.relation_count_limit,
                                           omit=self.tag)
        return context
Beispiel #4
0
    def test_tag_list_adheres_to_threshold(self):
        self.pub = Article.objects.create(
            title=u'taglist2',
            slug=u'taglist2',
            description=u'taglist',
            category=self.category_nested,
            publish_from=datetime(2008, 1, 1),
            published=True
        )
        self.only_pub = self.pub.publishable_ptr

        self.only_publishable.tags.set('tag1', 'tag2', 'tag3')
        self.only_pub.tags.set('tag1', 'tag2')

        t1 = Tag.objects.get(name='tag1')
        t2 = Tag.objects.get(name='tag2')

        tools.assert_equals(tag_list([self.only_publishable, self.only_pub], threshold=2), [t2, t1])
Beispiel #5
0
 def test_tag_list_limits_result_count(self):
     self.only_publishable.tags.set('tag1', 'tag2', 'tag3')
     tools.assert_equals(len(tag_list([self.only_publishable])), 3)
     tools.assert_equals(len(tag_list([self.only_publishable], count=2)), 2)