-class AbstractBadge(object):
-
- _instance = None
-
- @property
- def name(self):
- return " ".join(re.findall(r'([A-Z][a-z1-9]+)', re.sub('Badge', '', self.__class__.__name__)))
-
- @property
- def description(self):
- raise NotImplementedError
-
- def __new__(cls, *args, **kwargs):
- if cls._instance is None:
- cls.badge = "-".join(map(lower, re.findall(r'([A-Z][a-z1-9]+)', re.sub('Badge', '', cls.__name__))))
- cls._instance = super(AbstractBadge, cls).__new__(cls, *args, **kwargs)
-
- return cls._instance
-
- 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()
-
- def award_badge(self, user, obj=None, award_once=False):
- try:
- badge = Badge.objects.get(slug=self.badge)
- except:
- logging.log('Trying to award a badge not installed in the database.')
- return
-
- content_type = ContentType.objects.get_for_model(obj.__class__)