Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Simplified management of static URL prefixes.

  • Loading branch information...
commit 4ed8ad9be22cdb2666c3e588be103c01a7ed296b 1 parent 819cc24
@jphalip authored
View
5 treemenus/admin.py
@@ -187,10 +187,5 @@ def move_up_item(self, request, menu_pk, menu_item_pk):
return HttpResponseRedirect('../../../')
-if django.VERSION >= (1, 3):
- MenuAdmin.change_form_template = 'admin/treemenus/menu/change_form_django1.3_and_above.html'
-else:
- MenuAdmin.change_form_template = 'admin/treemenus/menu/change_form_django1.2_and_below.html'
-
admin.site.register(Menu, MenuAdmin)
View
10 ...menu/change_form_django1.3_and_above.html → ...tes/admin/treemenus/menu/change_form.html
@@ -1,6 +1,6 @@
{% extends "admin/change_form.html" %}
-{% load i18n adminmedia %}
-{% load static %}
+{% load i18n %}
+{% load tree_menu_tags %}
{% block after_related_objects %}
{% if change %}
@@ -8,7 +8,7 @@
<h2>{% trans "Menu Items" %}</h2>
<div class="form-row" >
- <img src="{% get_static_prefix %}img/treemenus/icon_addlink.gif" width="10" height="10"/> <a href="items/add/">{% trans "Add an item" %}</a>
+ <img src="{% get_treemenus_static_prefix %}/icon_addlink.gif" width="10" height="10"/> <a href="items/add/">{% trans "Add an item" %}</a>
</div>
<style type="text/css">
@@ -50,13 +50,13 @@
{% if menu_item.has_siblings %}
{% ifnotequal menu_item.rank menu_item.siblings.count %}
- <td width="20" align="center"><a href="items/{{ menu_item.pk }}/move_down/"><img src="{% get_static_prefix %}img/treemenus/arrow-down.gif" border="0" alt="{% trans 'Down' %}"/></b></td>
+ <td width="20" align="center"><a href="items/{{ menu_item.pk }}/move_down/"><img src="{% get_treemenus_static_prefix %}/arrow-down.gif" border="0" alt="{% trans 'Down' %}"/></b></td>
{% else %}
<td width="20">&nbsp;</td>
{% endifnotequal %}
{% ifnotequal menu_item.rank 0 %}
- <td width="20" align="center"><a href="items/{{ menu_item.pk }}/move_up/"><img src="{% get_static_prefix %}img/treemenus/arrow-up.gif" border="0" alt="{% trans 'Up' %}"/></a></td>
+ <td width="20" align="center"><a href="items/{{ menu_item.pk }}/move_up/"><img src="{% get_treemenus_static_prefix %}/arrow-up.gif" border="0" alt="{% trans 'Up' %}"/></a></td>
{% else %}
<td width="20">&nbsp;</td>
{% endifnotequal %}
View
72 treemenus/templates/admin/treemenus/menu/change_form_django1.2_and_below.html
@@ -1,72 +0,0 @@
-{% extends "admin/change_form.html" %}
-{% load i18n adminmedia %}
-
-{% block after_related_objects %}
-{% if change %}
- <fieldset class="module aligned">
- <h2>{% trans "Menu Items" %}</h2>
-
- <div class="form-row" >
- <img src="{% admin_media_prefix %}img/admin/icon_addlink.gif" width="10" height="10"/> <a href="items/add/">{% trans "Add an item" %}</a>
- </div>
-
- <style type="text/css">
- .form-row tbody tr:hover{
- background-color: #ffffbe;
- }
- </style>
-
- <div class="form-row" >
- <table cellspacing="0" width="100%">
- <thead>
- <tr>
- <th>{% trans "Caption" %}</th>
- <th>{% trans "Url" %}</th>
- <th>{% trans "Named url" %}</th>
- <th colspan="2">{% trans "Move" %}</th>
- </tr>
- </thead>
-
- <tbody>
- {% for menu_item in original.root_item.get_flattened %}
- <tr class="{% cycle 'row1' 'row2' %}">
-
- {% if forloop.first %}
- <td colspan="3">
- {% trans "[Root]" %}
- </td>
- {% else %}
- <td width="35%">
- <a href="items/{{ menu_item.pk }}/">{{ menu_item.caption_with_spacer|safe }}</a>
- </td>
- <td width="25%">
- {{ menu_item.url }}
- </td>
- <td width="25%">
- {{ menu_item.named_url }}
- </td>
- {% endif %}
-
- {% if menu_item.has_siblings %}
- {% ifnotequal menu_item.rank menu_item.siblings.count %}
- <td width="20" align="center"><a href="items/{{ menu_item.pk }}/move_down/"><img src="{% admin_media_prefix %}img/admin/arrow-down.gif" border="0" alt="{% trans 'Down' %}"/></b></td>
- {% else %}
- <td width="20">&nbsp;</td>
- {% endifnotequal %}
-
- {% ifnotequal menu_item.rank 0 %}
- <td width="20" align="center"><a href="items/{{ menu_item.pk }}/move_up/"><img src="{% admin_media_prefix %}img/admin/arrow-up.gif" border="0" alt="{% trans 'Up' %}"/></a></td>
- {% else %}
- <td width="20">&nbsp;</td>
- {% endifnotequal %}
- {% else %}
- <td width="20">&nbsp;</td><td width="20">&nbsp;</td>
- {% endif %}
- </tr>
- {% endfor %}
- </tbody>
- </table>
- </div>
- </fieldset>
-{% endif %}
-{% endblock %}
View
12 treemenus/templatetags/tree_menu_tags.py
@@ -1,5 +1,5 @@
+import django
from django import template
-
from django.template.defaulttags import url
from django.template import Node, TemplateSyntaxError
@@ -10,6 +10,16 @@
register = template.Library()
+@register.simple_tag
+def get_treemenus_static_prefix():
+ if django.VERSION >= (1, 3):
+ from django.templatetags.static import PrefixNode
+ return PrefixNode.handle_simple("STATIC_URL") + 'img/treemenus'
+ else:
+ from django.contrib.admin.templatetags.adminmedia import admin_media_prefix
+ return admin_media_prefix() + 'img/admin/'
+
+
def show_menu(context, menu_name, menu_type=None):
menu = Menu.objects.get(name=menu_name)
context['menu'] = menu
View
3  treemenus/tests/settings.py
@@ -19,3 +19,6 @@
ROOT_URLCONF = 'treemenus.tests.urls'
SECRET_KEY = 'Shush... Tell no one.'
+
+# For Django 1.3 and above
+STATIC_URL = '/static/'
Please sign in to comment.
Something went wrong with that request. Please try again.