]> git.openstreetmap.org Git - osqa.git/blob - forum/actions/user.py
Fix problem with dummy actions. Also try coercion of settings to the same type as...
[osqa.git] / forum / actions / user.py
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
6 \r
7 class UserJoinsAction(ActionProxy):\r
8     def repute_users(self):\r
9         self.repute(self.user, int(settings.INITIAL_REP))\r
10 \r
11 class EditProfileAction(ActionProxy):\r
12     pass\r
13 \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
18 \r
19     def process_action(self):\r
20         badge = self.__dict__['_badge']\r
21         trigger = self.__dict__['_trigger']\r
22 \r
23         award = Award(user=self.user, badge=badge, trigger=trigger, action=self)\r
24         if self.node:\r
25             award.node = self.node\r
26 \r
27         award.save()\r
28         award.badge.awarded_count = F('awarded_count') + 1\r
29         award.badge.save()\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
33 \r
34     def cancel_action(self):\r
35         award = self.award\r
36         badge = award.badge\r
37         badge.awarded_count = F('awarded_count') - 1\r
38         badge.save()\r
39         award.delete()\r
40 \r
41     @classmethod\r
42     def get_for(cls, user, badge, node=False):\r
43         try:\r
44             if node is False:\r
45                 return Award.objects.get(user=user, badge=badge).action\r
46             else:\r
47                 return Award.objects.get(user=user, node=node, badge=badge).action\r
48         except:\r
49             return None\r
50 \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
56         }