Permalink
Browse files

Flesh out the admin UI a bit.

  • Loading branch information...
1 parent e02ed3f commit 8ed9486e53e62d417e49ae8bbabe122ec75270f3 @tseaver tseaver committed Nov 8, 2011
Showing with 82 additions and 10 deletions.
  1. +46 −1 cartouche/admin.py
  2. +24 −3 cartouche/configure.zcml
  3. +6 −6 cartouche/templates/admin.pt
  4. +6 −0 cartouche/templates/admin_registration.pt
View
@@ -1,6 +1,7 @@
import os
import sys
+from pyramid.exceptions import HTTPNotFound
from pyramid.renderers import get_renderer
from pyramid.paster import bootstrap
import transaction
@@ -9,22 +10,66 @@
from cartouche.persistence import ConfirmedRegistrations
from cartouche.persistence import PendingRegistrations
-def admin_view(context, request):
+def admin_overview(context, request):
pending = request.registry.queryAdapter(context, IRegistrations,
name='pending')
if pending is None:
pending = PendingRegistrations(context)
+
confirmed = request.registry.queryAdapter(context, IRegistrations,
name='confirmed')
if confirmed is None:
confirmed = ConfirmedRegistrations(context)
+
main_template = get_renderer('templates/main.pt')
return {'main_template': main_template.implementation(),
'pending': sorted(pending),
'confirmed': sorted(confirmed),
}
+def admin_pending(context, request):
+ # Edit one pending registration
+ pending = request.registry.queryAdapter(context, IRegistrations,
+ name='pending')
+ if pending is None:
+ pending = PendingRegistrations(context)
+ email = request.params['pending']
+ record = pending.get(email)
+ if record is None:
+ return HTTPNotFound()
+ main_template = get_renderer('templates/main.pt')
+ return {'main_template': main_template.implementation(),
+ 'page_title': 'Edit Pending Registration',
+ 'email': email,
+ 'token': record.token,
+ }
+
+
+def admin_confirmed(context, request):
+ # Edit one pending registration
+ confirmed = request.registry.queryAdapter(context, IRegistrations,
+ name='confirmed')
+ if confirmed is None:
+ confirmed = ConfirmedRegistrations(context)
+
+ login = request.params['confirmed']
+ record = confirmed.get_by_login(login)
+ if record is None:
+ return HTTPNotFound()
+
+ main_template = get_renderer('templates/main.pt')
+ return {'main_template': main_template.implementation(),
+ 'page_title': 'Edit Confirmed Registration',
+ 'login': login,
+ 'uuid': record.uuid,
+ 'password': record.password,
+ 'token': record.token,
+ 'security_question': record.security_question,
+ 'security_answer': record.security_answer,
+ }
+
+
def add_admin_user():
__doc__ = """ Make an existing cartouche user a member of the 'admin' group.
View
@@ -14,7 +14,7 @@
<aclauthorizationpolicy/>
<view
- context=".interfaces.Root"
+ context=".interfaces.IRoot"
name="register.html"
view=".registration.register_view"
renderer="templates/register.pt"
@@ -64,9 +64,30 @@
/>
<view
- context=".interfaces.Root"
+ context=".interfaces.IRoot"
+ name="admin.html"
+ view=".admin.admin_confirmed"
+ request_method="GET"
+ request_param="confirmed"
+ renderer="templates/admin_registration.pt"
+ permission="admin"
+ />
+
+ <view
+ context=".interfaces.IRoot"
+ name="admin.html"
+ view=".admin.admin_pending"
+ request_method="GET"
+ request_param="pending"
+ renderer="templates/admin_registration.pt"
+ permission="admin"
+ />
+
+ <view
+ context=".interfaces.IRoot"
name="admin.html"
- view=".admin.admin_view"
+ view=".admin.admin_overview"
+ request_method="GET"
renderer="templates/admin.pt"
permission="admin"
/>
@@ -15,30 +15,30 @@
<th align="left">Token</th>
</tr>
<tr tal:repeat="(email, record) pending">
- <td>${email}</td>
+ <td><a href="?pending=${email}">${email}</a></td>
<td>${record.token}</td>
</tr>
</table>
<h3> confirmed registrations </h3>
<table>
<tr>
- <th align="left">UUID</th>
- <th align="left">E-mail</th>
<th align="left">Login</th>
+ <th align="left">E-mail</th>
<th align="left">Hashed password</th>
<th align="left">Security question</th>
<th align="left">Security answer</th>
+ <th align="left">UUID</th>
<th align="left">Token</th>
</tr>
<tr tal:repeat="(key, row) confirmed">
<tal:if tal:condition="not isinstance(row, basestring)">
- <td>${row.uuid}</td>
+ <td><a href="?confirmed=${row.login}">${row.login}</a></td>
<td>${row.email}</td>
- <td>${row.login}</td>
- <td>${row.password}</td>
+ <td>${row.password[6:16]}...</td>
<td>${row.security_question}</td>
<td>${row.security_answer}</td>
+ <td>${row.uuid}</td>
<td>${row.token}</td>
</tal:if>
</tr>
@@ -0,0 +1,6 @@
+<metal:body metal:use-macro="main_template">
+ <metal:slot metal:fill-slot="main">
+ <h1>${page_title}</h1>
+ </metal:slot>
+</metal:body>
+

0 comments on commit 8ed9486

Please sign in to comment.