embed support for HPC UI
diff --git a/xos/hpc/admin.py b/xos/hpc/admin.py
index 6a6fb5c..f276165 100644
--- a/xos/hpc/admin.py
+++ b/xos/hpc/admin.py
@@ -11,12 +11,16 @@
from django.contrib.contenttypes import generic
from suit.widgets import LinkedSelect
from core.admin import ServiceAppAdmin,SliceInline,ServiceAttrAsTabInline, ReadOnlyAwareAdmin, XOSTabularInline, SliderWidget, ServicePrivilegeInline
+from core.middleware import get_request
from functools import update_wrapper
from django.contrib.admin.views.main import ChangeList
from django.core.urlresolvers import reverse
from django.contrib.admin.utils import quote
+import threading
+_thread_locals = threading.local()
+
class FilteredChangeList(ChangeList):
""" A special ChangeList with a doctored url_for_result function that
points to the filteredchange view instead of the default change
@@ -25,6 +29,7 @@
def __init__(self, request, *args, **kwargs):
self.hpcService = getattr(request, "hpcService", None)
+ self.embedded = getattr(request, "embedded", False)
super(FilteredChangeList, self).__init__(request, *args, **kwargs)
def url_for_result(self, result):
@@ -32,10 +37,17 @@
return super(FilteredChangeList, self).url_for_result(result)
pk = getattr(result, self.pk_attname)
- return reverse('admin:%s_%s_filteredchange' % (self.opts.app_label,
- self.opts.model_name),
- args=(quote(self.hpcService.id), quote(pk),),
- current_app=self.model_admin.admin_site.name)
+ if embedded:
+ return reverse('admin:%s_%s_embeddedfilteredchange' % (self.opts.app_label,
+ self.opts.model_name),
+ args=(quote(self.hpcService.id), quote(pk),),
+ current_app=self.model_admin.admin_site.name)
+
+ else:
+ return reverse('admin:%s_%s_filteredchange' % (self.opts.app_label,
+ self.opts.model_name),
+ args=(quote(self.hpcService.id), quote(pk),),
+ current_app=self.model_admin.admin_site.name)
class FilteredAdmin(ReadOnlyAwareAdmin):
"""
@@ -57,6 +69,14 @@
the add link when the changelist is empty
"""
+ @property
+ def change_list_template(self):
+ return _thread_locals.change_list_template
+
+ @property
+ def change_form_template(self):
+ return _thread_locals.change_form_template
+
def get_urls(self):
from django.conf.urls import patterns, url
@@ -69,7 +89,9 @@
info = self.model._meta.app_label, self.model._meta.model_name
my_urls = [
url(r'^(.+)/filteredlist/$', wrap(self.filtered_changelist_view), name="%s_%s_filteredchangelist" % info),
+ url(r'^(.+)/embeddedfilteredlist/$', wrap(self.embedded_filtered_changelist_view), name="%s_%s_embeddedfilteredchangelist" % info),
url(r'^(.+)/(.+)/filteredchange$', wrap(self.filtered_change_view), name='%s_%s_filteredchange' % info),
+ url(r'^(.+)/(.+)/embeddedfilteredchange$', wrap(self.embedded_filtered_change_view), name='%s_%s_embeddedfilteredchange' % info),
url(r'^(.+)/filteredadd/$', wrap(self.filtered_add_view), name='%s_%s_filteredadd' % info),
]
return my_urls + urls
@@ -81,14 +103,40 @@
extra_context["custom_changelist_breadcrumb_url"] = "/admin/hpc/%s/%s/filteredlist/" % (self.model._meta.model_name, str(request.hpcService.id))
extra_context["custom_add_url"] = "/admin/hpc/%s/%s/filteredadd/" % (self.model._meta.model_name, str(request.hpcService.id))
+ def changelist_view(self, *args, **kwargs):
+ if "template" in kwargs:
+ _thread_locals.change_list_template = kwargs["template"]
+ del kwargs["template"]
+ else:
+ _thread_locals.change_list_template = "admin/change_list_bc.html"
+ return super(FilteredAdmin, self).changelist_view(*args, **kwargs)
+
def filtered_changelist_view(self, request, hpcServiceId, extra_context=None):
request.hpcService = HpcService.objects.get(id=hpcServiceId)
return self.changelist_view(request, extra_context=extra_context)
+ def embedded_filtered_changelist_view(self, request, hpcServiceId, extra_context=None):
+ request.hpcService = HpcService.objects.get(id=hpcServiceId)
+ request.embedded = True
+ return self.changelist_view(request, template="admin/change_list_embedded.html", extra_context=extra_context)
+
+ def change_view(self, *args, **kwargs):
+ if "template" in kwargs:
+ _thread_locals.change_form_template = kwargs["template"]
+ del kwargs["template"]
+ else:
+ _thread_locals.change_form_template = "admin/change_form_bc.html"
+ return super(FilteredAdmin, self).change_view(*args, **kwargs)
+
def filtered_change_view(self, request, hpcServiceId, object_id, extra_context=None):
request.hpcService = HpcService.objects.get(id=hpcServiceId)
return self.change_view(request, object_id, extra_context=extra_context)
+ def embedded_filtered_change_view(self, request, hpcServiceId, object_id, extra_context=None):
+ request.hpcService = HpcService.objects.get(id=hpcServiceId)
+ request.embedded = True
+ return self.change_view(request, object_id, template="admin/change_form_embedded.html", extra_context=extra_context)
+
def filtered_add_view(self, request, hpcServiceId, extra_context=None):
request.hpcService = HpcService.objects.get(id=hpcServiceId)
return self.add_view(request, extra_context=extra_context)
@@ -158,8 +206,18 @@
# 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"
+ """
+ @property
+ def change_form_template(self):
+ request=get_request()
+ if request.GET.get("embedded",False):
+ return "admin/change_form_embedded.html"
+ else:
+ return "admin/change_form_bc.html"
+ """
+
+ #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):