allura
修訂 | aede6f33cf54dc8aef2233f0992675c88bfab694 (tree) |
---|---|
時間 | 2012-04-18 05:14:17 |
作者 | bolkimen <bolkimen@yaho...> |
Commiter | Dave Brondsema |
ticket:17 add admin list
@@ -45,6 +45,7 @@ class W: | ||
45 | 45 | screenshot_list = ProjectScreenshots() |
46 | 46 | metadata_admin = aw.MetadataAdmin() |
47 | 47 | audit = aw.AuditLog() |
48 | + page_list=ffw.PageList() | |
48 | 49 | |
49 | 50 | class AdminWidgets(WidgetController): |
50 | 51 | widgets=['users', 'tool_status'] |
@@ -163,6 +164,7 @@ class ProjectAdminController(BaseController): | ||
163 | 164 | self.permissions = PermissionsController() |
164 | 165 | self.groups = GroupsController() |
165 | 166 | self.audit = AuditController() |
167 | + self.stats = StatsController() | |
166 | 168 | |
167 | 169 | @with_trailing_slash |
168 | 170 | @expose('jinja:allura.ext.admin:templates/project_admin.html') |
@@ -215,47 +217,6 @@ class ProjectAdminController(BaseController): | ||
215 | 217 | roles=M.ProjectRole.query.find(dict(project_id=c.project.root_project._id)).sort('_id').all(), |
216 | 218 | categories=M.ProjectCategory.query.find(dict(parent_id=None)).sort('label').all()) |
217 | 219 | |
218 | - @without_trailing_slash | |
219 | - @expose('jinja:allura.ext.admin:templates/project_stats.html') | |
220 | - def stats(self, **kw): | |
221 | - if c.project.shortname != '--init--': | |
222 | - redirect('index') | |
223 | - | |
224 | - # public private deleted | |
225 | - delete_count = M.Project.query.find(dict(neighborhood_id=c.project.neighborhood._id, deleted=True)).count() | |
226 | - public_count = 0 | |
227 | - private_count = 0 | |
228 | - last_updated_30 = 0 | |
229 | - last_updated_60 = 0 | |
230 | - last_updated_90 = 0 | |
231 | - today_date = datetime.today() | |
232 | - for p in M.Project.query.find(dict(neighborhood_id=c.project.neighborhood._id, deleted=False)).all(): | |
233 | - if p.private: | |
234 | - private_count = private_count + 1 | |
235 | - else: | |
236 | - public_count = public_count + 1 | |
237 | - if today_date - p.last_updated < timedelta(days=30): | |
238 | - last_updated_30 = last_updated_30 + 1 | |
239 | - if today_date - p.last_updated < timedelta(days=60): | |
240 | - last_updated_60 = last_updated_60 + 1 | |
241 | - if today_date - p.last_updated < timedelta(days=90): | |
242 | - last_updated_90 = last_updated_90 + 1 | |
243 | - | |
244 | - c.delete_count = delete_count | |
245 | - c.public_count = public_count | |
246 | - c.private_count = private_count | |
247 | - c.last_updated_30 = last_updated_30 | |
248 | - c.last_updated_60 = last_updated_60 | |
249 | - c.last_updated_90 = last_updated_90 | |
250 | - | |
251 | - c.markdown_editor = W.markdown_editor | |
252 | - c.label_edit = W.label_edit | |
253 | - c.mount_delete = W.mount_delete | |
254 | - c.admin_modal = W.admin_modal | |
255 | - c.install_modal = W.install_modal | |
256 | - mounts = c.project.ordered_mounts() | |
257 | - return dict() | |
258 | - | |
259 | 220 | @expose() |
260 | 221 | @require_post() |
261 | 222 | def update_labels(self, labels=None, labels_old=None, **kw): |
@@ -772,6 +733,80 @@ class AuditController(BaseController): | ||
772 | 733 | page=page, |
773 | 734 | count=count) |
774 | 735 | |
736 | +class StatsController(BaseController): | |
737 | + | |
738 | + def _check_security(self): | |
739 | + require_access(c.project, 'admin') | |
740 | + | |
741 | + @without_trailing_slash | |
742 | + @expose('jinja:allura.ext.admin:templates/project_stats.html') | |
743 | + def index(self, **kw): | |
744 | + if c.project.shortname != '--init--': | |
745 | + redirect('index') | |
746 | + | |
747 | + # public private deleted | |
748 | + delete_count = M.Project.query.find(dict(neighborhood_id=c.project.neighborhood._id, deleted=True)).count() | |
749 | + public_count = 0 | |
750 | + private_count = 0 | |
751 | + last_updated_30 = 0 | |
752 | + last_updated_60 = 0 | |
753 | + last_updated_90 = 0 | |
754 | + today_date = datetime.today() | |
755 | + for p in M.Project.query.find(dict(neighborhood_id=c.project.neighborhood._id, deleted=False)).all(): | |
756 | + if p.private: | |
757 | + private_count = private_count + 1 | |
758 | + else: | |
759 | + public_count = public_count + 1 | |
760 | + if today_date - p.last_updated < timedelta(days=30): | |
761 | + last_updated_30 = last_updated_30 + 1 | |
762 | + if today_date - p.last_updated < timedelta(days=60): | |
763 | + last_updated_60 = last_updated_60 + 1 | |
764 | + if today_date - p.last_updated < timedelta(days=90): | |
765 | + last_updated_90 = last_updated_90 + 1 | |
766 | + | |
767 | + c.delete_count = delete_count | |
768 | + c.public_count = public_count | |
769 | + c.private_count = private_count | |
770 | + c.last_updated_30 = last_updated_30 | |
771 | + c.last_updated_60 = last_updated_60 | |
772 | + c.last_updated_90 = last_updated_90 | |
773 | + | |
774 | + c.markdown_editor = W.markdown_editor | |
775 | + c.label_edit = W.label_edit | |
776 | + c.mount_delete = W.mount_delete | |
777 | + c.admin_modal = W.admin_modal | |
778 | + c.install_modal = W.install_modal | |
779 | + mounts = c.project.ordered_mounts() | |
780 | + return dict() | |
781 | + | |
782 | + @without_trailing_slash | |
783 | + @expose('jinja:allura.ext.admin:templates/project_stats_adminlist.html') | |
784 | + def adminlist(self, sort='alpha', limit=25, page=0, **kw): | |
785 | + limit, page, start = g.handle_paging(limit, page) | |
786 | + | |
787 | + pq = M.Project.query.find(dict(neighborhood_id=c.project.neighborhood._id, deleted=False)) | |
788 | + if sort=='alpha': | |
789 | + pq.sort('name') | |
790 | + else: | |
791 | + pq.sort('last_updated', pymongo.DESCENDING) | |
792 | + count = pq.count() | |
793 | + projects = pq.skip(start).limit(int(limit)).all() | |
794 | + | |
795 | + role_admin = M.ProjectRole.by_name('Admin')._id | |
796 | + | |
797 | + entries = [] | |
798 | + for proj in projects: | |
799 | + admin_role = M.ProjectRole.query.get(project_id=c.project._id,name='Admin') | |
800 | + for user_role in admin_role.users_with_role(): | |
801 | + log.info("User role: %s" % user_role.user) | |
802 | + entries.append({'project': proj, 'user': user_role.user}) | |
803 | + | |
804 | + return dict(entries=entries, | |
805 | + sort=sort, | |
806 | + limit=limit, page=page, count=count, | |
807 | + page_list=W.page_list) | |
808 | + | |
809 | + | |
775 | 810 | class AdminAppAdminController(DefaultAdminController): |
776 | 811 | '''Administer the admin app''' |
777 | 812 | pass |
@@ -30,9 +30,13 @@ | ||
30 | 30 | <span class="grid-prefix-1 grid-9 installable_tool"> |
31 | 31 | Private: {{ c.private_count }} |
32 | 32 | </span> |
33 | - <span class=" grid-9 installable_tool"> | |
33 | + <span class="grid-9 installable_tool"> | |
34 | 34 | Last 90 days: {{ c.last_updated_90 }} |
35 | 35 | </span> |
36 | + <br style="clear:both"/> | |
37 | + <span class="grid-prefix-1 grid-9 installable_tool"> | |
38 | + <a href="{{ c.project.url() }}admin/stats/adminlist">Admins list</a> | |
39 | + </span> | |
36 | 40 | </div> |
37 | 41 | |
38 | 42 | {% endblock %} |
@@ -0,0 +1,39 @@ | ||
1 | +{% extends g.theme.master %} | |
2 | + | |
3 | +{% do g.register_forge_css('css/forge/deck.css') %} | |
4 | + | |
5 | +{% block title %}{{c.project.name}} / Statistics / Admins list{% endblock %} | |
6 | + | |
7 | +{% block header %}Admins list{% endblock %} | |
8 | + | |
9 | +{% block content %} | |
10 | +<div class="nested-grid-container"> | |
11 | + <div style="overflow:auto"> | |
12 | + <table> | |
13 | + <thead> | |
14 | + <tr> | |
15 | + <th>Project</th> | |
16 | + <th>Username</th> | |
17 | + <th>E-mail</th> | |
18 | + <th>Name</th> | |
19 | + </tr> | |
20 | + </thead> | |
21 | + <tbody> | |
22 | + {% for entry in entries %} | |
23 | + <tr> | |
24 | + <td style="white-space: nowrap">{{ entry.project.name }}</td> | |
25 | + <td>{{ entry.user.username }}</td> | |
26 | + <td>{{ entry.user.preferences.email_address or 'Unknown' }}</td> | |
27 | + <td>{{ entry.user.display_name }}</td> | |
28 | + </tr> | |
29 | + {% endfor %} | |
30 | + </tbody> | |
31 | + </table> | |
32 | + </div> | |
33 | +</div> | |
34 | + | |
35 | +<div class="grid-15" style="clear:both"> | |
36 | + {{page_list.display(limit=limit, page=page, count=count)}} | |
37 | +</div> | |
38 | + | |
39 | +{% endblock %} |