summaryrefslogtreecommitdiff
path: root/packages
diff options
context:
space:
mode:
authorNicolás Reynolds <fauno@kiwwwi.com.ar>2011-03-18 16:11:31 -0300
committerNicolás Reynolds <fauno@kiwwwi.com.ar>2011-03-18 16:11:31 -0300
commit37075e5f3423a69fec03faf31ce2133c55374dfc (patch)
tree7403d5eefd5f20ab2a496dbbb9d9841b06e2e385 /packages
parent30b2a1954d5bf63c78fe654a0c0bb98508e2f3e2 (diff)
parentaca7700dd7519d45e677e18b1a0199f3712ce140 (diff)
Merge branch 'master' of git://projects.archlinux.org/archweb
Conflicts: templates/packages/details.html templates/packages/files.html
Diffstat (limited to 'packages')
-rw-r--r--packages/templatetags/package_extras.py19
-rw-r--r--packages/utils.py2
-rw-r--r--packages/views.py59
3 files changed, 51 insertions, 29 deletions
diff --git a/packages/templatetags/package_extras.py b/packages/templatetags/package_extras.py
index d59a5562..dd5b9347 100644
--- a/packages/templatetags/package_extras.py
+++ b/packages/templatetags/package_extras.py
@@ -1,4 +1,9 @@
-import cgi, urllib
+import urllib
+try:
+ from urlparse import parse_qs
+except ImportError:
+ from cgi import parse_qs
+
from django import template
from django.utils.html import escape
@@ -9,15 +14,15 @@ class BuildQueryStringNode(template.Node):
self.sortfield = sortfield
def render(self, context):
- qs = dict(cgi.parse_qsl(context['current_query'][1:]))
- if qs.has_key('sort') and qs['sort'] == self.sortfield:
+ qs = parse_qs(context['current_query'])
+ if qs.has_key('sort') and self.sortfield in qs['sort']:
if self.sortfield.startswith('-'):
- qs['sort'] = self.sortfield[1:]
+ qs['sort'] = [self.sortfield[1:]]
else:
- qs['sort'] = '-' + self.sortfield
+ qs['sort'] = ['-' + self.sortfield]
else:
- qs['sort'] = self.sortfield
- return '?' + urllib.urlencode(qs)
+ qs['sort'] = [self.sortfield]
+ return urllib.urlencode(qs, True)
@register.tag(name='buildsortqs')
def do_buildsortqs(parser, token):
diff --git a/packages/utils.py b/packages/utils.py
index 8d9f13ab..29a3087f 100644
--- a/packages/utils.py
+++ b/packages/utils.py
@@ -96,6 +96,8 @@ SELECT p.id, q.id
p.pkgver != q.pkgver
OR
p.pkgrel != q.pkgrel
+ OR
+ p.epoch != q.epoch
)
"""
cursor = connection.cursor()
diff --git a/packages/views.py b/packages/views.py
index 59779fe4..4101c538 100644
--- a/packages/views.py
+++ b/packages/views.py
@@ -126,6 +126,25 @@ def getmaintainer(request, name, repo, arch):
return HttpResponse(str('\n'.join(names)), mimetype='text/plain')
+def coerce_limit_value(value):
+ if not value:
+ return None
+ if value == 'all':
+ # negative value indicates show all results
+ return -1
+ value = int(value)
+ if value < 0:
+ raise ValueError
+ return value
+
+class LimitTypedChoiceField(forms.TypedChoiceField):
+ def valid_value(self, value):
+ try:
+ coerce_limit_value(value)
+ return True
+ except ValueError, TypeError:
+ return False
+
class PackageSearchForm(forms.Form):
repo = forms.MultipleChoiceField(required=False)
arch = forms.MultipleChoiceField(required=False)
@@ -136,25 +155,12 @@ class PackageSearchForm(forms.Form):
flagged = forms.ChoiceField(
choices=[('', 'All')] + make_choice(['Flagged', 'Not Flagged']),
required=False)
- limit = forms.ChoiceField(
+ limit = LimitTypedChoiceField(
choices=make_choice([50, 100, 250]) + [('all', 'All')],
+ coerce=coerce_limit_value,
required=False,
initial=50)
- def clean_limit(self):
- limit = self.cleaned_data['limit']
- if limit == 'all':
- limit = None
- elif limit:
- try:
- limit = int(limit)
- except:
- raise forms.ValidationError("Should be an integer")
- else:
- limit = 50
- return limit
-
-
def __init__(self, *args, **kwargs):
super(PackageSearchForm, self).__init__(*args, **kwargs)
self.fields['repo'].choices = make_choice(
@@ -168,12 +174,10 @@ class PackageSearchForm(forms.Form):
[(m.username, m.get_full_name()) for m in maints]
def search(request, page=None):
- current_query = '?'
limit = 50
packages = Package.objects.select_related('arch', 'repo')
if request.GET:
- current_query += request.GET.urlencode()
form = PackageSearchForm(data=request.GET)
if form.is_valid():
if form.cleaned_data['repo']:
@@ -188,7 +192,8 @@ def search(request, page=None):
inner_q = PackageRelation.objects.all().values('pkgbase')
packages = packages.exclude(pkgbase__in=inner_q)
elif form.cleaned_data['maintainer']:
- inner_q = PackageRelation.objects.filter(user__username=form.cleaned_data['maintainer']).values('pkgbase')
+ inner_q = PackageRelation.objects.filter(
+ user__username=form.cleaned_data['maintainer']).values('pkgbase')
packages = packages.filter(pkgbase__in=inner_q)
if form.cleaned_data['flagged'] == 'Flagged':
@@ -204,16 +209,26 @@ def search(request, page=None):
lu = form.cleaned_data['last_update']
packages = packages.filter(last_update__gte=
datetime(lu.year, lu.month, lu.day, 0, 0))
- 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()
else:
form = PackageSearchForm()
- page_dict = {'search_form': form,
- 'current_query': current_query
- }
if packages.count() == 1:
return redirect(packages[0])
+ current_query = request.GET.urlencode()
+ page_dict = {
+ 'search_form': form,
+ 'current_query': current_query
+ }
allowed_sort = ["arch", "repo", "pkgname", "last_update", "flag_date"]
allowed_sort += ["-" + s for s in allowed_sort]
sort = request.GET.get('sort', None)