diff options
-rw-r--r-- | media/arch.css | 29 | ||||
-rw-r--r-- | packages/templatetags/package_extras.py | 4 | ||||
-rw-r--r-- | packages/views.py | 66 | ||||
-rw-r--r-- | templates/forms/td_input.html | 5 | ||||
-rw-r--r-- | templates/packages/search.html | 89 | ||||
-rw-r--r-- | templates/packages/signoffs.html | 2 | ||||
-rw-r--r-- | urls.py | 1 |
7 files changed, 126 insertions, 70 deletions
diff --git a/media/arch.css b/media/arch.css index f1419fce..335e56b6 100644 --- a/media/arch.css +++ b/media/arch.css @@ -129,7 +129,7 @@ body { div.listing { padding-right: 10px; } -.error { +.error, .errorlist { color: #dd0000; font-size: small; } @@ -390,3 +390,30 @@ textarea.vLargeTextField { background-color: #eee4cb; } +/* override some calendar attributes copied from */ +/* CALENDARS & CLOCKS */ +.calendarbox, .clockbox { margin:5px auto; font-size:11px; width:16em; text-align:center; background:white; position:relative; } +.clockbox { width:9em; } +.calendar { margin:0; padding: 0; } +.calendar table { margin:0; padding:0; border-collapse:collapse; background:white; width:99%; } +.calendar caption, .calendarbox h2 { margin: 0; font-size:11px; text-align:center; border-top:none; } +.calendar th { font-size:10px; color:#666; padding:2px 3px; text-align:center; background:#e1e1e1 url(../img/admin/nav-bg.gif) 0 50% repeat-x; border-bottom:1px solid #ddd; } +.calendar td { font-size:11px; text-align: center; padding: 0; border-top:1px solid #eee; border-bottom:none; } +.calendar td.selected a { background: #C9DBED; } +.calendar td.nonday { background:#efefef; } +.calendar td.today a { background:#ffc; } +.calendar td a, .timelist a { display: block; font-weight:bold; padding:4px; text-decoration: none; color:#444; } +.calendar td a:hover, .timelist a:hover { background: #5b80b2; color:white; } +.calendar td a:active, .timelist a:active { background: #036; color:white; } +.calendarnav { font-size:10px; text-align: center; color:#ccc; margin:0; padding:1px 3px; } +.calendarnav a:link, #calendarnav a:visited, #calendarnav a:hover { color: #999; } +.calendar-shortcuts { background:white; font-size:10px; line-height:11px; border-top:1px solid #eee; padding:3px 0 4px; color:#ccc; } +.calendarbox .calendarnav-previous, .calendarbox .calendarnav-next { display:block; position:absolute; font-weight:bold; font-size:12px; background:#C9DBED url(../img/admin/default-bg.gif) bottom left repeat-x; padding:1px 4px 2px 4px; color:white; } +.calendarnav-previous:hover, .calendarnav-next:hover { background:#036; } +.calendarnav-previous { top:0; left:0; } +.calendarnav-next { top:0; right:0; } +.calendar-cancel { margin:0 !important; padding:0; font-size:10px; background:#e1e1e1 url(../img/admin/nav-bg.gif) 0 50% repeat-x; border-top:1px solid #ddd; } +.calendar-cancel a { padding:2px; color:#999; } +ul.timelist, .timelist li { list-style-type:none; margin:0; padding:0; } +.timelist a { padding:2px; } + diff --git a/packages/templatetags/package_extras.py b/packages/templatetags/package_extras.py index 5a92565c..56445832 100644 --- a/packages/templatetags/package_extras.py +++ b/packages/templatetags/package_extras.py @@ -30,6 +30,10 @@ def do_buildsortqs(parser, token): def space2br(value): return value.replace(' ', '<br />') +@register.inclusion_tag('forms/td_input.html') +def td_input(form_element): + return {'form_element': form_element} + @register.inclusion_tag('errors.html') def print_errors(errors): errs = [] diff --git a/packages/views.py b/packages/views.py index 09d76b3a..4a3db85e 100644 --- a/packages/views.py +++ b/packages/views.py @@ -1,6 +1,15 @@ +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 datetime import datetime from archweb_dev.main.utils import render_response from archweb_dev.main.models import Package, PackageFile @@ -44,8 +53,61 @@ def details(request, pkgid=0, name='', repo='', arch=''): return render_response(request, 'packages/details.html', {'pkg': pkg}) -# @TODO: replace search form with a newform -def search(request, query=''): +class EmptySelectWidget(forms.widgets.Select): + '''Like any select box but allows you to use a custom string for the + 'empty' field.''' + def __init__(self, empty_string="All", attrs=None, choices=()): + self.empty_string = empty_string + super(EmptySelectWidget, self).__init__(attrs, choices) + + def render(self, name, value, attrs=None, choices=()): + if value is None: value = '' + final_attrs = self.build_attrs(attrs, name=name) + output = [u'<select%s>' % flatatt(final_attrs)] + # Normalize to string. + str_value = force_unicode(value) + for option_value, option_label in chain(self.choices, choices): + if option_value == '': + option_label = self.empty_string + option_value = force_unicode(option_value) + selected_html = ( + option_value == str_value) and u' selected="selected"' or '' + output.append(u'<option value="%s"%s>%s</option>' % ( + escape(option_value), selected_html, + conditional_escape(force_unicode(option_label)))) + output.append(u'</select>') + return mark_safe(u'\n'.join(output)) + +class PackageSearchForm(forms.Form): + repo = forms.ModelChoiceField(Repo.objects.all(), + widget=EmptySelectWidget, required=False) + arch = forms.ModelChoiceField(Arch.objects.all(), + widget=EmptySelectWidget, required=False) + keywords = forms.CharField(required=False) + maintainer = forms.ModelChoiceField(User.objects.all(), + widget=EmptySelectWidget, required=False) + last_update = forms.DateField(required=False, widget=AdminDateWidget()) + limit = forms.ChoiceField(choices=[ + ('50', '50'), + ('100', '100'), + ('250', '250'), + ('All', 'All')], required=False) + +def search(request): + if request.GET: + form = PackageSearchForm(data=request.GET) + if form.is_valid(): + pass + else: + form = PackageSearchForm() + + page_dict = {'search_form': form} + return render_to_response('packages/search.html', + RequestContext(request, page_dict)) + + + + # OLD IMPLEMENTATION BELOW HERE if request.GET.has_key('q'): # take the q GET var over the one passed on the URL query = request.GET['q'].strip() diff --git a/templates/forms/td_input.html b/templates/forms/td_input.html new file mode 100644 index 00000000..38ff5a13 --- /dev/null +++ b/templates/forms/td_input.html @@ -0,0 +1,5 @@ +<td> + {{form_element.errors}} + {{form_element}} + {{form_element.help_text}} +</td> diff --git a/templates/packages/search.html b/templates/packages/search.html index f671c3ae..a181801b 100644 --- a/templates/packages/search.html +++ b/templates/packages/search.html @@ -1,76 +1,35 @@ -{% load package_extras %} {% extends "base.html" %} +{% load package_extras %} {% block title %}Arch Linux - Package Search{% endblock %} {% block head %} -<script type="text/JavaScript" src="/media/calendar.js"></script> -<link href="/media/calendar.css" rel="stylesheet" type="text/css" /> +<script type="text/javascript" src="/admin/jsi18n/"></script> +<script type="text/javascript" src="/media/admin_media/js/core.js"></script> +{{search_form.media}} {% endblock %} {% block content %} <div class="greybox"> <h4 style="text-align: right">Search Criteria</h4> - {% if errors %} - {% print_errors errors %} - {% endif %} - <hr /> - <form method="get" action="/packages/search/"> - <table width="100%"> - <tr> - <td><span class="smalltext">Arch</span></td> - <td><span class="smalltext">Repository</span></td> - <td><span class="smalltext">Keywords</span></td> - <td><span class="smalltext">Maintainer</span></td> - <td><span class="smalltext">Last Update</span></td> - <td><span class="smalltext">Per Page</span></td> - </tr><tr> - <td> - <select name="arch"> - <option value="all">All</option> - {% for a in arches %} - <option value="{{ a.name }}"{% ifequal arch a.name %} selected{% endifequal %}>{{ a.name }}</option> - {% endfor %} - </select> - </td><td> - <select name="repo"> - <option value="all">All</option> - {% for r in repos %} - <option value="{{ r.name }}"{% ifequal repo r.name %} selected{% endifequal %}>{{ r.name|capfirst }}</option> - {% endfor %} - </select> - </td><td> - <input type="text" name="q" value="{{ query|escape }}" size="30" maxlength="200" /> - </td><td> - <select name="maint"> - <option value="all">All</option> - {% for u in users %} - <option value="{{u.id}}" {% ifequal maint u.id - %}selected=selected {% - %endifequal%}>{{u.username}}</option> - {% endfor %} - </td><td> - <input type="text" name="lastupdate" value="{{ lastupdate|escape }}" size="10" maxlength="10" id="f_lastupdate" /> <button type="reset" id="f_trigger">...</button> - <script type="text/javascript"> - Calendar.setup({ - inputField : "f_lastupdate", // id of the input field - ifFormat : "%Y-%m-%d", // format of the input field - showsTime : false, // will display a time selector - button : "f_trigger", // trigger for the calendar (button ID) - singleClick : true, // double-click mode - step : 1 // show all years in drop-down boxes (instead of every other year as default) - }); - </script> - </td><td> - <select name="limit"> - <option value="50"{% ifequal limit 50 %} selected{% endifequal %}>50</option> - <option value="100"{% ifequal limit 100 %} selected{% endifequal %}>100</option> - <option value="250"{% ifequal limit 250 %} selected{% endifequal %}>250</option> - <option value="0"{% ifequal limit 0 %} selected{% endifequal %}>All</option> - </select> - </td><td> - <input type="submit" value=" Search " /> - </td> - </tr> - </table> + <form method="get"> + <table width="100%"> + <tr> + <td><span class="smalltext">Arch</span></td> + <td><span class="smalltext">Repository</span></td> + <td><span class="smalltext">Keywords</span></td> + <td><span class="smalltext">Maintainer</span></td> + <td><span class="smalltext">Last Update</span></td> + <td><span class="smalltext">Per Page</span></td> + </tr> + <tr> + {% td_input search_form.arch %} + {% td_input search_form.repo %} + {% td_input search_form.keywords %} + {% td_input search_form.maintainer%} + {% td_input search_form.last_update %} + {% td_input search_form.limit %} + <td><input type="submit" value="Search" /> + </tr> + </table> </form> </div> <br /><br /> diff --git a/templates/packages/signoffs.html b/templates/packages/signoffs.html index 55d534d7..7db29271 100644 --- a/templates/packages/signoffs.html +++ b/templates/packages/signoffs.html @@ -1,5 +1,5 @@ -{% load package_extras %} {% extends "base.html" %} +{% load package_extras %} {% block title %}Arch Linux - Package Signoffs{% endblock %} {% block head %} <script type="text/JavaScript" src="/media/calendar.js"></script> @@ -16,7 +16,6 @@ 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/([A-z0-9]+)/$', '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'), |