1 from django.utils.translation import ugettext as _
\r
2 from django.db.models import F
\r
3 from forum.models.action import ActionProxy
\r
4 from forum.models import Award
\r
5 from forum import settings
\r
7 class UserJoinsAction(ActionProxy):
\r
8 def repute_users(self):
\r
9 self.repute(self.user, int(settings.INITIAL_REP))
\r
11 class EditProfileAction(ActionProxy):
\r
14 class AwardAction(ActionProxy):
\r
15 def process_data(self, badge, trigger):
\r
16 self.__dict__['_badge'] = badge
\r
17 self.__dict__['_trigger'] = trigger
\r
19 def process_action(self):
\r
20 badge = self.__dict__['_badge']
\r
21 trigger = self.__dict__['_trigger']
\r
23 award = Award(user=self.user, badge=badge, trigger=trigger, action=self)
\r
25 award.node = self.node
\r
28 award.badge.awarded_count = F('awarded_count') + 1
\r
30 self.user.message_set.create(message=_("Congratulations, you have received a badge '%(badge_name)s'. " \
\r
31 + u"Check out <a href=\"%(profile_url)s\">your profile</a>.") % dict(badge_name=award.badge.name,
\r
32 profile_url=self.user.get_profile_url()))
\r
34 def cancel_action(self):
\r
37 badge.awarded_count = F('awarded_count') - 1
\r
42 def get_for(cls, user, node, badge):
\r
44 award = Award.objects.get(user=user, node=node, badge=badge)
\r
49 def describe(self, viewer=None):
\r
50 return _("%(user)s was awarded the %(badge_name)s badge") % {
\r
51 'user': self.hyperlink(self.user.get_profile_url(), self.friendly_username(viewer, self.user)),
\r
52 'badge_name': self.award.all()[0].badge.name,
\r