From ee5fbe5df5817578911fbf0c2e1fc2698e701b73 Mon Sep 17 00:00:00 2001 From: Stephen Burrows Date: Wed, 27 Apr 2011 14:44:44 -0400 Subject: [PATCH] Upped the django requirement to 1.3. Brought over grappelli use of the grp_tags library and updated the attribute inline javascript. --- README | 2 +- README.markdown | 2 +- .../grappelli_tabular_attribute.html | 125 ++++++++++++------ .../grappelli_tabular_container.html | 7 +- 4 files changed, 92 insertions(+), 44 deletions(-) diff --git a/README b/README index 4b1a6f7..6e47860 100644 --- a/README +++ b/README @@ -2,7 +2,7 @@ Philo is a foundation for developing web content management systems. Prerequisites: * Python 2.5.4+ - * Django 1.2+ + * Django 1.3+ * django-mptt e734079+ * (Optional) django-grappelli 2.0+ * (Optional) recaptcha-django r6 diff --git a/README.markdown b/README.markdown index 8060db8..349a727 100644 --- a/README.markdown +++ b/README.markdown @@ -3,7 +3,7 @@ Philo is a foundation for developing web content management systems. Prerequisites: * [Python 2.5.4+ <http://www.python.org>](http://www.python.org/) - * [Django 1.2+ <http://www.djangoproject.com/>](http://www.djangoproject.com/) + * [Django 1.3+ <http://www.djangoproject.com/>](http://www.djangoproject.com/) * [django-mptt e734079+ <https://github.com/django-mptt/django-mptt/>](https://github.com/django-mptt/django-mptt/) * (Optional) [django-grappelli 2.0+ <http://code.google.com/p/django-grappelli/>](http://code.google.com/p/django-grappelli/) * (Optional) [south 0.7.2+ <http://south.aeracode.org/)](http://south.aeracode.org/) diff --git a/templates/admin/philo/edit_inline/grappelli_tabular_attribute.html b/templates/admin/philo/edit_inline/grappelli_tabular_attribute.html index ccead57..25c1ac4 100644 --- a/templates/admin/philo/edit_inline/grappelli_tabular_attribute.html +++ b/templates/admin/philo/edit_inline/grappelli_tabular_attribute.html @@ -1,4 +1,4 @@ -{% load i18n adminmedia %} +{% load i18n adminmedia grp_tags %}
(function($) { - $(document).ready(function($) { - - $("#{{ inline_admin_formset.formset.prefix }}-group").grp_inline({ - prefix: "{{ inline_admin_formset.formset.prefix }}", - onBeforeAdded: function(inline) {}, - onAfterAdded: function(form) { - grappelli.reinitDateTimeFields(form); - grappelli.updateSelectFilter(form); - form.find("input.vForeignKeyRawIdAdminField").grp_related_fk({lookup_url:"{% url grp_related_lookup %}"}); - form.find("input.vManyToManyRawIdAdminField").grp_related_m2m({lookup_url:"{% url grp_m2m_lookup %}"}); - form.find("input[name*='object_id'][name$='id']").grp_related_generic({lookup_url:"{% url grp_related_lookup %}"}); - }, - }); - - {% if inline_admin_formset.opts.sortable_field_name %} - $("#{{ inline_admin_formset.formset.prefix }}-group > div.table").sortable({ - handle: "a.drag-handler", - items: "div.dynamic-form", - axis: "y", - appendTo: 'body', - forceHelperSize: true, - containment: '#{{ inline_admin_formset.formset.prefix }}-group > div.table', - tolerance: 'pointer', - }); - $("#{{ opts.module_name }}_form").bind("submit", function(){ - var sortable_field_name = "{{ inline_admin_formset.opts.sortable_field_name }}"; - var i = 0; - $("#{{ inline_admin_formset.formset.prefix }}-group").find("div.dynamic-form").each(function(){ - var fields = $(this).find("div.td :input[value]"); - if (fields.serialize()) { - $(this).find("input[name$='"+sortable_field_name+"']").val(i); - i++; - } - }); - }); - {% endif %} - - }); + $(document).ready(function($) { + + var prefix = "{{ inline_admin_formset.formset.prefix }}"; + var related_lookup_fields_fk = {% get_related_lookup_fields_fk inline_admin_formset.opts %}; + var related_lookup_fields_m2m = {% get_related_lookup_fields_m2m inline_admin_formset.opts %}; + var related_lookup_fields_generic = {% get_related_lookup_fields_generic inline_admin_formset.opts %}; + $.each(related_lookup_fields_fk, function() { + $("#{{ inline_admin_formset.formset.prefix }}-group > div.table") + .find("input[name^='" + prefix + "'][name$='" + this + "']") + .grp_related_fk({lookup_url:"{% url grp_related_lookup %}"}); + }); + $.each(related_lookup_fields_m2m, function() { + $("#{{ inline_admin_formset.formset.prefix }}-group > div.table") + .find("input[name^='" + prefix + "'][name$='" + this + "']") + .grp_related_m2m({lookup_url:"{% url grp_m2m_lookup %}"}); + }); + $.each(related_lookup_fields_generic, function() { + var content_type = this[0], + object_id = this[1]; + $("#{{ inline_admin_formset.formset.prefix }}-group > div.table") + .find("input[name^='" + prefix + "'][name$='" + this[1] + "']") + .each(function() { + var i = $(this).attr("id").match(/-\d+-/); + if (i) { + var ct_id = "#id_" + prefix + i[0] + content_type, + obj_id = "#id_" + prefix + i[0] + object_id; + $(this).grp_related_generic({content_type:ct_id, object_id:obj_id, lookup_url:"{% url grp_related_lookup %}"}); + } + }); + }); + + $("#{{ inline_admin_formset.formset.prefix }}-group").grp_inline({ + prefix: "{{ inline_admin_formset.formset.prefix }}", + onBeforeAdded: function(inline) {}, + onAfterAdded: function(form) { + grappelli.reinitDateTimeFields(form); + grappelli.updateSelectFilter(form); + $.each(related_lookup_fields_fk, function() { + form.find("input[name^='" + prefix + "'][name$='" + this + "']") + .grp_related_fk({lookup_url:"{% url grp_related_lookup %}"}); + }); + $.each(related_lookup_fields_m2m, function() { + form.find("input[name^='" + prefix + "'][name$='" + this + "']") + .grp_related_m2m({lookup_url:"{% url grp_m2m_lookup %}"}); + }); + $.each(related_lookup_fields_generic, function() { + var content_type = this[0], + object_id = this[1]; + form.find("input[name^='" + prefix + "'][name$='" + this[1] + "']") + .each(function() { + var i = $(this).attr("id").match(/-\d+-/); + if (i) { + var ct_id = "#id_" + prefix + i[0] + content_type, + obj_id = "#id_" + prefix + i[0] + object_id; + $(this).grp_related_generic({content_type:ct_id, object_id:obj_id, lookup_url:"{% url grp_related_lookup %}"}); + } + }); + }); + }, + }); + + {% if inline_admin_formset.opts.sortable_field_name %} + $("#{{ inline_admin_formset.formset.prefix }}-group > div.table").sortable({ + handle: "a.drag-handler", + items: "div.dynamic-form", + axis: "y", + appendTo: 'body', + forceHelperSize: true, + containment: '#{{ inline_admin_formset.formset.prefix }}-group > div.table', + tolerance: 'pointer', + }); + $("#{{ opts.module_name }}_form").bind("submit", function(){ + var sortable_field_name = "{{ inline_admin_formset.opts.sortable_field_name }}"; + var i = 0; + $("#{{ inline_admin_formset.formset.prefix }}-group").find("div.dynamic-form").each(function(){ + var fields = $(this).find("div.td :input[value]"); + if (fields.serialize()) { + $(this).find("input[name$='"+sortable_field_name+"']").val(i); + i++; + } + }); + }); + {% endif %} + + }); })(django.jQuery); diff --git a/templates/admin/philo/edit_inline/grappelli_tabular_container.html b/templates/admin/philo/edit_inline/grappelli_tabular_container.html index 59aba8f..621fea6 100644 --- a/templates/admin/philo/edit_inline/grappelli_tabular_container.html +++ b/templates/admin/philo/edit_inline/grappelli_tabular_container.html @@ -20,12 +20,13 @@ {% endfor %}{% endspaceless %} {% endfor %} {% for form in inline_admin_formset.formset.forms %} -
+
{{ form.non_field_errors }} - -
+
{% for field in form %} {% if not field.is_hidden %} + {% comment %}This will be true for one field: the content/content reference{% endcomment %} +
{{ field }} {{ field.errors }} -- 2.20.1