summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--devel/views.py4
-rw-r--r--packages/views.py61
-rw-r--r--templates/packages/search.html77
-rw-r--r--urls.py1
4 files changed, 99 insertions, 44 deletions
diff --git a/devel/views.py b/devel/views.py
index 77d4054b..b3724795 100644
--- a/devel/views.py
+++ b/devel/views.py
@@ -1,10 +1,10 @@
from django import forms
-from django.http import HttpResponse, HttpResponseRedirect
+from django.http import HttpResponseRedirect
from django.contrib.auth.models import User
from archweb_dev.main.utils import render_response
from archweb_dev.main.models import Package, Todolist
from archweb_dev.main.models import Arch, Repo
-from archweb_dev.main.models import UserProfile, News, Donor, Mirror
+from archweb_dev.main.models import UserProfile, News
def index(request):
'''the Developer dashboard'''
diff --git a/packages/views.py b/packages/views.py
index 87d42b75..a42c9d12 100644
--- a/packages/views.py
+++ b/packages/views.py
@@ -1,16 +1,12 @@
+import urllib
from django import forms
-from itertools import chain
from django.shortcuts import render_to_response
from django.template import RequestContext
from django.http import HttpResponseRedirect
from django.shortcuts import get_object_or_404
-from django.forms.util import flatatt
from django.contrib.auth.models import User
-from django.utils.safestring import mark_safe
-from django.utils.encoding import force_unicode
-from django.utils.html import escape, conditional_escape
from django.contrib.admin.widgets import AdminDateWidget
-from django.views.generic import list_detail, create_update
+from django.views.generic import list_detail
from datetime import datetime
from archweb_dev.main.utils import render_response
from archweb_dev.main.models import Package, PackageFile
@@ -61,8 +57,21 @@ class PackageSearchForm(forms.Form):
maintainer = forms.ChoiceField(required=False)
last_update = forms.DateField(required=False, widget=AdminDateWidget())
limit = forms.ChoiceField(
- choices=make_choice(['50', '100', '250', 'All']),
- required=False)
+ choices=make_choice([50, 100, 250]) + [('', 'All')],
+ required=False,
+ initial=50)
+
+ def clean_limit(self):
+ limit = self.cleaned_data['limit']
+ if limit:
+ try:
+ limit = int(limit)
+ except:
+ raise forms.ValidationError("Should be an integer")
+ else:
+ limit = None
+ return limit
+
def __init__(self, *args, **kwargs):
super(PackageSearchForm, self).__init__(*args, **kwargs)
@@ -73,20 +82,44 @@ class PackageSearchForm(forms.Form):
'arch'].widget.choices = [('', 'All')] + make_choice(
[arch.name for arch in Arch.objects.all()])
self.fields['maintainer'].choices = self.fields[
- 'maintainer'].widget.choices = [('', 'All')] + make_choice(
+ 'maintainer'].widget.choices = [
+ ('', 'All'), ('orphan', 'Orphan')] + make_choice(
[m.username for m in User.objects.all()])
-def search(request):
+def search(request, page=None):
+ current_query = '?'
+ limit=50
+ packages = Package.objects.all()
+
if request.GET:
+ current_query += urllib.urlencode(request.GET)
form = PackageSearchForm(data=request.GET)
if form.is_valid():
- pass
+ if form.cleaned_data['repo']:
+ packages = packages.filter(
+ repo__name=form.cleaned_data['repo'])
+ if form.cleaned_data['arch']:
+ packages = packages.filter(
+ arch__name=form.cleaned_data['arch'])
+ if form.cleaned_data['maintainer'] == 'orphan':
+ packages=packages.filter(maintainer__id = 0)
+ elif form.cleaned_data['maintainer']:
+ packages = packages.filter(
+ maintainer__username=form.cleaned_data['maintainer'])
+ limit = form.cleaned_data['limit']
+
else:
form = PackageSearchForm()
- page_dict = {'search_form': form}
- return render_to_response('packages/search.html',
- RequestContext(request, page_dict))
+ page_dict = {'search_form': form,
+ 'current_query': current_query
+ }
+ return list_detail.object_list(request, packages,
+ template_name="packages/search.html",
+ page=page,
+ paginate_by=limit,
+ template_object_name="package",
+ extra_context=page_dict)
diff --git a/templates/packages/search.html b/templates/packages/search.html
index a181801b..54d04ef7 100644
--- a/templates/packages/search.html
+++ b/templates/packages/search.html
@@ -10,7 +10,7 @@
{% block content %}
<div class="greybox">
<h4 style="text-align: right">Search Criteria</h4>
- <form method="get">
+ <form method="get" action="/packages/search/">
<table width="100%">
<tr>
<td><span class="smalltext">Arch</span></td>
@@ -34,48 +34,69 @@
</div>
<br /><br />
- {% if results %}
+ {% if package_list %}
<div class="greybox">
<table class="results" width="100%">
<tr>
<form method="post" action="/packages/update/">
<th>&nbsp;</th>
- <th><a href="{% buildsortqs "arch" %}">Arch</a></th>
- <th><a href="{% buildsortqs "repo" %}">Repo</a></th>
- <th><a href="{% buildsortqs "pkgname" %}">Name</a></th>
+ <th>Arch</th>
+ <th>Repo</th>
+ <th>Name</th>
<th>Version</th>
<th>Description</th>
- <th><a href="{% buildsortqs "maintainer" %}">Maintainer</a></th>
- <th><a href="{% buildsortqs "-last_update" %}">Last Updated</a></th>
+ <th>Maintainer</th>
+ <th>Last Updated</th>
</tr>
- {% for pkg in results %}
- <tr class="{% cycle pkgr2,pkgr1 %}">
- <td><input type="checkbox" name="pkgid" value="{{ pkg.id }}" /></td>
- <td>{{ pkg.arch.name }}</td>
- <td>{{ pkg.repo.name|capfirst }}</td>
- <td><a href="{{ pkg.get_absolute_url }}">{{ pkg.pkgname }}</a></td>
- {% if pkg.needupdate %}
- <td><span style="color:red">{{ pkg.pkgver }}-{{ pkg.pkgrel }}</span></td>
- {% else %}
- <td>{{ pkg.pkgver }}-{{ pkg.pkgrel }}</td>
+ {% for pkg in package_list %}
+ <tr class="{% cycle pkgr2,pkgr1 %}">
+ <td><input type="checkbox" name="pkgid" value="{{ pkg.id }}" /></td>
+ <td>{{ pkg.arch.name }}</td>
+ <td>{{ pkg.repo.name|capfirst }}</td>
+ <td><a href="{{ pkg.get_absolute_url }}">{{ pkg.pkgname }}</a></td>
+ {% if pkg.needupdate %}
+ <td><span style="color:red">{{ pkg.pkgver }}-{{ pkg.pkgrel }}</span></td>
+ {% else %}
+ <td>{{ pkg.pkgver }}-{{ pkg.pkgrel }}</td>
+ {% endif %}
+ <td>{{ pkg.pkgdesc }}</td>
+ <td>{{ pkg.maintainer|default:"Orphan" }}</td>
+ <td>{{ pkg.last_update|date:"Y-m-d" }}</td>
+ </tr>
+ {% endfor %}
+ {% if paginator %}
+ <tr>
+ <td colspan="6">
+ {{paginator.count}} packages found.
+ Page {{page_obj.number}} of {{paginator.num_pages}}.
+ </td>
+ <td>
+ {% if page_obj.has_previous %}
+ <a href="/packages/search/{{page_obj.previous_page_number}}/{{current_query}}">
+ &lt;&lt;&lt; Previous
+ </a>
+ {% else %}
+ &lt;&lt;&lt; Previous
+ {% endif %}
+ </td>
+ <td>
+ {% if page_obj.has_next %}
+ <a href="/packages/search/{{page_obj.next_page_number}}/{{current_query}}">
+ Next &gt;&gt;&gt;
+ </a>
+ {% else %} &gt;&gt;&gt;
+ Next
+ {% endif %}
+ </td>
+ <br />
+ </tr>
{% endif %}
- <td>{{ pkg.pkgdesc }}</td>
- <td>{{ pkg.maintainer|default:"Orphan" }}</td>
- <td>{{ pkg.last_update|date:"Y-m-d" }}</td>
- </tr>
- {% endfor %}
- <tr>
- <td colspan="2" style="font-size:x-small">{% if prevpage %}<br /><a href="{{ prevpage }}">&lt;&lt;&lt; Prev</a>{% endif %}</td>
- <td colspan="2">&nbsp;</td>
- <td colspan="2" style="font-size:x-small;text-align:right">{% if nextpage %}<br /><a href="{{ nextpage }}">Next &gt;&gt;&gt;</a>{% endif %}</td>
- </tr>
<tr>
<td colspan="3">&nbsp;</td>
<td colspan="2" style="text-align:center"><input type="submit" name="adopt" value="Adopt Packages"></td>
<td colspan="1" style="text-align:center"><input type="submit" name="disown" value="Disown Packages"></td>
<td colspan="1">&nbsp;</td>
</tr>
- </form>
</table>
</div>
{% endif %}
diff --git a/urls.py b/urls.py
index 55b9a370..a41bcc3d 100644
--- a/urls.py
+++ b/urls.py
@@ -16,6 +16,7 @@ urlpatterns = patterns('',
(r'^packages/signoff_package/(?P<arch>[A-z0-9]+)/(?P<pkgname>[A-z0-9\-+.]+)/$',
'archweb_dev.packages.views.signoff_package'),
(r'^packages/search/$', 'archweb_dev.packages.views.search'),
+ (r'^packages/search/(?P<page>\d+)/$', 'archweb_dev.packages.views.search'),
(r'^packages/update/$', 'archweb_dev.packages.views.update'),
(r'^packages/(?P<pkgid>\d+)/$', 'archweb_dev.packages.views.details'),
(r'^packages/(?P<name>[A-z0-9]+)/$', 'archweb_dev.packages.views.details'),