Esempio n. 1
0
File: user.py Progetto: nghitran/qaa
    def process_action(self):
        badge = self.__dict__['_badge']
        trigger = self.__dict__['_trigger']

        award = Award(user=self.user, badge=badge, trigger=trigger, action=self)
        if self.node:
            award.node = self.node

        award.save()
        award.badge.awarded_count = F('awarded_count') + 1
        award.badge.save()

        if award.badge.type == Badge.GOLD:
            self.user.gold += 1
        if award.badge.type == Badge.SILVER:
            self.user.silver += 1
        if award.badge.type == Badge.BRONZE:
            self.user.bronze += 1

        self.user.save()

        offline_msg_utils.create_offline_message(self.user, message=_(
                """Congratulations, you have received a badge '%(badge_name)s'. Check out <a href=\"%(profile_url)s\">your profile</a>."""
                ) %
        dict(badge_name=award.badge.name, profile_url=self.user.get_profile_url()), level=offline_msg_utils.constants.SUCCESS)
Esempio n. 2
0
    def create_offline_message(self, user, message=None, level=None):
        if not message:
            message = self.test_message

        if not level:
            level = self.test_level

        create_offline_message(user, message, level)
Esempio n. 3
0
File: user.py Progetto: nghitran/qaa
    def repute_users(self):
        self.repute(self._affected, self._value)

        if self._value > 0:
            offline_msg_utils.create_offline_message(self._affected, 
                    message=_("Congratulations, you have been awarded an extra %s reputation points.") % self._value +
                    '<br />%s' % self.extra.get('message', _('Thank you')), level=offline_msg_utils.constants.SUCCESS)
        else:
            offline_msg_utils.create_offline_message(self._affected,
                    message=_("You have been penalized in %s reputation points.") % self._value +
                    '<br />%s' % self.extra.get('message', ''), level=offline_msg_utils.constants.WARNING)
 def form_valid(self, form):
     message_kwargs = {'level' : form.cleaned_data['level']}
     if form.cleaned_data['expiration']:
         message_kwargs['content_object'] = OfflineExpiration.objects.create(datetime=form.cleaned_data['expiration'])
     if form.cleaned_data['groups']:
         users = User.objects.filter(groups__in=form.cleaned_data['groups']).distinct()
     else:
         users = User.objects.all()
     for user in users:
         create_offline_message(user, form.cleaned_data['message'], **message_kwargs)
     return super(OfflineGroupMessageView, self).form_valid(form)
 def _store(self, messages, *args, **kwargs):
     """ 
     Store messages. If logged in, store them offline, else, store in session.
     """
     if hasattr(self.request, 'user') and self.request.user.is_authenticated():
         for msg in messages:
             # just the basics, if you need the extra meta data, do this manually
             # and add the extra kwargs
             create_offline_message(self.request.user, msg.message, msg.level)
     else:
         messages = [msg for msg in messages if not isinstance(msg, OfflineMessage)]
         return super(OfflineStorageEngine, self)._store(messages, *args, **kwargs)
Esempio n. 6
0
 def _store(self, messages, *args, **kwargs):
     """ 
     Store messages. If logged in, store them offline, else, store in session.
     """
     if hasattr(self.request,
                'user') and self.request.user.is_authenticated():
         for msg in messages:
             # just the basics, if you need the extra meta data, do this manually
             # and add the extra kwargs
             create_offline_message(self.request.user, msg.message,
                                    msg.level)
     else:
         messages = [
             msg for msg in messages if not isinstance(msg, OfflineMessage)
         ]
         return super(OfflineStorageEngine,
                      self)._store(messages, *args, **kwargs)
Esempio n. 7
0
def add_message(user, level, message, content_object=None, meta={}):
    user = get_user(user)
    if not user:
        return None
    return messages_utils.create_offline_message(user,
                                                 message,
                                                 level,
                                                 content_object=content_object,
                                                 meta=meta)
Esempio n. 8
0
File: user.py Progetto: nghitran/qaa
 def cancel_action(self):
     for u in User.objects.filter(reputes__action=self).distinct():
         u.is_active = True
         u._pop_suspension_cache()
         u.save()
         offline_msg_utils.create_offline_message(u, message=_("Your suspension has been removed."), level=offline_msg_utils.constants.INFO)
Esempio n. 9
0
def add_message(user, level, message, content_object=None, meta={}):
    user = get_user(user)
    if not user:
        return None
    return messages_utils.create_offline_message(user, message, level, content_object=content_object, meta=meta)