]> git.openstreetmap.org Git - osqa.git/blob - forum/actions/user.py
Closing OSQA 102, the ip address on the feedback email is empty.
[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
7 class UserJoinsAction(ActionProxy):
8     def repute_users(self):
9         self.repute(self.user, int(settings.INITIAL_REP))
10
11 class EditProfileAction(ActionProxy):
12     pass
13
14 class AwardAction(ActionProxy):
15     def process_data(self, badge, trigger):
16         self.__dict__['_badge'] = badge
17         self.__dict__['_trigger'] = trigger
18
19     def process_action(self):
20         badge = self.__dict__['_badge']
21         trigger = self.__dict__['_trigger']
22
23         award = Award(user=self.user, badge=badge, trigger=trigger, action=self)
24         if self.node:
25             award.node = self.node
26
27         award.save()
28         award.badge.awarded_count = F('awarded_count') + 1
29         award.badge.save()
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()))
33
34     def cancel_action(self):
35         award = self.award
36         badge = award.badge
37         badge.awarded_count = F('awarded_count') - 1
38         badge.save()
39         award.delete()
40
41     @classmethod
42     def get_for(cls, user, badge, node=False):
43         try:
44             if node is False:
45                 return Award.objects.get(user=user, badge=badge).action
46             else:
47                 return Award.objects.get(user=user, node=node, badge=badge).action
48         except:
49             return None
50
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,
56         }