allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From brond...@apache.org
Subject [09/26] git commit: [#7656] ticket:648 Refactor projects search form to something more generic
Date Fri, 19 Sep 2014 20:04:23 GMT
[#7656] ticket:648 Refactor projects search form to something more generic


Project: http://git-wip-us.apache.org/repos/asf/allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/allura/commit/1371cc37
Tree: http://git-wip-us.apache.org/repos/asf/allura/tree/1371cc37
Diff: http://git-wip-us.apache.org/repos/asf/allura/diff/1371cc37

Branch: refs/heads/master
Commit: 1371cc37f49ba4412ee5eca27513516fd4dd9463
Parents: 638807a
Author: Igor Bondarenko <jetmind2@gmail.com>
Authored: Tue Sep 9 13:00:11 2014 +0300
Committer: Dave Brondsema <dbrondsema@slashdotmedia.com>
Committed: Fri Sep 19 19:35:39 2014 +0000

----------------------------------------------------------------------
 Allura/allura/controllers/site_admin.py              |  6 ++++--
 Allura/allura/lib/widgets/forms.py                   | 15 +++++++--------
 .../allura/templates/site_admin_search_projects.html |  2 +-
 3 files changed, 12 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/allura/blob/1371cc37/Allura/allura/controllers/site_admin.py
----------------------------------------------------------------------
diff --git a/Allura/allura/controllers/site_admin.py b/Allura/allura/controllers/site_admin.py
index bf7076e..5913411 100644
--- a/Allura/allura/controllers/site_admin.py
+++ b/Allura/allura/controllers/site_admin.py
@@ -54,7 +54,7 @@ class W:
     page_list = ffw.PageList()
     page_size = ffw.PageSize()
     audit = AuditLog()
-    search_projects_form = forms.SearchProjectsForm()
+    admin_search_form = forms.AdminSearchForm
 
 
 class SiteAdminController(object):
@@ -296,7 +296,9 @@ class SiteAdminController(object):
                               limit=validators.Int(if_invalid=None),
                               page=validators.Int(if_empty=0, if_invalid=0)))
     def search_projects(self, q=None, f=None, page=0, limit=None, **kw):
-        c.search_projects_form = W.search_projects_form
+        fields = [('shortname', 'shortname'), ('name', 'full name')]
+        fields.extend(aslist(tg.config.get('search.project.additional_fields'), ','))
+        c.search_form = W.admin_search_form(fields)
         c.page_list = W.page_list
         c.page_size = W.page_size
         count = 0

http://git-wip-us.apache.org/repos/asf/allura/blob/1371cc37/Allura/allura/lib/widgets/forms.py
----------------------------------------------------------------------
diff --git a/Allura/allura/lib/widgets/forms.py b/Allura/allura/lib/widgets/forms.py
index 794f926..0d25079 100644
--- a/Allura/allura/lib/widgets/forms.py
+++ b/Allura/allura/lib/widgets/forms.py
@@ -1081,21 +1081,20 @@ class AwardGrantForm(ForgeForm):
         ]
 
 
-class SearchProjectsForm(ForgeForm):
+class AdminSearchForm(ForgeForm):
     defaults = dict(
         ForgeForm.defaults,
         action='',
         method='get',
         submit_text=None)
 
+    def __init__(self, fields, *args, **kw):
+        super(AdminSearchForm, self).__init__(*args, **kw)
+        self._fields = fields
+
     @property
     def fields(self):
-        add_fields = aslist(tg.config.get('search.project.additional_fields'), ',')
-        search_fields = [
-            ew.Option(py_value='shortname', label='shortname'),
-            ew.Option(py_value='name', label='full name'),
-        ]
-        search_fields.extend([ew.Option(py_value=f, label=f) for f in add_fields])
+        search_fields = [ew.Option(py_value=v, label=l) for v, l in self._fields]
         search_fields.append(ew.Option(py_value='__custom__', label='custom query'))
         return [
             ew.RowField(fields=[
@@ -1114,7 +1113,7 @@ class SearchProjectsForm(ForgeForm):
             ])]
 
     def context_for(self, field):
-        ctx = super(SearchProjectsForm, self).context_for(field)
+        ctx = super(AdminSearchForm, self).context_for(field)
         if field.name is None and not ctx.get('value'):
             # RowField does not pass context down to the children :(
             render_ctx = ew_core.widget_context.render_context

http://git-wip-us.apache.org/repos/asf/allura/blob/1371cc37/Allura/allura/templates/site_admin_search_projects.html
----------------------------------------------------------------------
diff --git a/Allura/allura/templates/site_admin_search_projects.html b/Allura/allura/templates/site_admin_search_projects.html
index 73f30eb..a6e6b02 100644
--- a/Allura/allura/templates/site_admin_search_projects.html
+++ b/Allura/allura/templates/site_admin_search_projects.html
@@ -23,7 +23,7 @@
 
 {% block content %}
   <div class="grid-19">
-    {{ c.search_projects_form.display(q=q, f=f) }}
+    {{ c.search_form.display(q=q, f=f) }}
   </div>
 
   {% if projects %}


Mime
View raw message