From e5da38dce9b5ff481d4cf9f12cf073f5648c59d1 Mon Sep 17 00:00:00 2001 From: Evgeny Fadeev Date: Sun, 11 Mar 2012 20:58:42 -0500 Subject: replaced the unnecessary hack for dealing with deleted badges with the code that automatically updates the badge data at startup --- askbot/models/badges.py | 5 +++++ askbot/models/repute.py | 19 ------------------- askbot/views/meta.py | 6 ------ 3 files changed, 5 insertions(+), 25 deletions(-) diff --git a/askbot/models/badges.py b/askbot/models/badges.py index b909b7e1..61149df3 100644 --- a/askbot/models/badges.py +++ b/askbot/models/badges.py @@ -878,6 +878,11 @@ def init_badges(): #from the __init__ function? for key in BADGES.keys(): get_badge(key).get_stored_data() + #remove any badges from the database + #that are no longer in the BADGES dictionary + BadgeData.objects.exclude( + slug__in = map(slugify, BADGES.keys()) + ).delete() award_badges_signal = Signal( providing_args=[ diff --git a/askbot/models/repute.py b/askbot/models/repute.py index aa6287c2..5f582c0c 100644 --- a/askbot/models/repute.py +++ b/askbot/models/repute.py @@ -23,25 +23,6 @@ class BadgeData(models.Model): #return a dummy badge return badges.Badge(level = const.BRONZE_BADGE) - def is_real_badge(self): - """true if badge with a given slug exists - todo: may need attention - currently some badge data is defined in a file, - and some in the database. Data in the file is considered - more up to date. It is possifle that the file is edited, - and data is not deleted from the database, this method - will find such condition. - - The reason why some data is on disk, is that each - badge has code associated with them, that code is not stored in the database. - Therefore maintenance of badge data requires more attention... - """ - from askbot.models import badges - try: - badges.get_badge(self.slug) - return True - except KeyError: - return False - @property def name(self): return self._get_meta_data().name diff --git a/askbot/views/meta.py b/askbot/views/meta.py index 5cd17005..b2f09cf4 100644 --- a/askbot/views/meta.py +++ b/askbot/views/meta.py @@ -127,12 +127,6 @@ def badges(request):#user status/reputation system def badge(request, id): #todo: supplement database data with the stuff from badges.py badge = get_object_or_404(BadgeData, id=id) - if not badge.is_real_badge(): - #this is a hack around a non-elegant badge data system - #a request can come for a badge that is no longer used - #for example from a search engine that knows of past - #url structure - raise Http404 badge_recipients = User.objects.filter( award_user__badge = badge -- cgit v1.2.3-1-g7c22