Skip to content
This repository has been archived by the owner on Nov 25, 2017. It is now read-only.

Commit

Permalink
Fixed the way storymarket choice fields generate choices.
Browse files Browse the repository at this point in the history
Now API methods aren't called at module load time.
  • Loading branch information
jacobian committed Aug 2, 2010
1 parent 083b832 commit 8d182d0
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions django_storymarket/forms.py
Expand Up @@ -17,9 +17,12 @@ class StorymarketAPIChoiceField(forms.ChoiceField):
"""

def __init__(self, *args, **kwargs):
super(StorymarketAPIChoiceField, self).__init__(choices=self._get_choices(), *args, **kwargs)
# Skip ChoiceField's initializer since we're handling choices
# via the property below.
super(forms.ChoiceField, self).__init__(*args, **kwargs)

def _get_choices(self):
@property
def choices(self):
# Return a list of choices sorted by name, along with an empty choice.
cache_key = 'storymarket_choice_cache:%s' % self.__class__.__name__
choices = cache.get(cache_key)
Expand Down

0 comments on commit 8d182d0

Please sign in to comment.