diff options
author | Lukas Fleischer <archlinux@cryptocrack.de> | 2011-03-16 09:03:38 +0100 |
---|---|---|
committer | Dan McGee <dan@archlinux.org> | 2011-03-16 08:49:49 -0500 |
commit | aca7700dd7519d45e677e18b1a0199f3712ce140 (patch) | |
tree | a27b9a31b48b0530f437586f65b531a23f78ea53 | |
parent | b0061f5bd99ef49733b4b66ef67dfd8f156785b1 (diff) |
Fix valid_value() in "LimitTypedChoiceField" class.
We just returned the coerced value in valid_value() which may become
None if the valid value "all" was passed, resulting in valid_value()
evaluating to False. Explicitly returning True if the value can be
coerced without an error fixes this.
Signed-off-by: Lukas Fleischer <archlinux@cryptocrack.de>
Signed-off-by: Dan McGee <dan@archlinux.org>
-rw-r--r-- | packages/views.py | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/packages/views.py b/packages/views.py index 70b3a84b..4101c538 100644 --- a/packages/views.py +++ b/packages/views.py @@ -128,9 +128,10 @@ def getmaintainer(request, name, repo, arch): def coerce_limit_value(value): if not value: - return 50 - if value == 'all': return None + if value == 'all': + # negative value indicates show all results + return -1 value = int(value) if value < 0: raise ValueError @@ -139,7 +140,8 @@ def coerce_limit_value(value): class LimitTypedChoiceField(forms.TypedChoiceField): def valid_value(self, value): try: - return coerce_limit_value(value) + coerce_limit_value(value) + return True except ValueError, TypeError: return False @@ -208,8 +210,11 @@ def search(request, page=None): packages = packages.filter(last_update__gte= datetime(lu.year, lu.month, lu.day, 0, 0)) - if form.cleaned_data['limit']: - limit = form.cleaned_data['limit'] + asked_limit = form.cleaned_data['limit'] + if asked_limit and asked_limit < 0: + limit = None + elif asked_limit: + limit = asked_limit else: # Form had errors, don't return any results, just the busted form packages = Package.objects.none() |