• R/O
  • HTTP
  • SSH
  • HTTPS

提交

標籤
無標籤

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

allura


Commit MetaInfo

修訂3281984437c586ed54a854caec2396d901817886 (tree)
時間2012-07-18 23:28:54
作者Igor Bondarenko <jetmind2@gmai...>
CommiterDave Brondsema

Log Message

[#4349] ticket:110 Add /nf/admin/new_projects page.

Change Summary

差異

--- a/Allura/allura/controllers/site_admin.py
+++ b/Allura/allura/controllers/site_admin.py
@@ -2,14 +2,16 @@ import logging
22 from datetime import datetime, timedelta
33 from collections import defaultdict
44
5-from tg import expose, flash, config, request
5+from tg import expose, validate, flash, config, request
66 from tg.decorators import with_trailing_slash, without_trailing_slash
77 from ming.orm import session
88 import pymongo
9-from pylons import c
9+from pylons import c, g
10+from formencode import validators
1011
1112 from allura.lib import helpers as h
1213 from allura.lib.security import require_access
14+from allura.lib.widgets import form_fields as ffw
1315 from allura import model as M
1416 from allura.command.show_models import dfs, build_model_inheritance_graph
1517
@@ -18,6 +20,9 @@ from urlparse import urlparse
1820
1921 log = logging.getLogger(__name__)
2022
23+class W:
24+ page_list = ffw.PageList()
25+ page_size = ffw.PageSize()
2126
2227 class SiteAdminController(object):
2328
@@ -164,3 +169,22 @@ class SiteAdminController(object):
164169 flash('Artifact not found', 'error')
165170
166171 return data
172+
173+ @expose('jinja:allura:templates/site_admin_new_projects.html')
174+ @validate(dict(page=validators.Int(if_empty=0),
175+ limit=validators.Int(if_empty=100)))
176+ def new_projects(self, page=0, limit=100, **kwargs):
177+ c.page_list = W.page_list
178+ c.page_size = W.page_size
179+ limit, pagenum, start = g.handle_paging(limit, page, default=100)
180+ count = 0
181+ projects = (M.Project.query.find({'name': {'$regex': '^[^u][^/]'}})
182+ .sort('_id', -1))
183+ count = projects.count()
184+ projects = projects.skip(start).limit(limit)
185+ return {
186+ 'projects': projects,
187+ 'limit': limit,
188+ 'pagenum': pagenum,
189+ 'count': count
190+ }
--- a/Allura/allura/model/project.py
+++ b/Allura/allura/model/project.py
@@ -597,6 +597,13 @@ class Project(MappedClass, ActivityNode, ActivityObject):
597597 g.credentials.project_roles(project_id=self.root_project._id).named)
598598 return [ r.user for r in named_roles.roles_that_reach if r.user_id is not None ]
599599
600+ def admins(self):
601+ """Find all the users who have 'Admin' role for this project"""
602+ admin_role = ProjectRole.query.get(name='Admin', project_id=self._id)
603+ if not admin_role:
604+ return []
605+ return [r.user.username for r in admin_role.users_with_role(self)]
606+
600607 def user_in_project(self, username):
601608 from .auth import User
602609 u = User.by_username(username)
--- a/Allura/allura/nf/allura/css/site_style.css
+++ b/Allura/allura/nf/allura/css/site_style.css
@@ -2746,7 +2746,13 @@ div.codehilite pre div.code_block {
27462746 padding-left:10px;
27472747 width: 97%;
27482748 }
2749-
27502749 input.nofloat {
27512750 float: none;
27522751 }
2752+table thead tr th.tiny.narrow, table tr td.narrow {
2753+ padding-left: 2px;
2754+ padding-right: 2px;
2755+}
2756+#selected-projects {
2757+ padding: 10px 10px;
2758+}
--- /dev/null
+++ b/Allura/allura/public/nf/js/site_admin_new_projects.js
@@ -0,0 +1,15 @@
1+$(document).ready(function() {
2+ $('.js-select-project').change(function() {
3+ var shortname = $(this).attr('data-shortname');
4+ if ($(this).is(':checked')) {
5+ $('#selected-projects').append(' ' + shortname);
6+ } else {
7+ var shortnames = $('#selected-projects').text().split(' ');
8+ for (var i = 0; i < shortnames.length; i++) {
9+ if (shortnames[i] == shortname) break;
10+ }
11+ shortnames.splice(i, 1);
12+ $('#selected-projects').text(shortnames.join(' '));
13+ }
14+ });
15+});
--- a/Allura/allura/templates/site_admin.html
+++ b/Allura/allura/templates/site_admin.html
@@ -1,4 +1,7 @@
11 {% set hide_left_bar=False %}
2+{% if page == 'new_projects' %}
3+ {% set hide_left_bar=True %}
4+{% endif %}
25 {% extends g.theme.master %}
36
47 {% block title %}Forge Site Admin{% endblock %}
@@ -16,6 +19,7 @@
1619 <li class="{{page=='stats' and 'active' or ''}}"><a href="stats"><b data-icon="{{g.icons['stats'].char}}" class="ico {{g.icons['stats'].css}}"></b>Stats</a></li>
1720 <li class="{{page=='api_tickets' and 'active' or ''}}"><a href="api_tickets"><b data-icon="{{g.icons['admin'].char}}" class="ico {{g.icons['admin'].css}}"></b>API Tickets</a></li>
1821 <li class="{{page=='add_subscribers' and 'active' or ''}}"><a href="add_subscribers"><b data-icon="{{g.icons['admin'].char}}" class="ico {{g.icons['admin'].css}}"></b>Add Subscribers</a></li>
22+ <li class="{{page=='new_projects' and 'active' or ''}}"><a href="new_projects"><b data-icon="{{g.icons['admin'].char}}" class="ico {{g.icons['admin'].css}}"></b>New Projects</a></li>
1923 </ul>
2024 </div>
2125 {% endblock %}
--- /dev/null
+++ b/Allura/allura/templates/site_admin_new_projects.html
@@ -0,0 +1,44 @@
1+{% set page="new_projects" %}
2+{% extends 'allura:templates/site_admin.html' %}
3+
4+{% block content %}
5+ {{ c.page_size.display(limit=limit, count=count, page=pagenum) }}
6+ <table>
7+ <thead>
8+ <tr>
9+ <th class="narrow"></th>
10+ <th class="narrow">Created</th>
11+ <th>Shortname</th>
12+ <th>Name</th>
13+ <th>Short description</th>
14+ <th>Summary</th>
15+ <th>Deleted?</th>
16+ <th>Homepage</th>
17+ <th>Admins</th>
18+ </tr>
19+ </thead>
20+ {% for p in projects %}
21+ <tr>
22+ <td class="narrow">
23+ <input type="checkbox" class="js-select-project" data-shortname="{{ p.shortname }}" />
24+ </td>
25+ <td class="narrow">
26+ <small>{{ p._id.generation_time.strftime('%Y-%m-%d %H:%M:%S') }}</small>
27+ </td>
28+ <td><small>{{ p.shortname }}</small></td>
29+ <td><small>{{ p.name }}</small></td>
30+ <td><small>{{ p.short_description }}</small></td>
31+ <td><small>{{ p.summary }}</small></td>
32+ <td><small>{{ 'Yes' if p.deleted else 'No' }}</small></td>
33+ <td><small>{{ p.external_homepage|urlize(22) }}</small></td>
34+ <td><small>{{ p.admins()|join(' ') }}</small></td>
35+ </tr>
36+ {% endfor %}
37+ </table>
38+ {{ c.page_list.display(limit=limit, count=count, page=pagenum) }}
39+ <div id="selected-projects"></div>
40+{% endblock %}
41+
42+{% block extra_js %}
43+ <script type="text/javascript" src="{{g.forge_static('js/site_admin_new_projects.js')}}"></script>
44+{% endblock %}
--- a/Allura/allura/tests/functional/test_site_admin.py
+++ b/Allura/allura/tests/functional/test_site_admin.py
@@ -40,3 +40,10 @@ class TestSiteAdmin(TestController):
4040 def test_tickets_access(self):
4141 r = self.app.get('/nf/admin/api_tickets', extra_environ=dict(
4242 username='test-user'), status=403)
43+
44+ def test_new_projects_access(self):
45+ self.app.get('/nf/admin/new_projects', extra_environ=dict(
46+ username='test_user'), status=403)
47+ r = self.app.get('/nf/admin/new_projects', extra_environ=dict(
48+ username='*anonymous'), status=302).follow()
49+ assert 'Login' in r