Exemplo n.º 1
0
 def get(self, request, email):
     user = request.user
     
     following, created = User.objects.get_or_create(email=email)
     if created:
         following.username = email
         following.save()
     
     utils.follow(user, following)
     
     subscribed = self.reader_subscribe(request, email)
     if isinstance(subscribed, HttpResponse):
         return subscribed
     else:
         #notify
         pass
     
     if waffle.flag_is_active(request, 'followemail'):
         msg = """
         Remember when Google removed following and sharing from reader?  Do you want them back?
         It's easy! Check out http://readersharing.net
         
         %s is now following you on Google Reader
         
         Login to follow them back!
         """
         
         subject = "%s is now following you on Google Reader"
         send_mail(subject % user.username, 
                   msg % user.username, 
                   'Reader Sharing <*****@*****.**>',
                   [following.email], 
                   fail_silently=False)
     messages.success(request, "Followed %s" % email)    
     return redirect('/')
Exemplo n.º 2
0
    def test_signals(self):
        Handler = type(
            'Handler', (object, ), {
                'inc': lambda self: setattr(self, 'i',
                                            getattr(self, 'i') + 1),
                'i': 0
            })
        user_handler = Handler()
        group_handler = Handler()

        def follow_handler(sender, user, target, instance, **kwargs):
            self.assertEqual(sender, User)
            self.assertEqual(self.lennon, user)
            self.assertEqual(self.hendrix, target)
            self.assertEqual(True, isinstance(instance, Follow))
            user_handler.inc()

        def unfollow_handler(sender, user, target, instance, **kwargs):
            self.assertEqual(sender, User)
            self.assertEqual(self.lennon, user)
            self.assertEqual(self.hendrix, target)
            self.assertEqual(True, isinstance(instance, Follow))
            user_handler.inc()

        def group_follow_handler(sender, **kwargs):
            self.assertEqual(sender, Group)
            group_handler.inc()

        def group_unfollow_handler(sender, **kwargs):
            self.assertEqual(sender, Group)
            group_handler.inc()

        signals.followed.connect(follow_handler,
                                 sender=User,
                                 dispatch_uid='userfollow')
        signals.unfollowed.connect(unfollow_handler,
                                   sender=User,
                                   dispatch_uid='userunfollow')

        signals.followed.connect(group_follow_handler,
                                 sender=Group,
                                 dispatch_uid='groupfollow')
        signals.unfollowed.connect(group_unfollow_handler,
                                   sender=Group,
                                   dispatch_uid='groupunfollow')

        utils.follow(self.lennon, self.hendrix)
        utils.unfollow(self.lennon, self.hendrix)
        self.assertEqual(2, user_handler.i)

        utils.follow(self.lennon, self.musicians)
        utils.unfollow(self.lennon, self.musicians)

        self.assertEqual(2, user_handler.i)
        self.assertEqual(2, group_handler.i)
Exemplo n.º 3
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.º 4
0
Arquivo: views.py Projeto: twlopes/sp
def micro_cons(request):
	errors = []
	
	# Bootstrap toolkit specification

	layout = 'horizontal'

	if request.method == 'POST':
		
		cons_form = MicroConsModelForm(request.POST)
		article_form = ArticleModelForm(request.POST)
		
		if cons_form.is_valid() and article_form.is_valid():
			
			cons = cons_form.save(commit=False)
			article = article_form.save(commit=False)
			cons.director = request.user
			
			# saving constitution model form			

			cons_form.save()
			
			# Grab id and director name for cons just created

			saved_cons_id = cons.id
			saved_cons_director = cons.director
			
			# Save constitution id to the article model form.

			article.cons_id = saved_cons_id
			article.version_id = 1
			article.cons_id_key = MicroCons.objects.get(id=article.cons_id)
			article_form.save()

			# Grab relevant objects
			
			constitution = MicroCons.objects.get(id=saved_cons_id)
			user = User.objects.get(username=saved_cons_director)

			# Give user permission for constitution

			assign('change_microcons', user, constitution)

			# Make user follow changes to constitution

			utils.follow(user, constitution)
			
			return HttpResponseRedirect('/done')
	else:
		cons_form = MicroConsModelForm()
		article_form = ArticleModelForm()
	return render_to_response('cons_form.html', {'form': cons_form, 'article_form': article_form}, 
		context_instance=RequestContext(request, {'layout': layout,}))
Exemplo n.º 5
0
    def process_following(self, request, obj, success_url):
        user = request.user
        kwargs = {}
        if not user == obj:
            is_following = Follow.objects.is_following(user, obj)
            follow_obj = unfollow(user, obj) if is_following else \
                follow(user, obj)
            is_following = not is_following

            if follow_obj.target.__class__ is User:
                if is_following:
                    mail_followee(request, follow_obj.target, user)
                title = user_display(follow_obj.target)
            else:
                title = unicode(follow_obj.target)

            key = "follow" if is_following else "unfollow"
            kwargs.update({"object": title})
        else:
            key = "follow-warning"
        add_message(key, request, **kwargs)

        if request.is_ajax():
            messages = render_messages(request)
            data = {"is_following": is_following, "messages": messages}
            return HttpResponse(json.dumps(data), mimetype="application/json")
        else:
            return HttpResponseRedirect(success_url)
Exemplo n.º 6
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.º 7
0
 def test_signals(self):
     Handler = type('Handler', (object,), {
         'inc': lambda self: setattr(self, 'i', getattr(self, 'i') + 1),
         'i': 0
     })
     user_handler = Handler()
     group_handler = Handler()
     
     def follow_handler(sender, user, target, instance, **kwargs):
         self.assertEqual(sender, User)
         self.assertEqual(self.lennon, user)
         self.assertEqual(self.hendrix, target)
         self.assertEqual(True, isinstance(instance, Follow))
         user_handler.inc()
     
     def unfollow_handler(sender, user, target, instance, **kwargs):
         self.assertEqual(sender, User)
         self.assertEqual(self.lennon, user)
         self.assertEqual(self.hendrix, target)
         self.assertEqual(True, isinstance(instance, Follow))
         user_handler.inc()
     
     def group_follow_handler(sender, **kwargs):
         self.assertEqual(sender, Group)
         group_handler.inc()        
     
     def group_unfollow_handler(sender, **kwargs):
         self.assertEqual(sender, Group)
         group_handler.inc()
     
     signals.followed.connect(follow_handler, sender=User, dispatch_uid='userfollow')
     signals.unfollowed.connect(unfollow_handler, sender=User, dispatch_uid='userunfollow')
     
     signals.followed.connect(group_follow_handler, sender=Group, dispatch_uid='groupfollow')
     signals.unfollowed.connect(group_unfollow_handler, sender=Group, dispatch_uid='groupunfollow')
     
     utils.follow(self.lennon, self.hendrix)
     utils.unfollow(self.lennon, self.hendrix)
     self.assertEqual(2, user_handler.i)
     
     utils.follow(self.lennon, self.musicians)
     utils.unfollow(self.lennon, self.musicians)
     
     self.assertEqual(2, user_handler.i)
     self.assertEqual(2, group_handler.i)
Exemplo n.º 8
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.º 9
0
    def test_get_follows_for_queryset(self):
        utils.follow(self.hendrix, self.lennon)
        utils.follow(self.lennon, self.hendrix)

        result = Follow.objects.get_follows(User.objects.all())
        self.assertEqual(2, result.count())
Exemplo n.º 10
0
 def test_get_follows_for_queryset(self):
     utils.follow(self.hendrix, self.lennon)
     utils.follow(self.lennon, self.hendrix)
     
     result = Follow.objects.get_follows(User.objects.all())
     self.assertEqual(2, result.count())