mango r267 - in branches/django: . mango www
- From: ovitters svn gnome org
- To: svn-commits-list gnome org,gnome-sysadmin gnome org
- Subject: mango r267 - in branches/django: . mango www
- Date: Fri, 27 Jun 2008 21:20:47 +0000 (UTC)
Author: ovitters
Date: Fri Jun 27 21:20:47 2008
New Revision: 267
URL: http://svn.gnome.org/viewvc/mango?rev=267&view=rev
Log:
* mango/views.py (setup_filter, list_mirrors, list_foundationmembers,
list_modules): Introduce a setup_filter function and use it
whenever possible.
* www/list_foundationmembers.xsl:
Modified:
branches/django/ (props changed)
branches/django/ChangeLog
branches/django/mango/views.py
branches/django/www/list_foundationmembers.xsl
Modified: branches/django/mango/views.py
==============================================================================
--- branches/django/mango/views.py (original)
+++ branches/django/mango/views.py Fri Jun 27 21:20:47 2008
@@ -76,6 +76,34 @@
return page
+def setup_filter(pagenode, values, filters):
+ filter = None
+ filternode = None
+
+ for key, val in filters.items():
+ filter_value = values.get('filter_%s' % key, '')
+ if not filter_value:
+ continue
+
+ if not callable(val):
+ if filter_value not in val:
+ continue
+
+ val = val[filter_value]
+
+ q = val(filter_value)
+
+ if filter:
+ filter = filter & q
+ else:
+ filter = q
+
+ if not filternode:
+ filternode = ET.SubElement(pagenode, 'filter')
+ ET.SubElement(filternode, key).text = filter_value
+
+ return filter
+
def add_form_errors_to_xml(root, form):
"""Adds form errors to the XML node specified by root"""
@@ -178,12 +206,12 @@
def list_mirrors(request):
doc, pagenode = get_xmldoc('List Mirrors', request, 'listftpmirrors')
- filter = request.GET.get('filter_keyword', None)
- if filter:
- queryset = models.Ftpmirrors.objects.filter(Q(name__contains=filter) | Q(url__contains=filter))
+ filter = setup_filter(pagenode, request.GET, {
+ 'keyword': lambda keyword: Q(name__contains=keyword) | Q(url__contains=keyword)
+ })
- filternode = ET.SubElement(pagenode, 'filter')
- ET.SubElement(filternode, 'keyword').text = filter
+ if filter:
+ queryset = models.Ftpmirrors.objects.filter(filter)
else:
queryset = models.Ftpmirrors.objects.all()
@@ -243,30 +271,13 @@
def list_foundationmembers(request):
doc, pagenode = get_xmldoc('List Foundation Members', request, 'listfoundationmembers')
- filter, filternode = None, None
-
- filter_keyword = request.GET.get('filter_keyword', '')
- if filter_keyword:
- filter = Q(lastname__icontains=filter_keyword) | Q(firstname__icontains=filter_keyword) | Q(email__icontains=filter_keyword)
-
- filternode = ET.SubElement(pagenode, 'filter')
- ET.SubElement(filternode, 'keyword').text = filter_keyword
-
- filter_status = request.GET.get('filter_status', '')
- if filter_status:
- if filter_status == 'current':
- q = Q(last_renewed_on__gte=datetime.date.today() - datetime.timedelta(days=700))
- else:
- q = Q(last_renewed_on__lte=datetime.date.today() - datetime.timedelta(days=700))
-
- if filter:
- filter = filter & q
- else:
- filter = q
-
- if not filternode:
- filternode = ET.SubElement(pagenode, 'filter')
- ET.SubElement(filternode, 'status').text = filter_status
+ filter = setup_filter(pagenode, request.GET, {
+ 'keyword': lambda keyword: Q(lastname__icontains=keyword) | Q(firstname__icontains=keyword) | Q(email__icontains=keyword),
+ 'status': {
+ 'current': lambda keyword: Q(last_renewed_on__gte=datetime.date.today() - datetime.timedelta(days=700)) ,
+ 'needrenewal': lambda keyword: Q(last_renewed_on__lte=datetime.date.today() - datetime.timedelta(days=700))
+ }
+ })
if filter:
queryset = models.Foundationmembers.objects.filter(filter)
@@ -297,12 +308,9 @@
def list_modules(request):
doc, pagenode = get_xmldoc('List Modules', request, 'listmodules')
- filter = request.GET.get('filter_keyword', None)
- if filter:
- filternode = ET.SubElement(pagenode, 'filter')
- ET.SubElement(filternode, 'keyword').text = filter
-
- filter = Q(cn=filter) | Q(maintainerUid=filter)
+ filter = setup_filter(pagenode, request.GET, {
+ 'keyword': lambda keyword: Q(cn=keyword) | Q(maintainerUid=keyword)
+ })
queryset = models.Modules.search(filter)
Modified: branches/django/www/list_foundationmembers.xsl
==============================================================================
--- branches/django/www/list_foundationmembers.xsl (original)
+++ branches/django/www/list_foundationmembers.xsl Fri Jun 27 21:20:47 2008
@@ -25,13 +25,13 @@
<form method="GET" action="{$script}" name="filterform">
Search: <input type="text" name="filter_keyword" value="{filter/keyword}" onchange="this.form.submit()"/>
<select name="filter_status" onchange="this.form.submit()">
- <option value=""><xsl:if test="filter/status = ''"><xsl:attribute name="checked">checked</xsl:attribute></xsl:if>
+ <option value=""><xsl:if test="filter/status = ''"><xsl:attribute name="selected">selected</xsl:attribute></xsl:if>
All members
</option>
- <option value="current"><xsl:if test="filter/status = 'current'"><xsl:attribute name="checked">checked</xsl:attribute></xsl:if>
+ <option value="current"><xsl:if test="filter/status = 'current'"><xsl:attribute name="selected">selected</xsl:attribute></xsl:if>
Current members
</option>
- <option value="needrenewal"><xsl:if test="filter/status = 'needrenewal'"><xsl:attribute name="checked">checked</xsl:attribute></xsl:if>
+ <option value="needrenewal"><xsl:if test="filter/status = 'needrenewal'"><xsl:attribute name="selected">selected</xsl:attribute></xsl:if>
Old members needing renewal
</option>
</select>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]