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