in a database table: - Added a GroupFeatures model to the group models, and removed the old features.py - Added a agenda type for future use in showing different group types on different agendas. - Renamed the group feature has_materials to has_nonsession_materials. - Added API resources and admin support for the new tables. - Added a Directorate (with reviews) group type as complement to Directorate, to distinguish between directorates with and without reviews. - Adjusted tests as needed. - Updated the fixtures, and fixed the generate_fixtures script to include the new AgendaTypeName objects. There still exists about 70 instances of code comparing the group type with a list of types; most of these should probably be replaced with new features, instead, to make it possible to add new group types through the database table, rather than having to edit the code. That was the purpose of this refactoring from the start, but the presence of this large number of comparisons of group type against lists of types defeats the goal until we add appropriate features and replace the group type list comparisons. - Legacy-Id: 15316
176 lines
6.3 KiB
Python
176 lines
6.3 KiB
Python
from functools import update_wrapper
|
|
|
|
from django.contrib import admin
|
|
from django.contrib.admin.utils import unquote
|
|
from django.core.exceptions import PermissionDenied
|
|
from django.core.management import load_command_class
|
|
from django.http import Http404
|
|
from django.shortcuts import render
|
|
from django.utils.encoding import force_unicode
|
|
from django.utils.html import escape
|
|
from django.utils.translation import ugettext as _
|
|
|
|
from ietf.group.models import (Group, GroupFeatures, GroupHistory, GroupEvent, GroupURL, GroupMilestone,
|
|
GroupMilestoneHistory, GroupStateTransitions, Role, RoleHistory, ChangeStateGroupEvent,
|
|
MilestoneGroupEvent, )
|
|
|
|
class RoleInline(admin.TabularInline):
|
|
model = Role
|
|
raw_id_fields = ["person", "email"]
|
|
|
|
class GroupURLInline(admin.TabularInline):
|
|
model = GroupURL
|
|
|
|
class GroupAdmin(admin.ModelAdmin):
|
|
list_display = ["acronym", "name", "type", "state", "time", "role_list"]
|
|
list_display_links = ["acronym", "name"]
|
|
list_filter = ["type", "state", "time"]
|
|
search_fields = ["acronym", "name"]
|
|
ordering = ["name"]
|
|
raw_id_fields = ["charter", "parent"]
|
|
inlines = [RoleInline, GroupURLInline]
|
|
prepopulated_fields = {"acronym": ("name", )}
|
|
|
|
def role_list(self, obj):
|
|
roles = Role.objects.filter(group=obj).order_by("name", "person__name").select_related('person')
|
|
res = []
|
|
for r in roles:
|
|
res.append(u'<a href="../../person/person/%s/">%s</a> (<a href="../../group/role/%s/">%s)' % (r.person.pk, escape(r.person.plain_name()), r.pk, r.name.name))
|
|
return ", ".join(res)
|
|
role_list.short_description = "Persons"
|
|
role_list.allow_tags = True
|
|
|
|
|
|
# SDO reminder
|
|
def get_urls(self):
|
|
from ietf.utils.urls import url
|
|
|
|
def wrap(view):
|
|
def wrapper(*args, **kwargs):
|
|
return self.admin_site.admin_view(view)(*args, **kwargs)
|
|
return update_wrapper(wrapper, view)
|
|
|
|
info = self.model._meta.app_label, self.model._meta.model_name
|
|
|
|
urls = [
|
|
url(r'^reminder/$', wrap(self.send_reminder), name='%s_%s_reminder' % info),
|
|
url(r'^(.+)/reminder/$', wrap(self.send_one_reminder), name='%s_%s_one_reminder' % info),
|
|
]
|
|
urls += super(GroupAdmin, self).get_urls()
|
|
return urls
|
|
|
|
def send_reminder(self, request, sdo=None):
|
|
opts = self.model._meta
|
|
app_label = opts.app_label
|
|
|
|
output = None
|
|
sdo_pk = sdo and sdo.pk or None
|
|
if request.method == 'POST' and request.POST.get('send', False):
|
|
command = load_command_class('ietf.liaisons', 'remind_update_sdo_list')
|
|
output=command.handle(return_output=True, sdo_pk=sdo_pk)
|
|
output='\n'.join(output)
|
|
|
|
context = {
|
|
'opts': opts,
|
|
'has_change_permission': self.has_change_permission(request),
|
|
'app_label': app_label,
|
|
'output': output,
|
|
'sdo': sdo,
|
|
}
|
|
return render(request, 'admin/group/group/send_sdo_reminder.html', context )
|
|
|
|
|
|
def send_one_reminder(self, request, object_id):
|
|
model = self.model
|
|
opts = model._meta
|
|
|
|
try:
|
|
obj = self.queryset(request).get(pk=unquote(object_id))
|
|
except model.DoesNotExist:
|
|
obj = None
|
|
|
|
if not self.has_change_permission(request, obj):
|
|
raise PermissionDenied
|
|
|
|
if obj is None:
|
|
raise Http404(_('%(name)s object with primary key %(key)r does not exist.') % {'name': force_unicode(opts.verbose_name), 'key': escape(object_id)})
|
|
|
|
return self.send_reminder(request, sdo=obj)
|
|
|
|
|
|
admin.site.register(Group, GroupAdmin)
|
|
|
|
class GroupFeaturesAdmin(admin.ModelAdmin):
|
|
list_display = [
|
|
'type',
|
|
'customize_workflow',
|
|
'has_chartering_process',
|
|
'has_default_jabber',
|
|
'has_dependencies',
|
|
'has_documents',
|
|
'has_nonsession_materials',
|
|
'has_milestones',
|
|
'has_reviews',
|
|
'material_types',
|
|
'agenda_type',
|
|
'admin_roles',
|
|
'about_page',
|
|
'default_tab',
|
|
]
|
|
admin.site.register(GroupFeatures, GroupFeaturesAdmin)
|
|
|
|
class GroupHistoryAdmin(admin.ModelAdmin):
|
|
list_display = ["time", "acronym", "name", "type"]
|
|
list_display_links = ["acronym", "name"]
|
|
list_filter = ["type"]
|
|
search_fields = ["acronym", "name"]
|
|
ordering = ["name"]
|
|
raw_id_fields = ["group", "parent"]
|
|
|
|
admin.site.register(GroupHistory, GroupHistoryAdmin)
|
|
|
|
class GroupURLAdmin(admin.ModelAdmin):
|
|
list_display = [u'id', 'group', 'name', 'url']
|
|
raw_id_fields = ['group']
|
|
search_fields = ['name']
|
|
admin.site.register(GroupURL, GroupURLAdmin)
|
|
|
|
class GroupMilestoneAdmin(admin.ModelAdmin):
|
|
list_display = ["group", "desc", "due", "resolved", "time"]
|
|
search_fields = ["group__name", "group__acronym", "desc", "resolved"]
|
|
raw_id_fields = ["group", "docs"]
|
|
admin.site.register(GroupMilestone, GroupMilestoneAdmin)
|
|
admin.site.register(GroupMilestoneHistory, GroupMilestoneAdmin)
|
|
|
|
class GroupStateTransitionsAdmin(admin.ModelAdmin):
|
|
list_display = [u'id', 'group', 'state']
|
|
raw_id_fields = ['group', 'state']
|
|
admin.site.register(GroupStateTransitions, GroupStateTransitionsAdmin)
|
|
|
|
class RoleAdmin(admin.ModelAdmin):
|
|
list_display = ["name", "person", "email", "group"]
|
|
list_display_links = ["name"]
|
|
search_fields = ["name__name", "person__name", "email__address"]
|
|
list_filter = ["name", "group"]
|
|
ordering = ["id"]
|
|
raw_id_fields = ["email", "person", "group"]
|
|
admin.site.register(Role, RoleAdmin)
|
|
admin.site.register(RoleHistory, RoleAdmin)
|
|
|
|
class GroupEventAdmin(admin.ModelAdmin):
|
|
list_display = ["id", "group", "time", "type", "by", ]
|
|
search_fields = ["group__name", "group__acronym"]
|
|
admin.site.register(GroupEvent, GroupEventAdmin)
|
|
|
|
class ChangeStateGroupEventAdmin(admin.ModelAdmin):
|
|
list_display = ["id", "group", "state", "time", "type", "by", ]
|
|
list_filter = ["state", "time", ]
|
|
search_fields = ["group__name", "group__acronym"]
|
|
admin.site.register(ChangeStateGroupEvent, ChangeStateGroupEventAdmin)
|
|
|
|
class MilestoneGroupEventAdmin(admin.ModelAdmin):
|
|
list_display = [u'id', 'group', 'time', 'type', 'by', 'desc', 'milestone']
|
|
list_filter = ['time']
|
|
raw_id_fields = ['group', 'by', 'milestone']
|
|
admin.site.register(MilestoneGroupEvent, MilestoneGroupEventAdmin)
|