add url_for_model_changelist, add extra_context to add view, support custom_add_url
diff --git a/xos/core/admin.py b/xos/core/admin.py
index 79f6d06..e6911be 100644
--- a/xos/core/admin.py
+++ b/xos/core/admin.py
@@ -119,6 +119,10 @@
return actions
+ def url_for_model_changelist(self, request, model):
+ # used in add_extra_context
+ return reverse('admin:%s_%s_changelist' % (model._meta.app_label, model._meta.model_name), current_app=model._meta.app_label)
+
def add_extra_context(self, request, extra_context):
# allow custom application breadcrumb url and name
extra_context["custom_app_breadcrumb_url"] = getattr(self, "custom_app_breadcrumb_url", None)
@@ -135,7 +139,7 @@
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) }
+ "url": self.url_for_model_changelist(request,model) }
admins.append(info)
extra_context["registered_admins"] = admins
@@ -176,6 +180,13 @@
return super(XOSAdminMixin, self).changelist_view(request, extra_context=extra_context)
+ def add_view(self, request, extra_context = None):
+ extra_context = extra_context or {}
+
+ self.add_extra_context(request, extra_context)
+
+ return super(XOSAdminMixin, self).add_view(request, extra_context=extra_context)
+
def __user_is_readonly(self, request):
return request.user.isReadOnlyUser()
diff --git a/xos/templates/admin/change_list_bc.html b/xos/templates/admin/change_list_bc.html
index 8a6ba64..5e5e4c1 100644
--- a/xos/templates/admin/change_list_bc.html
+++ b/xos/templates/admin/change_list_bc.html
@@ -4,6 +4,7 @@
{% if not is_popup %}
{% block breadcrumbs %}
+ <!-- template: modify the breadcrumbs to support custom_app_breadcrumb -->
<ul class="breadcrumb">
<li><a href="{% url 'admin:index' %}">{% trans 'Home' %}</a>
<span class="divider">»</span></li>
@@ -18,3 +19,22 @@
</ul>
{% endblock %}
{% endif %}
+
+
+{% block object-tools %}
+ <!-- template: modify object-tools to support custom_add_url -->
+ {% if has_add_permission %}
+ <div class="object-tools">
+ {% block object-tools-items %}
+ {% if custom_add_url %}
+ <a href="{{ custom_add_url }}{% if is_popup %}?_popup=1{% endif %}" class="btn btn-success">
+ {% else %}
+ <a href="{% url cl.opts|admin_urlname:'add' %}{% if is_popup %}?_popup=1{% endif %}" class="btn btn-success">
+ {% endif %}
+ <i class="icon-plus-sign icon-white"></i>
+ {% blocktrans with cl.opts.verbose_name as name %}Add {{ name }}{% endblocktrans %}
+ </a>
+ {% endblock %}
+ </div>
+ {% endif %}
+{% endblock %}