]> git.openstreetmap.org Git - osqa.git/blob - forum/actions/user.py
Show the svn version in new admin.
[osqa.git] / forum / actions / user.py
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
6 from forum.settings import APP_SHORT_NAME
7
8 class UserJoinsAction(ActionProxy):
9     def repute_users(self):
10         self.repute(self.user, int(settings.INITIAL_REP))
11
12     def describe(self, viewer=None):
13         return _("%(user)s as joined the %(app_name)s Q&A community") % {
14             'user': self.hyperlink(self.user.get_profile_url(), self.friendly_username(viewer, self.user)),
15             'app_name': APP_SHORT_NAME,
16         }
17
18 class EditProfileAction(ActionProxy):
19     def describe(self, viewer=None):
20         return _("%(user)s edited %(hes_or_your)s %(profile_link)s") % {
21             'user': self.hyperlink(self.user.get_profile_url(), self.friendly_username(viewer, self.user)),
22             'hes_or_your': self.viewer_or_user_verb(viewer, self.user, _('your'), _('hes')),
23             'profile_link': self.hyperlink(self.user.get_profile_url(), _('profile')),
24         }
25
26 class AwardAction(ActionProxy):
27     def process_data(self, badge, trigger):
28         self.__dict__['_badge'] = badge
29         self.__dict__['_trigger'] = trigger
30
31     def process_action(self):
32         badge = self.__dict__['_badge']
33         trigger = self.__dict__['_trigger']
34
35         award = Award(user=self.user, badge=badge, trigger=trigger, action=self)
36         if self.node:
37             award.node = self.node
38
39         award.save()
40         award.badge.awarded_count = F('awarded_count') + 1
41         award.badge.save()
42         self.user.message_set.create(message=_("""Congratulations, you have received a badge '%(badge_name)s'
43                                      Check out <a href=\"%(profile_url)s\">your profile</a>.""") %
44                                      dict(badge_name=award.badge.name, profile_url=self.user.get_profile_url()))
45
46     def cancel_action(self):
47         award = self.award
48         badge = award.badge
49         badge.awarded_count = F('awarded_count') - 1
50         badge.save()
51         award.delete()
52
53     @classmethod
54     def get_for(cls, user, badge, node=False):
55         try:
56             if node is False:
57                 return Award.objects.get(user=user, badge=badge).action
58             else:
59                 return Award.objects.get(user=user, node=node, badge=badge).action
60         except:
61             return None
62
63     def describe(self, viewer=None):
64         return _("%(user)s %(were_was)s awarded the %(badge_name)s badge") % {
65             'user': self.hyperlink(self.user.get_profile_url(), self.friendly_username(viewer, self.user)),
66             'were_was': self.viewer_or_user_verb(viewer, self.user, _('were'), _('was')),
67             'badge_name': self.award.badge.name,
68         }