for HPC view, force app label to show HpcServer rather than hpc admin index
diff --git a/xos/core/admin.py b/xos/core/admin.py
index b32a281..272069b 100644
--- a/xos/core/admin.py
+++ b/xos/core/admin.py
@@ -119,7 +119,28 @@
return actions
+ def add_extra_context(self, extra_context):
+ # allow custom application breadcrumb url and name
+ extra_context["custom_app_breadcrumb_url"] = getattr(self, "custom_app_breadcrumb_url", None)
+ extra_context["custom_app_breadcrumb_name"] = getattr(self, "custom_app_breadcrumb_name", None)
+
+ # for Service admins to render their Administration page
+ if getattr(self, "extracontext_registered_admins", False):
+ admins=[]
+ for model, model_admin in admin.site._registry.items():
+ if model == self.model:
+ continue
+ if model._meta.app_label == self.model._meta.app_label:
+ info = {"app": model._meta.app_label,
+ "model": model._meta.model_name,
+ "name": capfirst(model._meta.verbose_name_plural),
+ "url": reverse('admin:%s_%s_changelist' % (model._meta.app_label, model._meta.model_name), current_app=model._meta.app_label) }
+ admins.append(info)
+ extra_context["registered_admins"] = admins
+
def change_view(self,request,object_id, extra_context=None):
+ extra_context = extra_context or {}
+
if self.__user_is_readonly(request):
if not hasattr(self, "readonly_save"):
# save the original readonly fields
@@ -136,6 +157,8 @@
if hasattr(self, "inlines_save"):
self.inlines = self.inlines_save
+ self.add_extra_context(extra_context)
+
try:
return super(PermissionCheckingAdminMixin, self).change_view(request, object_id, extra_context=extra_context)
except PermissionDenied:
@@ -145,6 +168,14 @@
request.readonly = True
return super(PermissionCheckingAdminMixin, self).change_view(request, object_id, extra_context=extra_context)
+ def changelist_view(self, request, extra_context = None):
+ extra_context = extra_context or {}
+
+ self.add_extra_context(extra_context)
+
+ return super(PermissionCheckingAdminMixin, self).changelist_view(request, extra_context=extra_context)
+
+
def __user_is_readonly(self, request):
return request.user.isReadOnlyUser()
@@ -194,28 +225,7 @@
return True
class ServiceAppAdmin (SingletonAdmin):
- # This is for services to render an 'administration page'. It builds up
- # a list of all registered admins for the service, and passes them in the
- # 'registered_admins' member of the template context.
-
- def change_view(self, request, object_id, extra_context=None):
- extra_context = extra_context or {}
-
- admins=[]
- for model, model_admin in admin.site._registry.items():
- if model == self.model:
- continue
- if model._meta.app_label == self.model._meta.app_label:
- info = {"app": model._meta.app_label,
- "model": model._meta.model_name,
- "name": capfirst(model._meta.verbose_name_plural),
- "url": reverse('admin:%s_%s_changelist' % (model._meta.app_label, model._meta.model_name), current_app=model._meta.app_label) }
- admins.append(info)
-
- extra_context["registered_admins"] = admins
-
- return super(ServiceAppAdmin, self).change_view(request=request, object_id=object_id,
- extra_context=extra_context)
+ extracontext_registered_admins = True
class XOSTabularInline(admin.TabularInline):
def __init__(self, *args, **kwargs):
diff --git a/xos/hpc/admin.py b/xos/hpc/admin.py
index b247deb..c419a12 100644
--- a/xos/hpc/admin.py
+++ b/xos/hpc/admin.py
@@ -32,6 +32,21 @@
suit_form_includes = (('hpcadmin.html', 'top', 'administration'),)
+class HPCAdmin(ReadOnlyAwareAdmin):
+ # Change the application breadcrumb to point to an HPC Service if one is
+ # defined
+
+ change_form_template = "admin/change_form_bc.html"
+ change_list_template = "admin/change_list_bc.html"
+ custom_app_breadcrumb_name = "Hpc"
+ @property
+ def custom_app_breadcrumb_url(self):
+ services = HpcService.objects.all()
+ if len(services)==1:
+ return "/admin/hpc/hpcservice/%s/" % services[0].id
+ else:
+ return "/admin/hpc/hpcservice/"
+
class CDNPrefixInline(XOSTabularInline):
model = CDNPrefix
extra = 0
@@ -46,7 +61,7 @@
fields = ('backend_status_icon', 'content_provider_id', 'name', 'enabled')
readonly_fields = ('backend_status_icon', 'content_provider_id',)
-class OriginServerAdmin(ReadOnlyAwareAdmin):
+class OriginServerAdmin(HPCAdmin):
list_display = ('backend_status_icon', 'url','protocol','redirects','contentProvider','authenticated','enabled' )
list_display_links = ('backend_status_icon', 'url', )
@@ -60,7 +75,7 @@
'serviceProvider' : LinkedSelect
}
-class ContentProviderAdmin(ReadOnlyAwareAdmin):
+class ContentProviderAdmin(HPCAdmin):
form = ContentProviderForm
list_display = ('backend_status_icon', 'name','description','enabled' )
list_display_links = ('backend_status_icon', 'name', )
@@ -73,7 +88,7 @@
suit_form_tabs = (('general','Details'),('prefixes','CDN Prefixes'))
-class ServiceProviderAdmin(ReadOnlyAwareAdmin):
+class ServiceProviderAdmin(HPCAdmin):
list_display = ('backend_status_icon', 'name', 'description', 'enabled')
list_display_links = ('backend_status_icon', 'name', )
fieldsets = [
@@ -92,7 +107,7 @@
'contentProvider' : LinkedSelect
}
-class CDNPrefixAdmin(ReadOnlyAwareAdmin):
+class CDNPrefixAdmin(HPCAdmin):
form = CDNPrefixForm
list_display = ['backend_status_icon', 'prefix','contentProvider']
list_display_links = ('backend_status_icon', 'prefix', )
@@ -100,7 +115,7 @@
readonly_fields = ('backend_status_text', )
user_readonly_fields = ['prefix','contentProvider', "cdn_prefix_id", "description", "defaultOriginServer", "enabled"]
-class SiteMapAdmin(ReadOnlyAwareAdmin):
+class SiteMapAdmin(HPCAdmin):
model = SiteMap
verbose_name = "Site Map"
verbose_name_plural = "Site Map"
@@ -109,7 +124,7 @@
user_readonly_fields = ('backend_status_text', "name", "contentProvider", "serviceProvider", "description", "map")
readonly_fields = ('backend_status_text', )
-class AccessMapAdmin(ReadOnlyAwareAdmin):
+class AccessMapAdmin(HPCAdmin):
model = AccessMap
verbose_name = "Access Map"
verbose_name_plural = "Access Map"
diff --git a/xos/templates/admin/change_form_bc.html b/xos/templates/admin/change_form_bc.html
new file mode 100644
index 0000000..70b5e9f
--- /dev/null
+++ b/xos/templates/admin/change_form_bc.html
@@ -0,0 +1,32 @@
+{% extends "admin/change_form.html" %}
+{% load i18n admin_static admin_modify suit_tags admin_urls %}
+{% load url from future %}
+
+{% if not is_popup %}
+ {% block breadcrumbs %}
+ <ul class="breadcrumb">
+ <li>
+ <a href="{% url 'admin:index' %}">{% trans 'Home' %}</a>
+ <span class="divider">»</span>
+ </li>
+ <li>
+ {% if custom_app_breadcrumb_url %}
+ <a href="{{ custom_app_breadcrumb_url }}">{{ custom_app_breadcrumb_name }}</a>
+ {% else %}
+ <a href="{% url 'admin:app_list' app_label=opts.app_label %}">{% firstof opts.app_config.verbose_name app_label|capfirst|escape %}</a>
+ {% endif %}
+ <span class="divider">»</span>
+ </li>
+ <li>
+ {% if has_change_permission %}
+ <a href="{% url opts|admin_urlname:'changelist' %}">
+ {{ opts.verbose_name_plural|capfirst }}</a>{% else %}
+ {{ opts.verbose_name_plural|capfirst }}{% endif %}
+ <span class="divider">»</span>
+ </li>
+ <li class="active">
+ {% if add %}{% trans 'Add' %} {{ opts.verbose_name }}{% else %}{{ original|truncatewords:"18" }}{% endif %}
+ </li>
+ </ul>
+ {% endblock %}
+{% endif %}
diff --git a/xos/templates/admin/change_list_bc.html b/xos/templates/admin/change_list_bc.html
new file mode 100644
index 0000000..8a6ba64
--- /dev/null
+++ b/xos/templates/admin/change_list_bc.html
@@ -0,0 +1,20 @@
+{% extends "admin/change_list.html" %}
+{% load i18n admin_static admin_modify suit_tags admin_urls %}
+{% load url from future %}
+
+{% if not is_popup %}
+ {% block breadcrumbs %}
+ <ul class="breadcrumb">
+ <li><a href="{% url 'admin:index' %}">{% trans 'Home' %}</a>
+ <span class="divider">»</span></li>
+ <li>
+ {% if custom_app_breadcrumb_url %}
+ <a href="{{ custom_app_breadcrumb_url }}">{{ custom_app_breadcrumb_name }}</a>
+ {% else %}
+ <a href="{% url 'admin:app_list' app_label=cl.opts.app_label %}">{% firstof opts.app_config.verbose_name app_label|capfirst|escape %}</a>
+ {% endif %}
+ <span class="divider">»</span></li>
+ <li class="active">{{ cl.opts.verbose_name_plural|capfirst }}</li>
+ </ul>
+ {% endblock %}
+{% endif %}