示例#1
0
    def award(self, recipient=None, context_object=None, timestamp=None):
        """do award, the recipient was proven to deserve,
        Returns True, if awarded, or False
        """
        from askbot.models.repute import Award
        if self.multiple == False:
            if recipient.badges.filter(slug=self.key).count() != 0:
                return False
        else:
            content_type = ContentType.objects.get_for_model(context_object)
            filters = {
                'user': recipient,
                'object_id': context_object.id,
                'content_type': content_type,
                'badge__slug': self.key,
            }
            #multiple badge is not re-awarded for the same post
            if Award.objects.filter(**filters).count() != 0:
                return False

        badge = self.get_stored_data()
        award = Award(user=recipient,
                      badge=badge,
                      awarded_at=timestamp,
                      content_object=context_object)
        award.save()  #note: there are signals that listen to saving the Award
        return True
示例#2
0
    def award(self, recipient = None, context_object = None, timestamp = None):
        """do award, the recipient was proven to deserve,
        Returns True, if awarded, or False
        """
        from askbot.models.repute import Award
        if self.multiple == False:
            if recipient.badges.filter(slug = self.key).count() != 0:
                return False
        else:
            content_type = ContentType.objects.get_for_model(context_object)
            filters = {
                'user': recipient,
                'object_id': context_object.id,
                'content_type': content_type,
                'badge__slug': self.key,
            }
            #multiple badge is not re-awarded for the same post
            if Award.objects.filter(**filters).count() != 0:
                return False

        badge = self.get_stored_data()
        award = Award(
                    user = recipient,
                    badge = badge,
                    awarded_at = timestamp,
                    content_object = context_object
                )
        award.save()#note: there are signals that listen to saving the Award
        return True
示例#3
0
    def award(self, recipient=None, context_object=None, timestamp=None):
        """do award, the recipient was proven to deserve"""

        if self.multiple == False:
            if recipient.badges.filter(slug=self.key).count() != 0:
                return False
        else:
            content_type = ContentType.objects.get_for_model(context_object)
            filters = {
                "user": recipient,
                "object_id": context_object.id,
                "content_type": content_type,
                "badge__slug": self.key,
            }
            # multiple badge is not re-awarded for the same post
            if Award.objects.filter(**filters).count() != 0:
                return False

        badge = self.get_stored_data()
        award = Award(user=recipient, badge=badge, awarded_at=timestamp, content_object=context_object)
        award.save()  # note: there are signals that listen to saving the Award
        return True