Support a `badges` list alongside optional `update_badges()` method in `badges.py` modules
This commit is contained in:
Родитель
943d687d15
Коммит
f0ab6bb178
|
@ -8,6 +8,7 @@ from django.utils.importlib import import_module
|
|||
from django.utils.module_loading import module_has_submodule
|
||||
|
||||
import badger
|
||||
import badger.utils
|
||||
|
||||
|
||||
if "notification" in settings.INSTALLED_APPS:
|
||||
|
@ -53,6 +54,8 @@ def update_badges(overwrite=False):
|
|||
badges_mod = import_module('%s.badges' % app)
|
||||
fixture_label = '%s_badges' % app.replace('.','_')
|
||||
call_command('loaddata', fixture_label, verbosity=1)
|
||||
if hasattr(badges_mod, 'badges'):
|
||||
badger.utils.update_badges(badges_mod.badges, overwrite)
|
||||
if hasattr(badges_mod, 'update_badges'):
|
||||
badges_mod.update_badges(overwrite)
|
||||
except ImportError, e:
|
||||
|
|
|
@ -140,18 +140,19 @@ class BadgesPyTest(BadgerTestCase):
|
|||
"""Upon completing collection of badges, award a meta-badge"""
|
||||
user = self._get_user()
|
||||
|
||||
ok_(not get_badge('master-badger').is_awarded_to(user))
|
||||
|
||||
# Cover a few bases on award creation...
|
||||
award_badge('test-1', user)
|
||||
award_badge('test-2', user)
|
||||
a = Award(badge=get_badge('button-clicker'), user=user)
|
||||
a.save()
|
||||
Award.objects.create(badge=get_badge('awesomeness'), user=user)
|
||||
|
||||
ok_(get_badge('master-badger').is_awarded_to(user))
|
||||
|
||||
get_badge('awesomeness').award_to(user)
|
||||
eq_(1, Award.objects.filter(badge=get_badge("master-badger"),
|
||||
user=user).count())
|
||||
|
||||
ok_(get_badge('master-badger').is_awarded_to(user))
|
||||
|
||||
def test_progress_quiet_save(self):
|
||||
"""Progress will not raise a BadgeAlreadyAwardedException unless told"""
|
||||
|
|
|
@ -13,7 +13,10 @@ def update_badges(badge_data, overwrite=False):
|
|||
return badges
|
||||
|
||||
|
||||
def update_badge(data, overwrite=False):
|
||||
def update_badge(data_in, overwrite=False):
|
||||
# Clone the data, because we might delete fields
|
||||
data = dict(**data_in)
|
||||
|
||||
# If there are prerequisites, ensure they're real badges and remove
|
||||
# from the set of data fields.
|
||||
if 'prerequisites' not in data:
|
||||
|
|
|
@ -11,32 +11,36 @@ from badger.models import Badge, Award, Progress
|
|||
from badger.signals import badge_was_awarded
|
||||
|
||||
|
||||
badges = [
|
||||
|
||||
dict(slug="test-2",
|
||||
title="Test #2",
|
||||
description="Second badge"),
|
||||
|
||||
dict(slug="awesomeness",
|
||||
title="Awesomeness (you have it)",
|
||||
description="Badge with a slug not derived from title."),
|
||||
|
||||
dict(slug="250-words",
|
||||
title="250 Words",
|
||||
description="You've posted 250 words to my guestbook!"),
|
||||
|
||||
dict(slug="250-words-by-percent",
|
||||
title="100% of 250 Words",
|
||||
description="You've posted 100% of 250 words to my guestbook!"),
|
||||
|
||||
]
|
||||
|
||||
|
||||
def update_badges(overwrite=False):
|
||||
badges = [
|
||||
|
||||
dict(slug="test-2",
|
||||
title="Test #2",
|
||||
description="Second badge"),
|
||||
|
||||
dict(slug="awesomeness",
|
||||
title="Awesomeness (you have it)",
|
||||
description="Badge with a slug not derived from title."),
|
||||
|
||||
dict(slug="250-words",
|
||||
title="250 Words",
|
||||
description="You've posted 250 words to my guestbook!"),
|
||||
|
||||
dict(slug="250-words-by-percent",
|
||||
title="100% of 250 Words",
|
||||
description="You've posted 100% of 250 words to my guestbook!"),
|
||||
|
||||
dict(slug="master-badger",
|
||||
title="Master Badger",
|
||||
description="You've collected all badges",
|
||||
prerequisites=('test-1', 'test-2', 'awesomeness',
|
||||
'button-clicker')),
|
||||
|
||||
]
|
||||
|
||||
return badger.utils.update_badges(badges, overwrite)
|
||||
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче