Skip to content

Commit 1cc908f

Browse files
committed
Port send SDO reminder admin page to new schema
- Legacy-Id: 3359
1 parent 89dd9b8 commit 1cc908f

8 files changed

Lines changed: 239 additions & 3 deletions

File tree

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{% extends "admin/change_form.html" %}
2+
{% load i18n %}
3+
4+
{% block object-tools %}
5+
{% if change %}{% if not is_popup %}
6+
<ul class="object-tools">
7+
{% ifequal original.type_id "sdo" %}
8+
<li><a href="reminder/">SDO Authorized List Reminder</a></li>
9+
{% endifequal %}
10+
<li><a href="history/" class="historylink">{% trans "History" %}</a></li>
11+
{% if has_absolute_url %}<li><a href="../../../r/{{ content_type_id }}/{{ object_id }}/" class="viewsitelink">{% trans "View on site" %}</a></li>{% endif%}
12+
</ul>
13+
{% endif %}{% endif %}
14+
{% endblock %}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{% extends "admin/change_list.html" %}
2+
{% load i18n %}
3+
4+
5+
{% block object-tools %}
6+
{% if has_add_permission %}
7+
<ul class="object-tools">
8+
<li><a href="reminder/">SDO Authorized List Reminder</a></li>
9+
<li>
10+
<a href="add/{% if is_popup %}?_popup=1{% endif %}" class="addlink">
11+
{% blocktrans with cl.opts.verbose_name as name %}Add {{ name }}{% endblocktrans %}
12+
</a>
13+
</li>
14+
</ul>
15+
{% endif %}
16+
{% endblock %}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
{% extends "admin/base_site.html" %}
2+
3+
{% load i18n admin_modify adminmedia %}
4+
5+
{% block extrastyle %}{{ block.super }}<link rel="stylesheet" type="text/css" href="{% admin_media_prefix %}css/forms.css" />{% endblock %}
6+
7+
{% block bodyclass %}change-form{% endblock %}
8+
9+
{% block breadcrumbs %}{% if not is_popup %}
10+
<div class="breadcrumbs">
11+
<a href="../../../">{% trans "Home" %}</a> &rsaquo;
12+
<a href="../../">{{ app_label|capfirst|escape }}</a> &rsaquo;
13+
{% if has_change_permission %}<a href="../">{{ opts.verbose_name_plural|capfirst }}</a>{% else %}{{ opts.verbose_name_plural|capfirst }}{% endif %} &rsaquo;
14+
{% trans "Send reminder" %}
15+
</div>
16+
{% endif %}{% endblock %}
17+
18+
{% block content %}<div id="content-main">
19+
<div>
20+
<h1>Send a reminder to each SDO Liaison Manager</h1>
21+
{% if output %}
22+
<p>
23+
Reminder sent successfully. See the output of the command:
24+
</p>
25+
<pre>
26+
{{ output }}
27+
</pre>
28+
{% else %}
29+
{% if sdo %}
30+
<p>
31+
You can send a reminder to the {{ sdo }} SDO Liaison Manager to request an updated list of persons authorized to send liaison statements on behalf of {{ sdo }}</h1>
32+
</p>
33+
{% else %}
34+
<p>
35+
You can send a reminder to each SDO Liaison Manager to request an updated list of persons authorized to send liaison statements on behalf of his SDO</h1>
36+
</p>
37+
<p>
38+
By clicking the 'Send' button you will send a request to <b>all</b> the SDO Liaison Managers. In order to send the request to one SDO Liaison Manager go to the SDO edit page.
39+
</p>
40+
{% endif %}
41+
<form action="" method="post">
42+
<input type="submit" name="send" value="Send" />
43+
</form>
44+
{% endif %}
45+
</div>
46+
</div>
47+
{% endblock %}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{% extends "admin/change_form.html" %}
2+
{% load i18n %}
3+
4+
{% block object-tools %}
5+
{% if change %}{% if not is_popup %}
6+
<ul class="object-tools">
7+
<li><a href="reminder/">Update Authorized List Reminder</a></li>
8+
<li><a href="history/" class="historylink">{% trans "History" %}</a></li>
9+
{% if has_absolute_url %}<li><a href="../../../r/{{ content_type_id }}/{{ object_id }}/" class="viewsitelink">{% trans "View on site" %}</a></li>{% endif%}
10+
</ul>
11+
{% endif %}{% endif %}
12+
{% endblock %}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{% extends "admin/change_list.html" %}
2+
{% load i18n %}
3+
4+
5+
{% block object-tools %}
6+
{% if has_add_permission %}
7+
<ul class="object-tools">
8+
<li><a href="reminder/">Update Authorized List Reminder</a></li>
9+
<li>
10+
<a href="add/{% if is_popup %}?_popup=1{% endif %}" class="addlink">
11+
{% blocktrans with cl.opts.verbose_name as name %}Add {{ name }}{% endblocktrans %}
12+
</a>
13+
</li>
14+
</ul>
15+
{% endif %}
16+
{% endblock %}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
{% extends "admin/base_site.html" %}
2+
3+
{% load i18n admin_modify adminmedia %}
4+
5+
{% block extrastyle %}{{ block.super }}<link rel="stylesheet" type="text/css" href="{% admin_media_prefix %}css/forms.css" />{% endblock %}
6+
7+
{% block bodyclass %}change-form{% endblock %}
8+
9+
{% block breadcrumbs %}{% if not is_popup %}
10+
<div class="breadcrumbs">
11+
<a href="../../../">{% trans "Home" %}</a> &rsaquo;
12+
<a href="../../">{{ app_label|capfirst|escape }}</a> &rsaquo;
13+
{% if has_change_permission %}<a href="../">{{ opts.verbose_name_plural|capfirst }}</a>{% else %}{{ opts.verbose_name_plural|capfirst }}{% endif %} &rsaquo;
14+
{% trans "Send reminder" %}
15+
</div>
16+
{% endif %}{% endblock %}
17+
18+
{% block content %}<div id="content-main">
19+
<div>
20+
<h1>Send a reminder to each SDO Liaison Manager</h1>
21+
{% if output %}
22+
<p>
23+
Reminder sent successfully. See the output of the command:
24+
</p>
25+
<pre>
26+
{{ output }}
27+
</pre>
28+
{% else %}
29+
{% if sdo %}
30+
<p>
31+
You can send a reminder to the {{ sdo }} SDO Liaison Manager to request an updated list of persons authorized to send liaison statements on behalf of {{ sdo }}</h1>
32+
</p>
33+
{% else %}
34+
<p>
35+
You can send a reminder to each SDO Liaison Manager to request an updated list of persons authorized to send liaison statements on behalf of his SDO</h1>
36+
</p>
37+
<p>
38+
By clicking the 'Send' button you will send a request to <b>all</b> the SDO Liaison Managers. In order to send the request to one SDO Liaison Manager go to the SDO edit page.
39+
</p>
40+
{% endif %}
41+
<form action="" method="post">
42+
<input type="submit" name="send" value="Send" />
43+
</form>
44+
{% endif %}
45+
</div>
46+
</div>
47+
{% endblock %}

redesign/group/admin.py

Lines changed: 86 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,97 @@
11
from django.contrib import admin
2+
from django import template
3+
from django.utils.functional import update_wrapper
4+
from django.contrib.admin.util import unquote
5+
from django.core.exceptions import PermissionDenied
6+
from django.core.management import load_command_class
7+
from django.http import Http404
8+
from django.shortcuts import render_to_response
9+
from django.utils.encoding import force_unicode
10+
from django.utils.functional import update_wrapper
11+
from django.utils.html import escape
12+
from django.utils.translation import ugettext as _
13+
214
from models import *
315

416
class GroupAdmin(admin.ModelAdmin):
517
list_display = ["acronym", "name", "type"]
18+
list_display_links = ["acronym", "name"]
19+
list_filter = ["type"]
620
search_fields = ["name"]
721
ordering = ["name"]
8-
raw_id_fields = ["charter"]
22+
raw_id_fields = ["charter", "parent", "ad"]
23+
24+
def get_urls(self):
25+
from django.conf.urls.defaults import patterns, url
26+
27+
def wrap(view):
28+
def wrapper(*args, **kwargs):
29+
return self.admin_site.admin_view(view)(*args, **kwargs)
30+
return update_wrapper(wrapper, view)
31+
32+
info = self.model._meta.app_label, self.model._meta.module_name
33+
34+
urls = patterns('',
35+
url(r'^reminder/$',
36+
wrap(self.send_reminder),
37+
name='%s_%s_reminder' % info),
38+
url(r'^(.+)/reminder/$',
39+
wrap(self.send_one_reminder),
40+
name='%s_%s_one_reminder' % info),
41+
)
42+
urls += super(GroupAdmin, self).get_urls()
43+
return urls
44+
45+
def send_reminder(self, request, sdo=None):
46+
opts = self.model._meta
47+
app_label = opts.app_label
48+
49+
output = None
50+
sdo_pk = sdo and sdo.pk or None
51+
if request.method == 'POST' and request.POST.get('send', False):
52+
command = load_command_class('ietf.liaisons', 'remind_update_sdo_list')
53+
output=command.handle(return_output=True, sdo_pk=sdo_pk)
54+
output='\n'.join(output)
55+
56+
context = {
57+
'opts': opts,
58+
'has_change_permission': self.has_change_permission(request),
59+
'app_label': app_label,
60+
'output': output,
61+
'sdo': sdo,
62+
}
63+
return render_to_response('admin/group/group/send_sdo_reminder.html',
64+
context,
65+
context_instance = template.RequestContext(request, current_app=self.admin_site.name),
66+
)
67+
68+
def send_one_reminder(self, request, object_id):
69+
model = self.model
70+
opts = model._meta
71+
72+
try:
73+
obj = self.queryset(request).get(pk=unquote(object_id))
74+
except model.DoesNotExist:
75+
obj = None
76+
77+
if not self.has_change_permission(request, obj):
78+
raise PermissionDenied
79+
80+
if obj is None:
81+
raise Http404(_('%(name)s object with primary key %(key)r does not exist.') % {'name': force_unicode(opts.verbose_name), 'key': escape(object_id)})
82+
83+
return self.send_reminder(request, sdo=obj)
84+
985

1086
admin.site.register(Group, GroupAdmin)
1187
admin.site.register(GroupHistory)
1288

13-
admin.site.register(Role)
89+
class RoleAdmin(admin.ModelAdmin):
90+
list_display = ["name", "email", "group"]
91+
list_display_links = ["name"]
92+
search_fields = ["name", "email"]
93+
list_filter = ["name"]
94+
ordering = ["id"]
95+
raw_id_fields = ["email", "group"]
96+
97+
admin.site.register(Role, RoleAdmin)

redesign/group/models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ class Role(models.Model):
8787
email = models.ForeignKey(Email, help_text="Email address used by person for this role")
8888
auth = models.CharField(max_length=255, blank=True) # unused?
8989
def __unicode__(self):
90-
return u"%s is %s in %s" % (self.email.get_name(), self.name.name, self.group.acronym)
90+
return u"%s is %s in %s" % (self.email.get_name(), self.name.name, self.group.acronym or self.group.name)
9191

9292

9393
class RoleHistory(models.Model):

0 commit comments

Comments
 (0)