Exemplo n.º 1
0
    def render(self, context):
        obj = self.obj.resolve(context)

        if not self.user:
            try:
                user = context['request'].user
            except KeyError:
                raise template.TemplateSyntaxError('There is no request object in the template context.')
        else:
            user = template.Variable(self.user).resolve(context)

        return utils.follow_url(user, obj)
Exemplo n.º 2
0
    def test_template_tags(self):
        follow_url = reverse('follow', args=['auth', 'user', self.hendrix.id])
        unfollow_url = reverse('unfollow',
                               args=['auth', 'user', self.hendrix.id])

        request = type('Request', (object, ), {'user': self.lennon})()

        self.assertEqual(follow_url, utils.follow_link(self.hendrix))
        self.assertEqual(unfollow_url, utils.unfollow_link(self.hendrix))

        tpl = template.Template(
            """{% load follow_tags %}{% follow_url obj %}""")
        ctx = template.Context({'obj': self.hendrix, 'request': request})

        self.assertEqual(follow_url, tpl.render(ctx))

        utils.follow(self.lennon, self.hendrix)

        self.assertEqual(unfollow_url, tpl.render(ctx))

        utils.unfollow(self.lennon, self.hendrix)

        self.assertEqual(follow_url, tpl.render(ctx))

        tpl = template.Template(
            """{% load follow_tags %}{% follow_url obj user %}""")
        ctx2 = template.Context({
            'obj': self.lennon,
            'user': self.hendrix,
            'request': request
        })

        self.assertEqual(utils.follow_url(self.hendrix, self.lennon),
                         tpl.render(ctx2))

        tpl = template.Template(
            """{% load follow_tags %}{% if request.user|is_following:obj %}True{% else %}False{% endif %}"""
        )

        self.assertEqual("False", tpl.render(ctx))

        utils.follow(self.lennon, self.hendrix)

        self.assertEqual("True", tpl.render(ctx))

        tpl = template.Template(
            """{% load follow_tags %}{% follow_form obj %}""")
        self.assertEqual(True, isinstance(tpl.render(ctx), unicode))

        tpl = template.Template(
            """{% load follow_tags %}{% follow_form obj "follow/form.html" %}"""
        )
        self.assertEqual(True, isinstance(tpl.render(ctx), unicode))
Exemplo n.º 3
0
 def render(self, context):
     obj = self.obj.resolve(context)
     
     if not self.user:
         try:
             user = context['request'].user
         except KeyError:
             raise template.TemplateSyntaxError('There is no request object in the template context.')
     else:
         user = template.Variable(self.user).resolve(context)
     
     return utils.follow_url(user, obj)
Exemplo n.º 4
0
 def test_template_tags(self):
     follow_url = reverse('follow', args=['auth', 'user', self.hendrix.id])
     unfollow_url = reverse('unfollow', args=['auth', 'user', self.hendrix.id])
     
     request = type('Request', (object,), {'user': self.lennon})()
     
     self.assertEqual(follow_url, utils.follow_link(self.hendrix))
     self.assertEqual(unfollow_url, utils.unfollow_link(self.hendrix))
     
     tpl = template.Template("""{% load follow_tags %}{% follow_url obj %}""")
     ctx = template.Context({
         'obj':self.hendrix,
         'request': request
     })
     
     self.assertEqual(follow_url, tpl.render(ctx))
     
     utils.follow(self.lennon, self.hendrix)
     
     self.assertEqual(unfollow_url, tpl.render(ctx))
     
     utils.unfollow(self.lennon, self.hendrix)
     
     self.assertEqual(follow_url, tpl.render(ctx))
     
     tpl = template.Template("""{% load follow_tags %}{% follow_url obj user %}""")
     ctx2 = template.Context({
         'obj': self.lennon,
         'user': self.hendrix,
         'request': request
     })
     
     self.assertEqual(utils.follow_url(self.hendrix, self.lennon), tpl.render(ctx2))
     
     tpl = template.Template("""{% load follow_tags %}{% if request.user|is_following:obj %}True{% else %}False{% endif %}""")
     
     self.assertEqual("False", tpl.render(ctx))
     
     utils.follow(self.lennon, self.hendrix)
     
     self.assertEqual("True", tpl.render(ctx))
     
     tpl = template.Template("""{% load follow_tags %}{% follow_form obj %}""")
     self.assertEqual(True, isinstance(tpl.render(ctx), str))
     
     tpl = template.Template("""{% load follow_tags %}{% follow_form obj "follow/form.html" %}""")
     self.assertEqual(True, isinstance(tpl.render(ctx), str))
Exemplo n.º 5
0
    def test_template_tags(self):
        follow_url = reverse("follow", args=["auth", "user", self.hendrix.id])
        unfollow_url = reverse("unfollow", args=["auth", "user", self.hendrix.id])

        request = type("Request", (object,), {"user": self.lennon})()

        self.assertEqual(follow_url, utils.follow_link(self.hendrix))
        self.assertEqual(unfollow_url, utils.unfollow_link(self.hendrix))

        tpl = template.Template("""{% load follow_tags %}{% follow_url obj %}""")
        ctx = template.Context({"obj": self.hendrix, "request": request})

        self.assertEqual(follow_url, tpl.render(ctx))

        utils.follow(self.lennon, self.hendrix)

        self.assertEqual(unfollow_url, tpl.render(ctx))

        utils.unfollow(self.lennon, self.hendrix)

        self.assertEqual(follow_url, tpl.render(ctx))

        tpl = template.Template("""{% load follow_tags %}{% follow_url obj user %}""")
        ctx2 = template.Context({"obj": self.lennon, "user": self.hendrix, "request": request})

        self.assertEqual(utils.follow_url(self.hendrix, self.lennon), tpl.render(ctx2))

        tpl = template.Template(
            """{% load follow_tags %}{% if request.user|is_following:obj %}True{% else %}False{% endif %}"""
        )

        self.assertEqual("False", tpl.render(ctx))

        utils.follow(self.lennon, self.hendrix)

        self.assertEqual("True", tpl.render(ctx))

        tpl = template.Template("""{% load follow_tags %}{% follow_form obj %}""")
        self.assertEqual(True, isinstance(tpl.render(ctx), unicode))

        tpl = template.Template("""{% load follow_tags %}{% follow_form obj "follow/form.html" %}""")
        self.assertEqual(True, isinstance(tpl.render(ctx), unicode))