mango r222 - in branches/django: . mango



Author: ovitters
Date: Sun Jun 22 13:26:05 2008
New Revision: 222
URL: http://svn.gnome.org/viewvc/mango?rev=222&view=rev

Log:
	* mango/urls.py: Add list_mirrors view.
	* mango/views.py (list_mirrors): Fetch ftp mirrors from database,
	optionally filtering it by a keyword.


Modified:
   branches/django/   (props changed)
   branches/django/ChangeLog
   branches/django/mango/urls.py
   branches/django/mango/views.py

Modified: branches/django/mango/urls.py
==============================================================================
--- branches/django/mango/urls.py	(original)
+++ branches/django/mango/urls.py	Sun Jun 22 13:26:05 2008
@@ -1,6 +1,6 @@
 from django.conf.urls.defaults import *
 
-from mango.views import current_datetime, list_users, test_index, list_accounts, edit_user
+from mango.views import current_datetime, list_users, test_index, list_accounts, edit_user, list_mirrors
 import mango.settings
 
 urlpatterns = patterns('',
@@ -8,6 +8,7 @@
     (r'^%susers/$' % mango.settings.SITE_ROOT, list_users),
     (r'^%stest/$' % mango.settings.SITE_ROOT, test_index),
     (r'^%saccounts/$' % mango.settings.SITE_ROOT, list_accounts),
+    (r'^%smirrors/$' % mango.settings.SITE_ROOT, list_mirrors),
     (r'^%susers/edit/(?P<user>\w+)/$' % mango.settings.SITE_ROOT, edit_user),
     # Example:
     # (r'^mango/', include('mango.foo.urls')),

Modified: branches/django/mango/views.py
==============================================================================
--- branches/django/mango/views.py	(original)
+++ branches/django/mango/views.py	Sun Jun 22 13:26:05 2008
@@ -1,5 +1,6 @@
 from django.http import HttpResponse, Http404, HttpResponseServerError
 from django.conf import settings
+from django.db.models import Q
 import datetime
 
 import ldap
@@ -71,7 +72,6 @@
     doc, root = get_xmldoc('Update user %s' % user, request)
     el = ET.SubElement(root, 'updateuser')
 
-    
     l = models.LdapUtil().handle
     if not l:
         return HttpResponseServerError('Cannot connect to LDAP?')
@@ -127,3 +127,28 @@
     return get_xmlresponse(doc, "list_accounts.xsl")
 
 
+def list_mirrors(request):
+    doc, root = get_xmldoc('List Mirrors', request)
+    ftpnodes = ET.SubElement(root, 'listftpmirrors')
+
+    filter = request.GET.get('filter_keyword', None)
+    if filter:
+        mirrors = models.Ftpmirrors.objects.filter(Q(name__contains=filter) | Q(url__contains=filter))
+        filternode = ET.SubElement(ftpnodes, 'filter')
+        keynode = ET.SubElement(filternode, 'keyword')
+        keynode.text = filter
+    else:
+        mirrors = models.Ftpmirrors.objects.all()
+    for mirror in mirrors:
+        ftpnode = ET.SubElement(ftpnodes, 'ftpmirror')
+
+        fields = ('id', 'name', 'url', 'location', 'email', 'description', 'comments', 'last_update')
+        for field in fields:
+            node = ET.SubElement(ftpnode, field)
+            node.text = unicode(getattr(mirror, field))
+        if mirror.active:
+            node = ET.SubElement(ftpnode, 'active')
+
+    return get_xmlresponse(doc, "list_ftpmirrors.xsl")
+
+



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]