Esempio n. 1
0
    def __new__(mcs, name, bases, dic):
        badge = type.__new__(mcs, name, bases, dic)

        if not dic.get('abstract', False):
            if not name in installed:
                ondb = Badge(cls=name, type=dic.get('type', Badge.BRONZE))
                ondb.save()
            else:
                ondb = installed[name]

            badge.ondb = ondb.id

            inst = badge()

            def hook(action, new):
                user = inst.award_to(action)

                if user:
                    badge.award(user, action, badge.award_once)

            for action in badge.listen_to:
                action.hook(hook)

            BadgesMeta.by_class[name] = inst
            BadgesMeta.by_id[ondb.id] = inst

        return badge
Esempio n. 2
0
    def __new__(mcs, name, bases, dic):
        badge = type.__new__(mcs, name, bases, dic)

        if not dic.get('abstract', False):
            if not name in installed:
                ondb = Badge(cls=name, type=dic.get('type', Badge.BRONZE))
                ondb.save()
            else:
                ondb = installed[name]

            badge.ondb = ondb.id

            inst = badge()

            def hook(action, new):
                user = inst.award_to(action)

                if user:
                    badge.award(user, action, badge.award_once)

            for action in badge.listen_to:
                action.hook(hook)

            BadgesMeta.by_class[name] = inst
            BadgesMeta.by_id[ondb.id] = inst

        return badge
Esempio n. 3
0
 def install(self):
     try:
         installed = Badge.objects.get(slug=self.badge)
     except:
         badge = Badge(name=self.name,
                       description=self.description,
                       slug=self.badge,
                       type=self.type)
         badge.save()
Esempio n. 4
0
File: base.py Progetto: igorgue/osqa
 def install(self):
     try:
         installed = Badge.objects.get(slug=self.badge)
     except:
         badge = Badge(name=self.name, description=self.description, slug=self.badge, type=self.type)
         badge.save()