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
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()