django-unfold 0.40.0__py3-none-any.whl → 0.41.0__py3-none-any.whl
Sign up to get free protection for your applications and to get access to all the features.
- {django_unfold-0.40.0.dist-info → django_unfold-0.41.0.dist-info}/METADATA +6 -1
- {django_unfold-0.40.0.dist-info → django_unfold-0.41.0.dist-info}/RECORD +41 -38
- {django_unfold-0.40.0.dist-info → django_unfold-0.41.0.dist-info}/WHEEL +1 -1
- unfold/admin.py +5 -0
- unfold/contrib/filters/forms.py +2 -2
- unfold/contrib/forms/templates/unfold/forms/array.html +2 -2
- unfold/contrib/guardian/templates/admin/guardian/model/obj_perms_manage.html +1 -1
- unfold/contrib/guardian/templates/admin/guardian/model/obj_perms_manage_group.html +1 -1
- unfold/contrib/guardian/templates/admin/guardian/model/obj_perms_manage_user.html +1 -1
- unfold/contrib/import_export/templates/admin/import_export/export.html +1 -1
- unfold/contrib/import_export/templates/admin/import_export/import.html +1 -1
- unfold/contrib/simple_history/templates/simple_history/object_history_form.html +1 -1
- unfold/static/admin/js/inlines.js +439 -0
- unfold/static/unfold/css/styles.css +1 -1
- unfold/static/unfold/fonts/material-symbols/Material-Symbols-Outlined.woff2 +0 -0
- unfold/static/unfold/fonts/material-symbols/styles.css +1 -2
- unfold/static/unfold/js/alpine.sort.js +1 -0
- unfold/static/unfold/js/app.js +36 -10
- unfold/static/unfold/js/select2.init.js +1 -1
- unfold/styles.css +5 -1
- unfold/templates/admin/app_index.html +1 -1
- unfold/templates/admin/auth/user/change_password.html +1 -1
- unfold/templates/admin/base.html +1 -1
- unfold/templates/admin/change_form.html +1 -1
- unfold/templates/admin/change_list.html +46 -44
- unfold/templates/admin/delete_confirmation.html +4 -9
- unfold/templates/admin/delete_selected_confirmation.html +4 -8
- unfold/templates/admin/edit_inline/stacked.html +15 -6
- unfold/templates/admin/edit_inline/tabular.html +36 -19
- unfold/templates/admin/object_history.html +1 -1
- unfold/templates/admin/submit_line.html +8 -8
- unfold/templates/registration/password_change_done.html +1 -1
- unfold/templates/registration/password_change_form.html +1 -1
- unfold/templates/unfold/change_list_filter.html +7 -9
- unfold/templates/unfold/helpers/delete_submit_line.html +11 -0
- unfold/templates/unfold/helpers/display_header.html +8 -3
- unfold/templates/unfold/helpers/field_readonly_value.html +1 -1
- unfold/templates/unfold/helpers/fieldset_row.html +2 -0
- unfold/templates/unfold/layouts/skeleton.html +1 -0
- unfold/templates/unfold/widgets/url.html +7 -5
- {django_unfold-0.40.0.dist-info → django_unfold-0.41.0.dist-info}/LICENSE.md +0 -0
@@ -0,0 +1,439 @@
|
|
1
|
+
/*global DateTimeShortcuts, SelectFilter*/
|
2
|
+
/**
|
3
|
+
* Django admin inlines
|
4
|
+
*
|
5
|
+
* Based on jQuery Formset 1.1
|
6
|
+
* @author Stanislaus Madueke (stan DOT madueke AT gmail DOT com)
|
7
|
+
* @requires jQuery 1.2.6 or later
|
8
|
+
*
|
9
|
+
* Copyright (c) 2009, Stanislaus Madueke
|
10
|
+
* All rights reserved.
|
11
|
+
*
|
12
|
+
* Spiced up with Code from Zain Memon's GSoC project 2009
|
13
|
+
* and modified for Django by Jannis Leidel, Travis Swicegood and Julien Phalip.
|
14
|
+
*
|
15
|
+
* Licensed under the New BSD License
|
16
|
+
* See: https://opensource.org/licenses/bsd-license.php
|
17
|
+
*/
|
18
|
+
"use strict";
|
19
|
+
{
|
20
|
+
const $ = django.jQuery;
|
21
|
+
$.fn.formset = function (opts) {
|
22
|
+
const options = $.extend({}, $.fn.formset.defaults, opts);
|
23
|
+
const $this = $(this);
|
24
|
+
const $parent = $this.parent();
|
25
|
+
const updateElementIndex = function (el, prefix, ndx) {
|
26
|
+
const id_regex = new RegExp("(" + prefix + "-(\\d+|__prefix__))");
|
27
|
+
const replacement = prefix + "-" + ndx;
|
28
|
+
if ($(el).prop("for")) {
|
29
|
+
$(el).prop("for", $(el).prop("for").replace(id_regex, replacement));
|
30
|
+
}
|
31
|
+
if (el.id) {
|
32
|
+
el.id = el.id.replace(id_regex, replacement);
|
33
|
+
}
|
34
|
+
if (el.name) {
|
35
|
+
el.name = el.name.replace(id_regex, replacement);
|
36
|
+
}
|
37
|
+
};
|
38
|
+
const totalForms = $("#id_" + options.prefix + "-TOTAL_FORMS").prop(
|
39
|
+
"autocomplete",
|
40
|
+
"off"
|
41
|
+
);
|
42
|
+
let nextIndex = parseInt(totalForms.val(), 10);
|
43
|
+
const maxForms = $("#id_" + options.prefix + "-MAX_NUM_FORMS").prop(
|
44
|
+
"autocomplete",
|
45
|
+
"off"
|
46
|
+
);
|
47
|
+
const minForms = $("#id_" + options.prefix + "-MIN_NUM_FORMS").prop(
|
48
|
+
"autocomplete",
|
49
|
+
"off"
|
50
|
+
);
|
51
|
+
let addButton;
|
52
|
+
|
53
|
+
/**
|
54
|
+
* The "Add another MyModel" button below the inline forms.
|
55
|
+
*/
|
56
|
+
const addInlineAddButton = function () {
|
57
|
+
if (addButton === null) {
|
58
|
+
if ($this.prop("tagName") === "TR") {
|
59
|
+
// If forms are laid out as table rows, insert the
|
60
|
+
// "add" button in a new table row:
|
61
|
+
const numCols = $this.eq(-1).children().length;
|
62
|
+
$parent.append(
|
63
|
+
'<tr class="' +
|
64
|
+
options.addCssClass +
|
65
|
+
'"><td colspan="' +
|
66
|
+
numCols +
|
67
|
+
'"><a href="#">' +
|
68
|
+
options.addText +
|
69
|
+
"</a></tr>"
|
70
|
+
);
|
71
|
+
addButton = $parent.find("tr:last a");
|
72
|
+
} else {
|
73
|
+
// Otherwise, insert it immediately after the last form:
|
74
|
+
$this
|
75
|
+
.filter(":last")
|
76
|
+
.after(
|
77
|
+
'<div class="' +
|
78
|
+
options.addCssClass +
|
79
|
+
'"><a href="#">' +
|
80
|
+
options.addText +
|
81
|
+
"</a></div>"
|
82
|
+
);
|
83
|
+
addButton = $this.filter(":last").next().find("a");
|
84
|
+
}
|
85
|
+
}
|
86
|
+
addButton.on("click", addInlineClickHandler);
|
87
|
+
};
|
88
|
+
|
89
|
+
const addInlineClickHandler = function (e) {
|
90
|
+
e.preventDefault();
|
91
|
+
const template = $("#" + options.prefix + "-empty");
|
92
|
+
const row = template.clone(true);
|
93
|
+
row
|
94
|
+
.removeClass(options.emptyCssClass)
|
95
|
+
.addClass(options.formCssClass)
|
96
|
+
.attr("id", options.prefix + "-" + nextIndex);
|
97
|
+
addInlineDeleteButton(row);
|
98
|
+
row.find("*").each(function () {
|
99
|
+
updateElementIndex(this, options.prefix, totalForms.val());
|
100
|
+
});
|
101
|
+
// Insert the new form when it has been fully edited.
|
102
|
+
row.insertBefore($(template));
|
103
|
+
// Update number of total forms.
|
104
|
+
$(totalForms).val(parseInt(totalForms.val(), 10) + 1);
|
105
|
+
nextIndex += 1;
|
106
|
+
// Hide the add button if there's a limit and it's been reached.
|
107
|
+
if (maxForms.val() !== "" && maxForms.val() - totalForms.val() <= 0) {
|
108
|
+
addButton.parent().hide();
|
109
|
+
}
|
110
|
+
// Show the remove buttons if there are more than min_num.
|
111
|
+
toggleDeleteButtonVisibility(row.closest(".inline-group"));
|
112
|
+
|
113
|
+
// Pass the new form to the post-add callback, if provided.
|
114
|
+
if (options.added) {
|
115
|
+
options.added(row);
|
116
|
+
}
|
117
|
+
row.get(0).dispatchEvent(
|
118
|
+
new CustomEvent("formset:added", {
|
119
|
+
bubbles: true,
|
120
|
+
detail: {
|
121
|
+
formsetName: options.prefix,
|
122
|
+
},
|
123
|
+
})
|
124
|
+
);
|
125
|
+
};
|
126
|
+
|
127
|
+
/**
|
128
|
+
* The "X" button that is part of every unsaved inline.
|
129
|
+
* (When saved, it is replaced with a "Delete" checkbox.)
|
130
|
+
*/
|
131
|
+
const addInlineDeleteButton = function (row) {
|
132
|
+
if (row.is("tr")) {
|
133
|
+
// If the forms are laid out in table rows, insert
|
134
|
+
// the remove button into the last table cell:
|
135
|
+
row
|
136
|
+
.children(":last")
|
137
|
+
.append(
|
138
|
+
'<div><a class="' +
|
139
|
+
options.deleteCssClass +
|
140
|
+
'" href="#">' +
|
141
|
+
options.deleteText +
|
142
|
+
"</a></div>"
|
143
|
+
);
|
144
|
+
} else if (row.is("ul") || row.is("ol")) {
|
145
|
+
// If they're laid out as an ordered/unordered list,
|
146
|
+
// insert an <li> after the last list item:
|
147
|
+
row.append(
|
148
|
+
'<li><a class="' +
|
149
|
+
options.deleteCssClass +
|
150
|
+
'" href="#">' +
|
151
|
+
options.deleteText +
|
152
|
+
"</a></li>"
|
153
|
+
);
|
154
|
+
} else {
|
155
|
+
// Otherwise, just insert the remove button as the
|
156
|
+
// last child element of the form's container:
|
157
|
+
row
|
158
|
+
.children(":first")
|
159
|
+
.append(
|
160
|
+
'<span><a class="' +
|
161
|
+
options.deleteCssClass +
|
162
|
+
'" href="#">' +
|
163
|
+
options.deleteText +
|
164
|
+
"</a></span>"
|
165
|
+
);
|
166
|
+
}
|
167
|
+
// Add delete handler for each row.
|
168
|
+
row
|
169
|
+
.find("a." + options.deleteCssClass)
|
170
|
+
.on("click", inlineDeleteHandler.bind(this));
|
171
|
+
};
|
172
|
+
|
173
|
+
const inlineDeleteHandler = function (e1) {
|
174
|
+
e1.preventDefault();
|
175
|
+
const deleteButton = $(e1.target);
|
176
|
+
const row = deleteButton.closest("." + options.formCssClass);
|
177
|
+
const inlineGroup = row.closest(".inline-group");
|
178
|
+
// Remove the parent form containing this button,
|
179
|
+
// and also remove the relevant row with non-field errors:
|
180
|
+
const prevRow = row.prev();
|
181
|
+
if (prevRow.length && prevRow.hasClass("row-form-errors")) {
|
182
|
+
prevRow.remove();
|
183
|
+
}
|
184
|
+
row.remove();
|
185
|
+
nextIndex -= 1;
|
186
|
+
// Pass the deleted form to the post-delete callback, if provided.
|
187
|
+
if (options.removed) {
|
188
|
+
options.removed(row);
|
189
|
+
}
|
190
|
+
document.dispatchEvent(
|
191
|
+
new CustomEvent("formset:removed", {
|
192
|
+
detail: {
|
193
|
+
formsetName: options.prefix,
|
194
|
+
},
|
195
|
+
})
|
196
|
+
);
|
197
|
+
// Update the TOTAL_FORMS form count.
|
198
|
+
const forms = $("." + options.formCssClass);
|
199
|
+
$("#id_" + options.prefix + "-TOTAL_FORMS").val(forms.length);
|
200
|
+
// Show add button again once below maximum number.
|
201
|
+
if (maxForms.val() === "" || maxForms.val() - forms.length > 0) {
|
202
|
+
addButton.parent().show();
|
203
|
+
}
|
204
|
+
// Hide the remove buttons if at min_num.
|
205
|
+
toggleDeleteButtonVisibility(inlineGroup);
|
206
|
+
// Also, update names and ids for all remaining form controls so
|
207
|
+
// they remain in sequence:
|
208
|
+
let i, formCount;
|
209
|
+
const updateElementCallback = function () {
|
210
|
+
updateElementIndex(this, options.prefix, i);
|
211
|
+
};
|
212
|
+
for (i = 0, formCount = forms.length; i < formCount; i++) {
|
213
|
+
updateElementIndex($(forms).get(i), options.prefix, i);
|
214
|
+
$(forms.get(i)).find("*").each(updateElementCallback);
|
215
|
+
}
|
216
|
+
};
|
217
|
+
|
218
|
+
const toggleDeleteButtonVisibility = function (inlineGroup) {
|
219
|
+
if (minForms.val() !== "" && minForms.val() - totalForms.val() >= 0) {
|
220
|
+
inlineGroup.find(".inline-deletelink").hide();
|
221
|
+
} else {
|
222
|
+
inlineGroup.find(".inline-deletelink").show();
|
223
|
+
}
|
224
|
+
};
|
225
|
+
|
226
|
+
$this.each(function (i) {
|
227
|
+
$(this)
|
228
|
+
.not("." + options.emptyCssClass)
|
229
|
+
.addClass(options.formCssClass);
|
230
|
+
});
|
231
|
+
|
232
|
+
// Create the delete buttons for all unsaved inlines:
|
233
|
+
$this
|
234
|
+
.filter(
|
235
|
+
"." +
|
236
|
+
options.formCssClass +
|
237
|
+
":not(.has_original):not(." +
|
238
|
+
options.emptyCssClass +
|
239
|
+
")"
|
240
|
+
)
|
241
|
+
.each(function () {
|
242
|
+
addInlineDeleteButton($(this));
|
243
|
+
});
|
244
|
+
toggleDeleteButtonVisibility($this);
|
245
|
+
|
246
|
+
// Create the add button, initially hidden.
|
247
|
+
addButton = options.addButton;
|
248
|
+
addInlineAddButton();
|
249
|
+
|
250
|
+
// Show the add button if allowed to add more items.
|
251
|
+
// Note that max_num = None translates to a blank string.
|
252
|
+
const showAddButton =
|
253
|
+
maxForms.val() === "" || maxForms.val() - totalForms.val() > 0;
|
254
|
+
if ($this.length && showAddButton) {
|
255
|
+
addButton.parent().show();
|
256
|
+
} else {
|
257
|
+
addButton.parent().hide();
|
258
|
+
}
|
259
|
+
|
260
|
+
return this;
|
261
|
+
};
|
262
|
+
|
263
|
+
/* Setup plugin defaults */
|
264
|
+
$.fn.formset.defaults = {
|
265
|
+
prefix: "form", // The form prefix for your django formset
|
266
|
+
addText: "add another", // Text for the add link
|
267
|
+
deleteText: "remove", // Text for the delete link
|
268
|
+
addCssClass: "add-row", // CSS class applied to the add link
|
269
|
+
deleteCssClass: "delete-row", // CSS class applied to the delete link
|
270
|
+
emptyCssClass: "empty-row", // CSS class applied to the empty row
|
271
|
+
formCssClass: "dynamic-form", // CSS class applied to each form in a formset
|
272
|
+
added: null, // Function called each time a new form is added
|
273
|
+
removed: null, // Function called each time a form is deleted
|
274
|
+
addButton: null, // Existing add button to use
|
275
|
+
};
|
276
|
+
|
277
|
+
// Tabular inlines ---------------------------------------------------------
|
278
|
+
$.fn.tabularFormset = function (selector, options) {
|
279
|
+
const $rows = $(this);
|
280
|
+
|
281
|
+
const reinitDateTimeShortCuts = function () {
|
282
|
+
// Reinitialize the calendar and clock widgets by force
|
283
|
+
if (typeof DateTimeShortcuts !== "undefined") {
|
284
|
+
$(".datetimeshortcuts").remove();
|
285
|
+
DateTimeShortcuts.init();
|
286
|
+
}
|
287
|
+
};
|
288
|
+
|
289
|
+
const updateSelectFilter = function () {
|
290
|
+
// If any SelectFilter widgets are a part of the new form,
|
291
|
+
// instantiate a new SelectFilter instance for it.
|
292
|
+
if (typeof SelectFilter !== "undefined") {
|
293
|
+
$(".selectfilter").each(function (index, value) {
|
294
|
+
SelectFilter.init(value.id, this.dataset.fieldName, false);
|
295
|
+
});
|
296
|
+
$(".selectfilterstacked").each(function (index, value) {
|
297
|
+
SelectFilter.init(value.id, this.dataset.fieldName, true);
|
298
|
+
});
|
299
|
+
}
|
300
|
+
};
|
301
|
+
|
302
|
+
const initPrepopulatedFields = function (row) {
|
303
|
+
row.find(".prepopulated_field").each(function () {
|
304
|
+
const field = $(this),
|
305
|
+
input = field.find("input, select, textarea"),
|
306
|
+
dependency_list = input.data("dependency_list") || [],
|
307
|
+
dependencies = [];
|
308
|
+
$.each(dependency_list, function (i, field_name) {
|
309
|
+
dependencies.push(
|
310
|
+
"#" +
|
311
|
+
row
|
312
|
+
.find(".field-" + field_name)
|
313
|
+
.find("input, select, textarea")
|
314
|
+
.attr("id")
|
315
|
+
);
|
316
|
+
});
|
317
|
+
if (dependencies.length) {
|
318
|
+
input.prepopulate(dependencies, input.attr("maxlength"));
|
319
|
+
}
|
320
|
+
});
|
321
|
+
};
|
322
|
+
|
323
|
+
$rows.formset({
|
324
|
+
prefix: options.prefix,
|
325
|
+
addText: options.addText,
|
326
|
+
formCssClass: "dynamic-" + options.prefix,
|
327
|
+
deleteCssClass: "inline-deletelink",
|
328
|
+
deleteText: options.deleteText,
|
329
|
+
emptyCssClass: "empty-form",
|
330
|
+
added: function (row) {
|
331
|
+
initPrepopulatedFields(row);
|
332
|
+
reinitDateTimeShortCuts();
|
333
|
+
updateSelectFilter();
|
334
|
+
},
|
335
|
+
addButton: options.addButton,
|
336
|
+
});
|
337
|
+
|
338
|
+
return $rows;
|
339
|
+
};
|
340
|
+
|
341
|
+
// Stacked inlines ---------------------------------------------------------
|
342
|
+
$.fn.stackedFormset = function (selector, options) {
|
343
|
+
const $rows = $(this);
|
344
|
+
const updateInlineLabel = function (row) {
|
345
|
+
$(selector)
|
346
|
+
.find(".inline_label")
|
347
|
+
.each(function (i) {
|
348
|
+
const count = i + 1;
|
349
|
+
$(this).html(
|
350
|
+
$(this)
|
351
|
+
.html()
|
352
|
+
.replace(/(#\d+)/g, "#" + count)
|
353
|
+
);
|
354
|
+
});
|
355
|
+
};
|
356
|
+
|
357
|
+
const reinitDateTimeShortCuts = function () {
|
358
|
+
// Reinitialize the calendar and clock widgets by force, yuck.
|
359
|
+
if (typeof DateTimeShortcuts !== "undefined") {
|
360
|
+
$(".datetimeshortcuts").remove();
|
361
|
+
DateTimeShortcuts.init();
|
362
|
+
}
|
363
|
+
};
|
364
|
+
|
365
|
+
const updateSelectFilter = function () {
|
366
|
+
// If any SelectFilter widgets were added, instantiate a new instance.
|
367
|
+
if (typeof SelectFilter !== "undefined") {
|
368
|
+
$(".selectfilter").each(function (index, value) {
|
369
|
+
SelectFilter.init(value.id, this.dataset.fieldName, false);
|
370
|
+
});
|
371
|
+
$(".selectfilterstacked").each(function (index, value) {
|
372
|
+
SelectFilter.init(value.id, this.dataset.fieldName, true);
|
373
|
+
});
|
374
|
+
}
|
375
|
+
};
|
376
|
+
|
377
|
+
const initPrepopulatedFields = function (row) {
|
378
|
+
row.find(".prepopulated_field").each(function () {
|
379
|
+
const field = $(this),
|
380
|
+
input = field.find("input, select, textarea"),
|
381
|
+
dependency_list = input.data("dependency_list") || [],
|
382
|
+
dependencies = [];
|
383
|
+
$.each(dependency_list, function (i, field_name) {
|
384
|
+
// Dependency in a fieldset.
|
385
|
+
let field_element = row.find(".form-row .field-" + field_name);
|
386
|
+
// Dependency without a fieldset.
|
387
|
+
if (!field_element.length) {
|
388
|
+
field_element = row.find(".form-row.field-" + field_name);
|
389
|
+
}
|
390
|
+
dependencies.push(
|
391
|
+
"#" + field_element.find("input, select, textarea").attr("id")
|
392
|
+
);
|
393
|
+
});
|
394
|
+
if (dependencies.length) {
|
395
|
+
input.prepopulate(dependencies, input.attr("maxlength"));
|
396
|
+
}
|
397
|
+
});
|
398
|
+
};
|
399
|
+
|
400
|
+
$rows.formset({
|
401
|
+
prefix: options.prefix,
|
402
|
+
addText: options.addText,
|
403
|
+
formCssClass: "dynamic-" + options.prefix,
|
404
|
+
deleteCssClass: "inline-deletelink",
|
405
|
+
deleteText: options.deleteText,
|
406
|
+
emptyCssClass: "empty-form",
|
407
|
+
removed: updateInlineLabel,
|
408
|
+
added: function (row) {
|
409
|
+
initPrepopulatedFields(row);
|
410
|
+
reinitDateTimeShortCuts();
|
411
|
+
updateSelectFilter();
|
412
|
+
updateInlineLabel(row);
|
413
|
+
},
|
414
|
+
addButton: options.addButton,
|
415
|
+
});
|
416
|
+
|
417
|
+
return $rows;
|
418
|
+
};
|
419
|
+
|
420
|
+
$(document).ready(function () {
|
421
|
+
$(".js-inline-admin-formset").each(function () {
|
422
|
+
const data = $(this).data(),
|
423
|
+
inlineOptions = data.inlineFormset;
|
424
|
+
let selector;
|
425
|
+
switch (data.inlineType) {
|
426
|
+
case "stacked":
|
427
|
+
selector = inlineOptions.name + "-group .inline-related";
|
428
|
+
$(selector).stackedFormset(selector, inlineOptions.options);
|
429
|
+
break;
|
430
|
+
case "tabular":
|
431
|
+
selector =
|
432
|
+
inlineOptions.name +
|
433
|
+
"-group .tabular.inline-related tbody:last > tr.form-row";
|
434
|
+
$(selector).tabularFormset(selector, inlineOptions.options);
|
435
|
+
break;
|
436
|
+
}
|
437
|
+
});
|
438
|
+
});
|
439
|
+
}
|