You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by je...@apache.org on 2014/09/09 16:28:30 UTC
[10/18] git commit: [#7656] ticket:648 Refactor controller & template
to reuse as much as we can
[#7656] ticket:648 Refactor controller & template to reuse as much as we can
Project: http://git-wip-us.apache.org/repos/asf/allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/allura/commit/3577c180
Tree: http://git-wip-us.apache.org/repos/asf/allura/tree/3577c180
Diff: http://git-wip-us.apache.org/repos/asf/allura/diff/3577c180
Branch: refs/heads/je/42cc_7656
Commit: 3577c180445516e50b8530039c8574f4783d25a9
Parents: 7a6ccbd
Author: Igor Bondarenko <je...@gmail.com>
Authored: Tue Sep 9 14:09:55 2014 +0300
Committer: Igor Bondarenko <je...@gmail.com>
Committed: Tue Sep 9 14:09:55 2014 +0300
----------------------------------------------------------------------
Allura/allura/controllers/site_admin.py | 74 ++++++++++++--------
Allura/allura/templates/site_admin_search.html | 49 +++++++++++++
.../templates/site_admin_search_projects.html | 74 --------------------
.../site_admin_search_projects_results.html | 27 +++++++
.../templates/site_admin_search_users.html | 25 -------
.../site_admin_search_users_results.html | 7 ++
6 files changed, 126 insertions(+), 130 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/allura/blob/3577c180/Allura/allura/controllers/site_admin.py
----------------------------------------------------------------------
diff --git a/Allura/allura/controllers/site_admin.py b/Allura/allura/controllers/site_admin.py
index 5913411..b19b84b 100644
--- a/Allura/allura/controllers/site_admin.py
+++ b/Allura/allura/controllers/site_admin.py
@@ -290,41 +290,35 @@ class SiteAdminController(object):
flash('Can not add comment "%s" for user %s' % (comment, user))
redirect(request.referer)
- @without_trailing_slash
- @expose('jinja:allura:templates/site_admin_search_projects.html')
- @validate(validators=dict(q=validators.UnicodeString(if_empty=None),
- 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):
- fields = [('shortname', 'shortname'), ('name', 'full name')]
- fields.extend(aslist(tg.config.get('search.project.additional_fields'), ','))
- c.search_form = W.admin_search_form(fields)
+ def _search(self, model, fields, add_fields, q=None, f=None, page=0, limit=None, **kw):
+ all_fields = fields + [(fld, fld) for fld in add_fields]
+ c.search_form = W.admin_search_form(all_fields)
c.page_list = W.page_list
c.page_size = W.page_size
count = 0
- projects = []
+ objects = []
limit, page, start = g.handle_paging(limit, page, default=25)
if q:
- match = search.search_projects(q, f, rows=limit, start=start)
+ match = search.site_admin_search(model, q, f, rows=limit, start=start)
if match:
count = match.hits
- projects = match.docs
- pids = [bson.ObjectId(p['id'].split('#')[1]) for p in projects]
- mongo_projects = {}
- for p in M.Project.query.find({'_id': {'$in': pids}}):
- mongo_projects[str(p._id)] = p
-
- for i in range(len(projects)):
- p = projects[i]
- _id = p['id'].split('#')[1]
- p['project'] = mongo_projects.get(_id)
- # Some projects can be deleted, but still have index in solr, should skip those
- projects = [p for p in projects if p.get('project')]
-
- def convert_fields(p):
+ objects = match.docs
+ ids = [bson.ObjectId(obj['id'].split('#')[1]) for obj in objects]
+ mongo_objects = {}
+ for obj in model.query.find({'_id': {'$in': ids}}):
+ mongo_objects[str(obj._id)] = obj
+
+ for i in range(len(objects)):
+ obj = objects[i]
+ _id = obj['id'].split('#')[1]
+ obj['object'] = mongo_objects.get(_id)
+ # Some objects can be deleted, but still have index in solr, should skip those
+ objects = [obj for obj in objects if obj.get('object')]
+
+ def convert_fields(obj):
# throw the type away (e.g. '_s' from 'url_s')
result = {}
- for k,v in p.iteritems():
+ for k,v in obj.iteritems():
name = k.rsplit('_', 1)
if len(name) == 2:
name = name[0]
@@ -336,21 +330,39 @@ class SiteAdminController(object):
return {
'q': q,
'f': f,
- 'projects': map(convert_fields, projects),
+ 'objects': map(convert_fields, objects),
'count': count,
'page': page,
'limit': limit,
- 'additional_fields': aslist(config.get('search.project.additional_fields'), ','),
- 'provider': ProjectRegistrationProvider.get(),
+ 'fields': fields,
+ 'additional_fields': add_fields,
+ 'type_s': model.type_s,
}
@without_trailing_slash
- @expose('jinja:allura:templates/site_admin_search_users.html')
+ @expose('jinja:allura:templates/site_admin_search.html')
+ @validate(validators=dict(q=validators.UnicodeString(if_empty=None),
+ 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):
+ fields = [('shortname', 'shortname'), ('name', 'full name')]
+ add_fields = aslist(tg.config.get('search.project.additional_fields'), ',')
+ r = self._search(M.Project, fields, add_fields, q, f, page, limit, **kw)
+ r['search_results_template'] = 'allura:templates/site_admin_search_projects_results.html'
+ r['provider'] = ProjectRegistrationProvider.get()
+ return r
+
+ @without_trailing_slash
+ @expose('jinja:allura:templates/site_admin_search.html')
@validate(validators=dict(q=validators.UnicodeString(if_empty=None),
limit=validators.Int(if_invalid=None),
page=validators.Int(if_empty=0, if_invalid=0)))
def search_users(self, q=None, f=None, page=0, limit=None, **kw):
- return {}
+ fields = []
+ add_fields = aslist(tg.config.get('search.user.additional_fields'), ',')
+ r = self._search(M.User, fields, add_fields, q, f, page, limit, **kw)
+ r['search_results_template'] = 'allura:templates/site_admin_search_users_results.html'
+ return r
class TaskManagerController(object):
http://git-wip-us.apache.org/repos/asf/allura/blob/3577c180/Allura/allura/templates/site_admin_search.html
----------------------------------------------------------------------
diff --git a/Allura/allura/templates/site_admin_search.html b/Allura/allura/templates/site_admin_search.html
new file mode 100644
index 0000000..685f65b
--- /dev/null
+++ b/Allura/allura/templates/site_admin_search.html
@@ -0,0 +1,49 @@
+{#-
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+-#}
+{% extends 'allura:templates/site_admin.html' %}
+
+{% block title %}Search {{ type_s }}s{% endblock %}
+{% block header %}Search {{ type_s }}s{% endblock %}
+
+{% block content %}
+ <div class="grid-19">
+ {{ c.search_form.display(q=q, f=f) }}
+ </div>
+
+ {% if objects %}
+ <table>
+ {% include search_results_template %}
+ </table>
+ {% endif %}
+
+ <div class="grid-19">
+ {{c.page_list.display(limit=limit, page=page, count=count)}}
+ {{c.page_size.display(limit=limit, page=page, count=count)}}
+ </div>
+{% endblock %}
+
+{% block extra_css %}
+<style>
+ table { clear: both; }
+ table th {
+ text-align: left;
+ padding: 5px 10px;
+ }
+</style>
+{% endblock %}
http://git-wip-us.apache.org/repos/asf/allura/blob/3577c180/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
deleted file mode 100644
index a6e6b02..0000000
--- a/Allura/allura/templates/site_admin_search_projects.html
+++ /dev/null
@@ -1,74 +0,0 @@
-{#-
- Licensed to the Apache Software Foundation (ASF) under one
- or more contributor license agreements. See the NOTICE file
- distributed with this work for additional information
- regarding copyright ownership. The ASF licenses this file
- to you under the Apache License, Version 2.0 (the
- "License"); you may not use this file except in compliance
- with the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing,
- software distributed under the License is distributed on an
- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- KIND, either express or implied. See the License for the
- specific language governing permissions and limitations
- under the License.
--#}
-{% extends 'allura:templates/site_admin.html' %}
-
-{% block title %}Search Projects{% endblock %}
-{% block header %}Search Projects{% endblock %}
-
-{% block content %}
- <div class="grid-19">
- {{ c.search_form.display(q=q, f=f) }}
- </div>
-
- {% if projects %}
- <table>
- <tr>
- <th>Short name</th>
- <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'] }}">{{ 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>
- {% for url, label in provider.details_links(p['project']) %}
- <a href="{{ url }}">{{ label }}</a><br>
- {% endfor %}
- </td>
- </tr>
- {% endfor %}
- </table>
- {% endif %}
-
- <div class="grid-19">
- {{c.page_list.display(limit=limit, page=page, count=count)}}
- {{c.page_size.display(limit=limit, page=page, count=count)}}
- </div>
-{% endblock %}
-
-{% block extra_css %}
-<style>
- table { clear: both; }
- table th {
- text-align: left;
- padding: 5px 10px;
- }
-</style>
-{% endblock %}
http://git-wip-us.apache.org/repos/asf/allura/blob/3577c180/Allura/allura/templates/site_admin_search_projects_results.html
----------------------------------------------------------------------
diff --git a/Allura/allura/templates/site_admin_search_projects_results.html b/Allura/allura/templates/site_admin_search_projects_results.html
new file mode 100644
index 0000000..622e9a6
--- /dev/null
+++ b/Allura/allura/templates/site_admin_search_projects_results.html
@@ -0,0 +1,27 @@
+<tr>
+ <th>Short name</th>
+ <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 objects %}
+<tr>
+ <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>
+ {% for url, label in provider.details_links(p['object']) %}
+ <a href="{{ url }}">{{ label }}</a><br>
+ {% endfor %}
+ </td>
+</tr>
+{% endfor %}
http://git-wip-us.apache.org/repos/asf/allura/blob/3577c180/Allura/allura/templates/site_admin_search_users.html
----------------------------------------------------------------------
diff --git a/Allura/allura/templates/site_admin_search_users.html b/Allura/allura/templates/site_admin_search_users.html
deleted file mode 100644
index ec18e90..0000000
--- a/Allura/allura/templates/site_admin_search_users.html
+++ /dev/null
@@ -1,25 +0,0 @@
-{#-
- Licensed to the Apache Software Foundation (ASF) under one
- or more contributor license agreements. See the NOTICE file
- distributed with this work for additional information
- regarding copyright ownership. The ASF licenses this file
- to you under the Apache License, Version 2.0 (the
- "License"); you may not use this file except in compliance
- with the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing,
- software distributed under the License is distributed on an
- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- KIND, either express or implied. See the License for the
- specific language governing permissions and limitations
- under the License.
--#}
-{% extends 'allura:templates/site_admin.html' %}
-
-{% block title %}Search Users{% endblock %}
-{% block header %}Search Users{% endblock %}
-
-{% block content %}
-{% endblock %}
http://git-wip-us.apache.org/repos/asf/allura/blob/3577c180/Allura/allura/templates/site_admin_search_users_results.html
----------------------------------------------------------------------
diff --git a/Allura/allura/templates/site_admin_search_users_results.html b/Allura/allura/templates/site_admin_search_users_results.html
new file mode 100644
index 0000000..b73c5c4
--- /dev/null
+++ b/Allura/allura/templates/site_admin_search_users_results.html
@@ -0,0 +1,7 @@
+<tr>
+</tr>
+
+{% for user in objects %}
+<tr>
+</tr>
+{% endfor %}