From b1d3c0c51614c771913e77647f63b92597cfffd4 Mon Sep 17 00:00:00 2001 From: Daniel Date: Sat, 26 Mar 2022 15:45:18 -0400 Subject: [PATCH] Preparing for release to PyPi --- README.md | 18 ++++++++++++++++++ nested_inline/__init__.py | 2 +- .../static/admin/js/inlines-nested.min.js | 2 +- 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index e81f6ae..d038f47 100644 --- a/README.md +++ b/README.md @@ -76,10 +76,28 @@ admin.py admin.site.register(TopLevel, TopLevelAdmin) +Minifying Javascript +-------------------- + +Released versions of this library should have a minified version of the js. + +Minification is done with uglifyjs. If npm is installed on your system, +you can install uglifyjs with the command: +```sh +npm install -g uglify-js +``` + +Then change to the directory where the file 'inlines-nested.js' and +run the following command: +```sh +uglifyjs --compress --mangle --output ./inlines-nested.min.js -- inlines-nested.js +``` Changelist ---------- +0.4.5 - Support django 4.0 and django-csp + 0.4.4 - Add formset:added and formset:removed events (#97) 0.4.3 - Update media so it expects to find jquery in the right place. (#75) diff --git a/nested_inline/__init__.py b/nested_inline/__init__.py index 2d2d7ee..58f60b3 100644 --- a/nested_inline/__init__.py +++ b/nested_inline/__init__.py @@ -1 +1 @@ -__version__ = (0, 4, 4) +__version__ = (0, 4, 5) diff --git a/nested_inline/static/admin/js/inlines-nested.min.js b/nested_inline/static/admin/js/inlines-nested.min.js index 9a02f80..a7a6899 100644 --- a/nested_inline/static/admin/js/inlines-nested.min.js +++ b/nested_inline/static/admin/js/inlines-nested.min.js @@ -1 +1 @@ -!function(m){function h(d,l,o,f){var c=m(!1),p=d.replace(/[-][0-9][-]/g,"-0-"),e=m("#"+p+"-group ."+p+"-0-nested-inline").not(".cloned");return e.length||(e=m("#"+p+"-group ."+p+"-nested-inline").not(".cloned")),e.each(function(e,t){var r=m(this).attr("id").split("-group")[0],i=r.replace(p+"-0",d+"-"+l),a=m(t).clone();if(a.addClass("cloned"),a.children().first().hasClass("tabular")){a.find(".form-row").not(".empty-form").remove(),a.find(".nested-inline-row").remove(),template_form=a.find("#"+r+"-empty"),new_form=template_form.clone().removeClass(o.emptyCssClass).addClass("dynamic-"+i),new_form.insertBefore(template_form),new_form.find("input").each(function(){var e=m(this);e.val()&&e.removeAttr("value")}),x(a,r,i),a.find("#id_"+i+"-TOTAL_FORMS").val(1),a.find("#id_"+i+"-INITIAL_FORMS").val(0);var n=a.find(".add-row").text();a.find(".add-row").remove(),a.find(".tabular.inline-related tbody tr."+i+"-not-nested").tabularFormset({prefix:i,adminStaticPrefix:o.adminStaticPrefix,addText:n,deleteText:o.deleteText}),(s=h(i,0,o,!1)).length&&a.find(".form-row").addClass("no-bottom-border"),s.each(function(){m(this).next()?border_class=" no-bottom-border":border_class="",a.find("#"+i+"-empty").before(m('').html(m("",{colspan:"100%"}).html(m(this))))})}else{var s=h(i,0,o,!0);a.find(".inline-related").not(".empty-form").remove(),template_form=a.find("#"+r+"-empty"),new_form=template_form.clone().removeClass(o.emptyCssClass).addClass("dynamic-"+i),new_form.insertBefore(template_form),new_form.find("input").each(function(){var e=m(this);e.val()&&e.removeAttr("value")}),new_form.find(".inline_label").text("#1"),x(a,r,i),a.find("#id_"+i+"-TOTAL_FORMS").val(1),a.find("#id_"+i+"-INITIAL_FORMS").val(0);n=a.find(".add-row").text();a.find(".add-row").remove(),a.find(".inline-related").stackedFormset({prefix:i,adminStaticPrefix:o.adminStaticPrefix,addText:n,deleteText:o.deleteText}),s.each(function(){new_form.append(m(this))})}f&&(a=a.add(m('
'))),c=c.length?c.add(a):a}),c}function x(e,t,r){e.attr("id",e.attr("id").replace(t,r)),e.find("*").each(function(){m(this).attr("for")&&m(this).attr("for",m(this).attr("for").replace(t,r)),m(this).attr("class")&&m(this).attr("class",m(this).attr("class").replace(t,r)),this.id&&(this.id=this.id.replace(t,r)),this.name&&(this.name=this.name.replace(t,r))}),prefix_fix=e.find(".inline-related").first(),nextIndex=d(r),prefix_fix.hasClass("tabular")&&(prefix_fix=prefix_fix.find(".form-row").first()),prefix_fix.attr("id",prefix_fix.attr("id").replace("-empty","-"+nextIndex)),prefix_fix.find("*").each(function(){m(this).attr("for")&&m(this).attr("for",m(this).attr("for").replace("__prefix__","0")),m(this).attr("class")&&m(this).attr("class",m(this).attr("class").replace("__prefix__","0")),this.id&&(this.id=this.id.replace("__prefix__","0")),this.name&&(this.name=this.name.replace("__prefix__","0"))})}function d(e){return formset_prop=m("#id_"+e+"-TOTAL_FORMS"),formset_prop.length?parseInt(formset_prop.attr("autocomplete","off").val()):0}function l(e,t){var r=d(e);t?m("#id_"+e+"-TOTAL_FORMS").attr("autocomplete","off").val(parseInt(r)+1):m("#id_"+e+"-TOTAL_FORMS").attr("autocomplete","off").val(parseInt(r)-1)}function o(e){var t=m("#id_"+e+"-MAX_NUM_FORMS").attr("autocomplete","off").val();return void 0===t?"":parseInt(t)}m.fn.formset=function(e){var s=m.extend({},m.fn.formset.defaults,e),t=m(this),r=t.parent();d(s.prefix);t.each(function(e){m(this).not("."+s.emptyCssClass).addClass(s.formCssClass)});var i=""===o(s.prefix)||0'+s.addText+""),a=r.find("tr:last a")}else t.filter(":last").after('"),a=t.filter(":last").next().find("a");a.click(function(e){e.preventDefault();var n=d(s.prefix),t=m("#"+s.prefix+"-empty"),r=t.clone(!0);r.removeClass(s.emptyCssClass).addClass(s.formCssClass).attr("id",s.prefix+"-"+n),r.is("tr")?r.children(":last").append('
'+s.deleteText+"
"):r.is("ul")||r.is("ol")?r.append('
  • '+s.deleteText+"
  • "):r.children(":first").append(''+s.deleteText+""),r.find("*").each(function(){var e,t,r,i,a;e=this,t=s.prefix,r=n,i=new RegExp("("+t+"-(\\d+|__prefix__))"),a=t+"-"+r,m(e).attr("for")&&m(e).attr("for",m(e).attr("for").replace(i,a)),e.id&&(e.id=e.id.replace(i,a)),e.name&&(e.name=e.name.replace(i,a))}),r.insertBefore(m(t)),l(s.prefix,!0),""!==o(s.prefix)&&o(s.prefix)-d(s.prefix)<=0&&a.parent().hide(),r.find("a."+s.deleteCssClass).click(function(e){e.preventDefault();for(var t=m(this).parents("."+s.formCssClass),r=t.parent();t.next().hasClass("nested-inline-row");)t.next().remove();t.remove(),l(s.prefix,!1),s.removed&&s.removed(r),m(document).trigger("formset:removed",[t,s.prefix])}),r.is("tr")?(nested_formsets=h(s.prefix,n,s,!1),nested_formsets.length&&r.addClass("no-bottom-border"),nested_formsets.each(function(){m(this).next()?border_class=" no-bottom-border":border_class="",m('').html(m("",{colspan:"100%"}).html(m(this))).insertBefore(m(t))})):(nested_formsets=h(s.prefix,n,s,!0),nested_formsets.each(function(){r.append(m(this))})),s.added&&s.added(r),n+=1,m(document).trigger("formset:added",[r,s.prefix])})}return this},m.fn.formset.defaults={prefix:"form",addText:"add another",deleteText:"remove",addCssClass:"add-row",deleteCssClass:"delete-row",emptyCssClass:"empty-row",formCssClass:"dynamic-form",added:null,removed:null},m.fn.tabularFormset=function(a){var t=m(this),r=function(e){row_number=0,m(t.selector).not(".add-row").removeClass("row1 row2").each(function(){for(m(this).addClass("row"+(row_number%2+1)),next=m(this).next();next.hasClass("nested-inline-row");)next.addClass("row"+(row_number%2+1)),next=next.next();row_number+=1})};return t.formset({prefix:a.prefix,addText:a.addText,formCssClass:"dynamic-"+a.prefix,deleteCssClass:"inline-deletelink",deleteText:a.deleteText,emptyCssClass:"empty-form",removed:r,added:function(e){var i;(i=e).find(".prepopulated_field").each(function(){var e=m(this).find("input, select, textarea"),t=e.data("dependency_list")||[],r=[];m.each(t,function(e,t){r.push("#"+i.find(".field-"+t).find("input, select, textarea").attr("id"))}),r.length&&e.prepopulate(r,e.attr("maxlength"))}),"undefined"!=typeof DateTimeShortcuts&&(m(".datetimeshortcuts").remove(),DateTimeShortcuts.init()),"undefined"!=typeof SelectFilter&&(m(".selectfilter").each(function(e,t){var r=t.name.split("-");SelectFilter.init(t.id,r[r.length-1],!1,a.adminStaticPrefix)}),m(".selectfilterstacked").each(function(e,t){var r=t.name.split("-");SelectFilter.init(t.id,r[r.length-1],!0,a.adminStaticPrefix)})),r()}}),t},m.fn.stackedFormset=function(a){var e=m(this),t=function(e){e.children(".inline-related").not(".empty-form").children("h3").find(".inline_label").each(function(e){var t=e+1;m(this).html(m(this).html().replace(/(#\d+)/g,"#"+t))})};return e.formset({prefix:a.prefix,addText:a.addText,formCssClass:"dynamic-"+a.prefix,deleteCssClass:"inline-deletelink",deleteText:a.deleteText,emptyCssClass:"empty-form",removed:t,added:function(e){var i;(i=e).find(".prepopulated_field").each(function(){var e=m(this).find("input, select, textarea"),t=e.data("dependency_list")||[],r=[];m.each(t,function(e,t){r.push("#"+i.find(".form-row .field-"+t).find("input, select, textarea").attr("id"))}),r.length&&e.prepopulate(r,e.attr("maxlength"))}),"undefined"!=typeof DateTimeShortcuts&&(m(".datetimeshortcuts").remove(),DateTimeShortcuts.init()),"undefined"!=typeof SelectFilter&&(m(".selectfilter").each(function(e,t){var r=t.name.split("-");SelectFilter.init(t.id,r[r.length-1],!1,a.adminStaticPrefix)}),m(".selectfilterstacked").each(function(e,t){var r=t.name.split("-");SelectFilter.init(t.id,r[r.length-1],!0,a.adminStaticPrefix)})),t(e.parent())}}),e}}(django.jQuery); \ No newline at end of file +!function(m){function h(d,l,o,f){var c=m(!1),p=d.replace(/[-][0-9][-]/g,"-0-"),e=m("#"+p+"-group ."+p+"-0-nested-inline").not(".cloned");return(e=e.length?e:m("#"+p+"-group ."+p+"-nested-inline").not(".cloned")).each(function(e,t){var i,r,a=m(this).attr("id").split("-group")[0],n=a.replace(p+"-0",d+"-"+l),s=m(t).clone();s.addClass("cloned"),s.children().first().hasClass("tabular")?(s.find(".form-row").not(".empty-form").remove(),s.find(".nested-inline-row").remove(),template_form=s.find("#"+a+"-empty"),(new_form=template_form.clone().removeClass(o.emptyCssClass).addClass("dynamic-"+n)).insertBefore(template_form),new_form.find("input").each(function(){var e=m(this);e.val()&&e.removeAttr("value")}),x(s,a,n),s.find("#id_"+n+"-TOTAL_FORMS").val(1),s.find("#id_"+n+"-INITIAL_FORMS").val(0),r=s.find(".add-row").text(),s.find(".add-row").remove(),s.find(".tabular.inline-related tbody tr."+n+"-not-nested").tabularFormset({prefix:n,adminStaticPrefix:o.adminStaticPrefix,addText:r,deleteText:o.deleteText}),(i=h(n,0,o,!1)).length&&s.find(".form-row").addClass("no-bottom-border"),i.each(function(){border_class=m(this).next()?" no-bottom-border":"",s.find("#"+n+"-empty").before(m('').html(m("",{colspan:"100%"}).html(m(this))))})):(i=h(n,0,o,!0),s.find(".inline-related").not(".empty-form").remove(),template_form=s.find("#"+a+"-empty"),(new_form=template_form.clone().removeClass(o.emptyCssClass).addClass("dynamic-"+n)).insertBefore(template_form),new_form.find("input").each(function(){var e=m(this);e.val()&&e.removeAttr("value")}),new_form.find(".inline_label").text("#1"),x(s,a,n),s.find("#id_"+n+"-TOTAL_FORMS").val(1),s.find("#id_"+n+"-INITIAL_FORMS").val(0),r=s.find(".add-row").text(),s.find(".add-row").remove(),s.find(".inline-related").stackedFormset({prefix:n,adminStaticPrefix:o.adminStaticPrefix,addText:r,deleteText:o.deleteText}),i.each(function(){new_form.append(m(this))})),f&&(s=s.add(m('
    '))),c=c.length?c.add(s):s}),c}function x(e,t,i){e.attr("id",e.attr("id").replace(t,i)),e.find("*").each(function(){m(this).attr("for")&&m(this).attr("for",m(this).attr("for").replace(t,i)),m(this).attr("class")&&m(this).attr("class",m(this).attr("class").replace(t,i)),this.id&&(this.id=this.id.replace(t,i)),this.name&&(this.name=this.name.replace(t,i))}),prefix_fix=e.find(".inline-related").first(),nextIndex=s(i),(prefix_fix.hasClass("tabular")?prefix_fix=prefix_fix.find(".form-row").first():prefix_fix).attr("id",prefix_fix.attr("id").replace("-empty","-"+nextIndex)),prefix_fix.find("*").each(function(){m(this).attr("for")&&m(this).attr("for",m(this).attr("for").replace("__prefix__","0")),m(this).attr("class")&&m(this).attr("class",m(this).attr("class").replace("__prefix__","0")),this.id&&(this.id=this.id.replace("__prefix__","0")),this.name&&(this.name=this.name.replace("__prefix__","0"))})}function s(e){return(formset_prop=m("#id_"+e+"-TOTAL_FORMS")).length?parseInt(formset_prop.attr("autocomplete","off").val()):0}function d(e,t){var i=s(e);t?m("#id_"+e+"-TOTAL_FORMS").attr("autocomplete","off").val(parseInt(i)+1):m("#id_"+e+"-TOTAL_FORMS").attr("autocomplete","off").val(parseInt(i)-1)}function l(e){e=m("#id_"+e+"-MAX_NUM_FORMS").attr("autocomplete","off").val();return void 0===e?"":parseInt(e)}m.fn.formset=function(e){var r,n=m.extend({},m.fn.formset.defaults,e),e=m(this),t=e.parent(),i=(s(n.prefix),e.each(function(e){m(this).not("."+n.emptyCssClass).addClass(n.formCssClass)}),""===l(n.prefix)||0'+n.addText+""),t.find("tr:last a")):(e.filter(":last").after('"),e.filter(":last").next().find("a"))).click(function(e){e.preventDefault();var a=s(n.prefix),t=m("#"+n.prefix+"-empty"),i=t.clone(!0);i.removeClass(n.emptyCssClass).addClass(n.formCssClass).attr("id",n.prefix+"-"+a),i.is("tr")?i.children(":last").append('"):i.is("ul")||i.is("ol")?i.append('
  • '+n.deleteText+"
  • "):i.children(":first").append(''+n.deleteText+""),i.find("*").each(function(){var e,t,i,r;e=this,t=n.prefix,i=a,r=new RegExp("("+t+"-(\\d+|__prefix__))"),t=t+"-"+i,m(e).attr("for")&&m(e).attr("for",m(e).attr("for").replace(r,t)),e.id&&(e.id=e.id.replace(r,t)),e.name&&(e.name=e.name.replace(r,t))}),i.insertBefore(m(t)),d(n.prefix,!0),""!==l(n.prefix)&&l(n.prefix)-s(n.prefix)<=0&&r.parent().hide(),i.find("a."+n.deleteCssClass).click(function(e){e.preventDefault();for(var t=m(this).parents("."+n.formCssClass),e=t.parent();t.next().hasClass("nested-inline-row");)t.next().remove();t.remove(),d(n.prefix,!1),n.removed&&n.removed(e),m(document).trigger("formset:removed",[t,n.prefix])}),i.is("tr")?((nested_formsets=h(n.prefix,a,n,!1)).length&&i.addClass("no-bottom-border"),nested_formsets.each(function(){border_class=m(this).next()?" no-bottom-border":"",m('').html(m("",{colspan:"100%"}).html(m(this))).insertBefore(m(t))})):(nested_formsets=h(n.prefix,a,n,!0)).each(function(){i.append(m(this))}),n.added&&n.added(i),a+=1,m(document).trigger("formset:added",[i,n.prefix])}),this},m.fn.formset.defaults={prefix:"form",addText:"add another",deleteText:"remove",addCssClass:"add-row",deleteCssClass:"delete-row",emptyCssClass:"empty-row",formCssClass:"dynamic-form",added:null,removed:null},m.fn.tabularFormset=function(a){function t(e){row_number=0,m(i.selector).not(".add-row").removeClass("row1 row2").each(function(){for(m(this).addClass("row"+(row_number%2+1)),next=m(this).next();next.hasClass("nested-inline-row");)next.addClass("row"+(row_number%2+1)),next=next.next();row_number+=1})}var i=m(this);return i.formset({prefix:a.prefix,addText:a.addText,formCssClass:"dynamic-"+a.prefix,deleteCssClass:"inline-deletelink",deleteText:a.deleteText,emptyCssClass:"empty-form",removed:t,added:function(e){var r;(r=e).find(".prepopulated_field").each(function(){var e=m(this).find("input, select, textarea"),t=e.data("dependency_list")||[],i=[];m.each(t,function(e,t){i.push("#"+r.find(".field-"+t).find("input, select, textarea").attr("id"))}),i.length&&e.prepopulate(i,e.attr("maxlength"))}),"undefined"!=typeof DateTimeShortcuts&&(m(".datetimeshortcuts").remove(),DateTimeShortcuts.init()),"undefined"!=typeof SelectFilter&&(m(".selectfilter").each(function(e,t){var i=t.name.split("-");SelectFilter.init(t.id,i[i.length-1],!1,a.adminStaticPrefix)}),m(".selectfilterstacked").each(function(e,t){var i=t.name.split("-");SelectFilter.init(t.id,i[i.length-1],!0,a.adminStaticPrefix)})),t()}}),i},m.fn.stackedFormset=function(a){function t(e){e.children(".inline-related").not(".empty-form").children("h3").find(".inline_label").each(function(e){e+=1;m(this).html(m(this).html().replace(/(#\d+)/g,"#"+e))})}var e=m(this);return e.formset({prefix:a.prefix,addText:a.addText,formCssClass:"dynamic-"+a.prefix,deleteCssClass:"inline-deletelink",deleteText:a.deleteText,emptyCssClass:"empty-form",removed:t,added:function(e){var r;(r=e).find(".prepopulated_field").each(function(){var e=m(this).find("input, select, textarea"),t=e.data("dependency_list")||[],i=[];m.each(t,function(e,t){i.push("#"+r.find(".form-row .field-"+t).find("input, select, textarea").attr("id"))}),i.length&&e.prepopulate(i,e.attr("maxlength"))}),"undefined"!=typeof DateTimeShortcuts&&(m(".datetimeshortcuts").remove(),DateTimeShortcuts.init()),"undefined"!=typeof SelectFilter&&(m(".selectfilter").each(function(e,t){var i=t.name.split("-");SelectFilter.init(t.id,i[i.length-1],!1,a.adminStaticPrefix)}),m(".selectfilterstacked").each(function(e,t){var i=t.name.split("-");SelectFilter.init(t.id,i[i.length-1],!0,a.adminStaticPrefix)})),t(e.parent())}}),e}}(django.jQuery); \ No newline at end of file