Friday, January 30, 2015

Re: How to get hold of a session after getting signaled?

As far as I can tell on the project source, the only place the "badge_awarded" signal is triggered is in the "award_to" method in the Badge class, which does not handle a request object.

If you are calling something like "badge.award_to(user)" in one of your views, then you can modify the request response immediately after, without using the signal.

On Fri, Jan 30, 2015 at 1:19 PM, Tobias Dacoir <falc410@gmail.com> wrote:
I'm using django-badges in my project which can emit a signal when a user is awarded a badge. I was able to implemented a receiver function, however the output is the following:

signals.py (from badges):
import django.dispatch

badge_awarded
= django.dispatch.Signal(providing_args=['user', 'badge'])



my receiver function test:

from badges.signals import badge_awarded
@receiver(badge_awarded)
def do_something_after_badge_awarded(sender, user, badge, **kwargs):
   
print "Badge Signal received"
   
print sender # <play.meta_badges.neueBadge object at 0x109733d90>
   
print user # user object
   
print badge # badge object
   
print kwargs



and the output was:
Badge Signal received
<play.meta_badges.neueBadge object at 0x109733d90>
player1
Test Badge 2
{'signal': <django.dispatch.dispatcher.Signal object at 0x1096da4d0>}


I want to add a message to the request, to notify or show the user that he earned a badge. Is it possible someone get hold of the request? I can freely modify the original source code from django-badges. Currently it's invoked by post_save() on a model instance. So I doubt I can get the request from there.

I found a solution to add another 3rd party app which is called django-notification, but I don't want to add too many apps to my project. Another solution might be to just set some variable in the database and in my view to query this variable - however that will also cost performance and two database hits.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/5e8f655c-8385-46aa-94ae-2c5baef2034a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CALn3ei1Q8cCtBgmsAQV%2BN_o3-5i-%2BrACxMXJXX3Gc%2BQhbtqkQw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment