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 Check out <a href=\"%(profile_url)s\">your profile</a>.""") %
\r
32 dict(badge_name=award.badge.name, 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, badge, node=False):
\r
45 return Award.objects.get(user=user, badge=badge).action
\r
47 return Award.objects.get(user=user, node=node, badge=badge).action
\r
51 def describe(self, viewer=None):
\r
52 return _("%(user)s %(were_was)s awarded the %(badge_name)s badge") % {
\r
53 'user': self.hyperlink(self.user.get_profile_url(), self.friendly_username(viewer, self.user)),
\r
54 'were_was': self.viewer_or_user_verb(viewer, self.user, _('were'), _('was')),
\r
55 'badge_name': self.award.all()[0].badge.name,
\r