Translate edit-inline template patch to Grappelli's template.
authorW. Trevor King <wking@drexel.edu>
Fri, 5 Aug 2011 16:44:06 +0000 (12:44 -0400)
committerW. Trevor King <wking@drexel.edu>
Fri, 5 Aug 2011 16:44:06 +0000 (12:44 -0400)
Also move it back to example/data/templates/, because otherwise it
won't override the built-in template.

cookbook/templates/admin/edit_inline/tabular.html [deleted file]
example/data/templates/admin/edit_inline/tabular.html [new file with mode: 0644]
example/settings.py

diff --git a/cookbook/templates/admin/edit_inline/tabular.html b/cookbook/templates/admin/edit_inline/tabular.html
deleted file mode 100644 (file)
index b0a2c65..0000000
+++ /dev/null
@@ -1,129 +0,0 @@
-{% load i18n adminmedia admin_modify %}
-{% load url from future %}
-<div class="inline-group" id="{{ inline_admin_formset.formset.prefix }}-group">
-  <div class="tabular inline-related {% if forloop.last %}last-related{% endif %}">
-{{ inline_admin_formset.formset.management_form }}
-<fieldset class="module">
-   <h2>{{ inline_admin_formset.opts.verbose_name_plural|capfirst }}</h2>
-   {{ inline_admin_formset.formset.non_form_errors }}
-   <table>
-     <thead><tr>
-     {% for field in inline_admin_formset.fields %}
-       {% if not field.widget.is_hidden %}
-         <th{% if forloop.first %} colspan="2"{% endif %}{% if field.required %} class="required"{% endif %}>{{ field.label|capfirst }}</th>
-       {% endif %}
-     {% endfor %}
-     {% if inline_admin_formset.formset.can_delete %}<th>{% trans "Delete?" %}</th>{% endif %}
-     </tr></thead>
-
-     <tbody>
-     {% for inline_admin_form in inline_admin_formset %}
-        {% if inline_admin_form.form.non_field_errors %}
-        <tr><td colspan="{{ inline_admin_form|cell_count }}">{{ inline_admin_form.form.non_field_errors }}</td></tr>
-        {% endif %}
-        <tr class="{% cycle "row1" "row2" %} {% if inline_admin_form.original or inline_admin_form.show_url %}has_original{% endif %}{% if forloop.last %} empty-form{% endif %}"
-             id="{{ inline_admin_formset.formset.prefix }}-{% if not forloop.last %}{{ forloop.counter0 }}{% else %}empty{% endif %}">
-        <td class="original">
-          {% if inline_admin_form.original or inline_admin_form.show_url %}<p>
-          {% if inline_admin_form.original %} {{ inline_admin_form.original }}{% if inline_admin_form.model_admin.show_edit_link and inline_admin_form.original %} <a href="{% url adminform.model_admin.admin_site.app_name|add:':'|add:app_label|add:'_'|add:inline_admin_formset.opts.opts.module_name|add:'_changelist' %}{{ inline_admin_form.original.pk }}">Edit</a>{% endif %}{% endif %} 
-          {% if inline_admin_form.show_url %}<a href="../../../r/{{ inline_admin_form.original_content_type_id }}/{{ inline_admin_form.original.id }}/">{% trans "View on site" %}</a>{% endif %}
-            </p>{% endif %}
-          {% if inline_admin_form.has_auto_field %}{{ inline_admin_form.pk_field.field }}{% endif %}
-          {{ inline_admin_form.fk_field.field }}
-          {% spaceless %}
-          {% for fieldset in inline_admin_form %}
-            {% for line in fieldset %}
-              {% for field in line %}
-                {% if field.is_hidden %} {{ field.field }} {% endif %}
-              {% endfor %}
-            {% endfor %}
-          {% endfor %}
-          {% endspaceless %}
-        </td>
-        {% for fieldset in inline_admin_form %}
-          {% for line in fieldset %}
-            {% for field in line %}
-              <td class="{{ field.field.name }}">
-              {% if field.is_readonly %}
-                  <p>{{ field.contents }}</p>
-              {% else %}
-                  {{ field.field.errors.as_ul }}
-                  {{ field.field }}
-              {% endif %}
-              </td>
-            {% endfor %}
-          {% endfor %}
-        {% endfor %}
-        {% if inline_admin_formset.formset.can_delete %}
-          <td class="delete">{% if inline_admin_form.original %}{{ inline_admin_form.deletion_field.field }}{% endif %}</td>
-        {% endif %}
-        </tr>
-     {% endfor %}
-     </tbody>
-   </table>
-</fieldset>
-  </div>
-</div>
-
-<script type="text/javascript">
-(function($) {
-    $(document).ready(function($) {
-        var rows = "#{{ inline_admin_formset.formset.prefix }}-group .tabular.inline-related tbody tr";
-        var alternatingRows = function(row) {
-            $(rows).not(".add-row").removeClass("row1 row2")
-                .filter(":even").addClass("row1").end()
-                .filter(rows + ":odd").addClass("row2");
-        }
-        var reinitDateTimeShortCuts = function() {
-            // Reinitialize the calendar and clock widgets by force
-            if (typeof DateTimeShortcuts != "undefined") {
-                $(".datetimeshortcuts").remove();
-                DateTimeShortcuts.init();
-            }
-        }
-        var updateSelectFilter = function() {
-            // If any SelectFilter widgets are a part of the new form,
-            // instantiate a new SelectFilter instance for it.
-            if (typeof SelectFilter != "undefined"){
-                $(".selectfilter").each(function(index, value){
-                  var namearr = value.name.split('-');
-                  SelectFilter.init(value.id, namearr[namearr.length-1], false, "{% admin_media_prefix %}");
-                });
-                $(".selectfilterstacked").each(function(index, value){
-                  var namearr = value.name.split('-');
-                  SelectFilter.init(value.id, namearr[namearr.length-1], true, "{% admin_media_prefix %}");
-                });
-            }
-        }
-        var initPrepopulatedFields = function(row) {
-            row.find('.prepopulated_field').each(function() {
-                var field = $(this);
-                var input = field.find('input, select, textarea');
-                var dependency_list = input.data('dependency_list') || [];
-                var dependencies = [];
-                $.each(dependency_list, function(i, field_name) {
-                  dependencies.push('#' + row.find(field_name).find('input, select, textarea').attr('id'));
-                });
-                if (dependencies.length) {
-                    input.prepopulate(dependencies, input.attr('maxlength'));
-                }
-            });
-        }
-        $(rows).formset({
-            prefix: "{{ inline_admin_formset.formset.prefix }}",
-            addText: "{% blocktrans with inline_admin_formset.opts.verbose_name|title as verbose_name %}Add another {{ verbose_name }}{% endblocktrans %}",
-            formCssClass: "dynamic-{{ inline_admin_formset.formset.prefix }}",
-            deleteCssClass: "inline-deletelink",
-            deleteText: "{% trans "Remove" %}",
-            emptyCssClass: "empty-form",
-            removed: alternatingRows,
-            added: (function(row) {
-                initPrepopulatedFields(row);
-                reinitDateTimeShortCuts();
-                updateSelectFilter();
-                alternatingRows(row);
-            })
-        });
-    });
-})(django.jQuery);
-</script>
diff --git a/example/data/templates/admin/edit_inline/tabular.html b/example/data/templates/admin/edit_inline/tabular.html
new file mode 100644 (file)
index 0000000..f7f1146
--- /dev/null
@@ -0,0 +1,181 @@
+{% load i18n adminmedia grp_tags %}
+{% load url from future %}
+<!-- group -->
+<div class="group tabular{% if inline_admin_formset.opts.classes %} {{ inline_admin_formset.opts.classes|join:" " }}{% endif %}"
+    id="{{ inline_admin_formset.formset.prefix }}-group" >
+    <h2 class="collapse-handler">{{ inline_admin_formset.opts.verbose_name_plural|capfirst }}</h2>
+    <ul class="tools">
+        <li class="add-handler-container"><a href="javascript://" class="icon add-handler" title="{% trans 'Add Another' %}"> </a></li>
+    </ul>
+    {{ inline_admin_formset.formset.management_form }}
+    {{ inline_admin_formset.formset.non_form_errors }}
+    <!-- container -->
+    <div class="module table">
+        <div class="module thead">
+            <div class="tr">
+                {% for field in inline_admin_formset.fields %}
+                    {% if not field.widget.is_hidden %}
+                        <div class="th {{ field.label|lower|slugify }}{% if field.required %} required{% endif %}">{{ field.label|capfirst }}</div>
+                    {% endif %}
+                {% endfor %}
+                {% if inline_admin_formset.formset.can_delete %}<div class="th">&nbsp;</div>{% endif %}
+            </div>
+        </div>
+        {% with inline_admin_formset.opts.sortable_field_name|default:"" as sortable_field_name %}
+        {% for inline_admin_form in inline_admin_formset|formsetsort:sortable_field_name %}
+            <!-- element -->
+            <div class="module tbody{% if inline_admin_form.original or inline_admin_form.show_url %} has_original{% endif %}{% if forloop.last %} empty-form{% endif %}"
+                id="{{ inline_admin_formset.formset.prefix }}{% if not forloop.last %}{{ forloop.counter0 }}{% else %}-empty{% endif %}">
+                {% if inline_admin_form.form.non_field_errors %}
+                    <ul class="errorlist"><li>{{ inline_admin_form.form.non_field_errors }}</li></ul>
+                {% endif %}
+                <h3 style="display: none;"><b>{{ inline_admin_formset.opts.verbose_name|title }} #{{ forloop.counter }}</b>&nbsp;&nbsp;{% if inline_admin_form.original %} {{ inline_admin_form.original }}{% endif %}</h3>
+                {% spaceless %}
+                {% for fieldset in inline_admin_form %}
+                    {% for line in fieldset %}
+                        {% for field in line %}
+                            {% if field.is_hidden %} {{ field.field }} {% endif %}
+                        {% endfor %}
+                    {% endfor %}
+                {% endfor %}
+                {% endspaceless %}
+                <div class="tr">
+                    {% for fieldset in inline_admin_form %}
+                        {% for line in fieldset %}
+                            {% for field in line %}
+                                <div class="td {{ field.field.name }} {% if field.field.errors %} error{% endif %}">
+                                    {% if field.is_readonly %}
+                                        <p>{{ field.contents }}</p>
+                                    {% else %}
+                                        {{ field.field }}
+                                        {{ field.field.errors.as_ul }}
+                                    {% endif %}
+                                    {% if field.field.help_text %}<p class="help">{{ field.field.help_text }}</p>{% endif %}
+                                </div>
+                            {% endfor %}
+                        {% endfor %}
+                    {% endfor %}
+                    <div class="td tools">
+                        {% spaceless %}
+                        <ul class="tools">
+                            {% if inline_admin_form.model_admin.show_edit_link and inline_admin_form.original %}<li><a href="{% url adminform.model_admin.admin_site.app_name|add:':'|add:app_label|add:'_'|add:inline_admin_formset.opts.opts.module_name|add:'_changelist' %}{{ inline_admin_form.original.pk }}">Edit</a></li>{% endif %}
+                            {% if inline_admin_form.show_url %}<li class="viewsite-link-container"><a href="../../../r/{{ inline_admin_form.original_content_type_id }}/{{ inline_admin_form.original.id }}/" class="icon viewsite-link" title="{% trans 'View on Site' %}" target="_blank"> </a></li>{% endif %}
+                            {% if inline_admin_formset.opts.sortable_field_name %}
+                                <li class="drag-handler-container"><a href="javascript://" class="icon drag-handler" title="{% trans 'Move Item' %}"></a></li>
+                            {% endif %}
+                            {% if inline_admin_formset.formset.can_delete %}
+                                <li class="delete-handler-container">{{ inline_admin_form.deletion_field.field }}<a href="javascript://" class="icon {% if inline_admin_form.original %}delete-handler{% else %}remove-handler{% endif %}" title="{% trans 'Remove' %}"> </a></li>
+                            {% else %}
+                                {% if inline_admin_form.original %}
+                                    <li class="delete-handler-container">&nbsp;</li>
+                                {% else %}
+                                    <li class="delete-handler-container"><a href="javascript://" class="icon remove-handler" title="{% trans 'Remove' %}"> </a></li>
+                                {% endif %}
+                            {% endif %}
+                        </ul>
+                        {% endspaceless %}
+                    </div>
+                    {{ inline_admin_form.fk_field.field }}
+                    {% if inline_admin_form.has_auto_field %}{{ inline_admin_form.pk_field.field }}{% endif %}
+                </div>
+            </div>
+        {% endfor %}
+        {% endwith %}
+    </div>
+    <div class="module add-item">
+        <a href="javascript://" class="add-handler">{% blocktrans with inline_admin_formset.opts.verbose_name|title as verbose_name %}Add WTK another {{ verbose_name }}{% endblocktrans %}</a>
+        <ul class="tools">
+            <li class="add-handler-container"><a href="javascript://" class="icon add-handler" title="{% trans 'Add Item' %}"> </a></li>
+        </ul><br clear="all" />
+    </div>
+</div>
+
+<script type="text/javascript">
+(function($) {
+    $(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);
+</script>
index 49d2f64e49d43b2ba70704354a08df35fb3d83ee..ffefb6d9cd8fb8099df27b93329122bb0cd0c757 100644 (file)
@@ -120,6 +120,7 @@ TEMPLATE_DIRS = (
     # Put strings here, like "/home/html/django_templates" or "C:/www/django/templates".
     # Always use forward slashes, even on Windows.
     # Don't forget to use absolute paths, not relative paths.
+    os.path.join(DATA_DIRECTORY, 'templates'),
 )
 
 INSTALLED_APPS = (