allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From brond...@apache.org
Subject [09/18] git commit: [#7278] ticket:612 Config option to include custom fields
Date Thu, 21 Aug 2014 19:47:21 GMT
[#7278] ticket:612 Config option to include custom fields


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

Branch: refs/heads/master
Commit: 9a8bf68352e40305745215874afbeb3901a495de
Parents: eb4ac9c
Author: Igor Bondarenko <jetmind2@gmail.com>
Authored: Fri Aug 1 16:32:37 2014 +0300
Committer: Dave Brondsema <dbrondsema@slashdotmedia.com>
Committed: Thu Aug 21 18:49:55 2014 +0000

----------------------------------------------------------------------
 Allura/allura/controllers/site_admin.py           | 17 ++++++++++++++++-
 Allura/allura/lib/widgets/forms.py                | 13 ++++++++-----
 .../templates/site_admin_search_projects.html     | 18 ++++++++++++------
 Allura/development.ini                            |  4 ++++
 4 files changed, 40 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/allura/blob/9a8bf683/Allura/allura/controllers/site_admin.py
----------------------------------------------------------------------
diff --git a/Allura/allura/controllers/site_admin.py b/Allura/allura/controllers/site_admin.py
index 5bbf1fd..ebd1ff5 100644
--- a/Allura/allura/controllers/site_admin.py
+++ b/Allura/allura/controllers/site_admin.py
@@ -23,6 +23,7 @@ from tg import expose, validate, flash, config, redirect
 from tg.decorators import with_trailing_slash, without_trailing_slash
 import bson
 import tg
+from paste.deploy.converters import aslist
 from pylons import app_globals as g
 from pylons import tmpl_context as c
 from pylons import request
@@ -305,13 +306,27 @@ class SiteAdminController(object):
             if match:
                 count = match.hits
                 projects = match.docs
+
+        def convert_fields(p):
+            # throw the type away (e.g. '_s' from 'url_s')
+            result = {}
+            for k,v in p.iteritems():
+                name = k.rsplit('_', 1)
+                if len(name) == 2:
+                    name = name[0]
+                else:
+                    name = k
+                result[name] = v
+            return result
+
         return {
             'q': q,
             'f': f,
-            'projects': projects,
+            'projects': map(convert_fields, projects),
             'count': count,
             'page': page,
             'limit': limit,
+            'additional_fields': aslist(config.get('search.project.additional_fields'), ','),
         }
 
 

http://git-wip-us.apache.org/repos/asf/allura/blob/9a8bf683/Allura/allura/lib/widgets/forms.py
----------------------------------------------------------------------
diff --git a/Allura/allura/lib/widgets/forms.py b/Allura/allura/lib/widgets/forms.py
index c560fb3..794f926 100644
--- a/Allura/allura/lib/widgets/forms.py
+++ b/Allura/allura/lib/widgets/forms.py
@@ -1090,16 +1090,19 @@ class SearchProjectsForm(ForgeForm):
 
     @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.append(ew.Option(py_value='__custom__', label='custom query'))
         return [
             ew.RowField(fields=[
                 ew.SingleSelectField(
                     name='f',
                     show_label=False,
-                    options=[
-                        ew.Option(py_value='shortname', label='shortname'),
-                        ew.Option(py_value='name', label='full name'),
-                        ew.Option(py_value='__custom__', label='custom query'),
-                    ]),
+                    options=search_fields),
                 ew.InputField(name='q', show_label=False, attrs={'style': 'width: 500px'}),
                 ew.SubmitButton(
                     show_label=False,

http://git-wip-us.apache.org/repos/asf/allura/blob/9a8bf683/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 b5debc5..41f37db 100644
--- a/Allura/allura/templates/site_admin_search_projects.html
+++ b/Allura/allura/templates/site_admin_search_projects.html
@@ -33,17 +33,23 @@
         <th>Full name</th>
         <th>Registered</th>
         <th>Deleted?</th>
+        {% for field in additional_fields %}
+        <th>{{ field }}</th>
+        {% endfor %}
         <th>Details</th>
       </tr>
     {% for p in projects %}
       <tr>
-        <td><a href="{{ p['url_s'] }}">{{ p['shortname_s'] }}</a></td>
-        <td>{{ p['name_s'] }}</td>
-        <td>{{ h.ago_string(p['registration_dt']) }}</td>
-        <td>{{ 'Yes' if p['deleted_b'] else 'No' }}</td>
+        <td><a href="{{ p['url'] }}">{{ p['shortname'] }}</a></td>
+        <td>{{ p['name'] }}</td>
+        <td>{{ h.ago_string(p['registration']) }}</td>
+        <td>{{ p['deleted'] }}</td>
+        {% for field in additional_fields %}
+        <td>{{ p[field] }}</td>
+        {% endfor %}
         <td>
-          <a href="{{ p['url_s'] + 'admin/groups/' }}">Members</a><br>
-          <a href="{{ p['url_s'] + 'admin/audit/' }}">Audit Trail</a>
+          <a href="{{ p['url'] + 'admin/groups/' }}">Members</a><br>
+          <a href="{{ p['url'] + 'admin/audit/' }}">Audit Trail</a>
         </td>
       </tr>
     {% endfor %}

http://git-wip-us.apache.org/repos/asf/allura/blob/9a8bf683/Allura/development.ini
----------------------------------------------------------------------
diff --git a/Allura/development.ini b/Allura/development.ini
index b7c52e0..80275d5 100644
--- a/Allura/development.ini
+++ b/Allura/development.ini
@@ -120,6 +120,10 @@ user_prefs_storage.method = local
 user_prefs_storage.ldap.fields.display_name = cn
 
 
+# Additional fields for admin project search (/nf/admin/search_projects/)
+# Note: whitespace after comma is important!
+# search.project.additional_fields = private, url, title
+
 # Set the locations of some static resources
 #  script_name is the path that is handled by the application
 #  url_base is the prefix that references to the static resources should have


Mime
View raw message