Skip to content

Commit

Permalink
bulk-update page layout
Browse files Browse the repository at this point in the history
  • Loading branch information
saxix committed Jun 1, 2023
1 parent 42c021f commit b843d48
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 47 deletions.
41 changes: 22 additions & 19 deletions src/adminactions/bulk_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,17 @@ class BulkUpdateForm(forms.Form):
action = forms.CharField(
label="", required=True, initial="", widget=forms.HiddenInput()
)

_async = forms.BooleanField(
label="Async",
required=False,
help_text=_("use Celery to run update in background"),
_file = forms.FileField(
label="CSV File",
required=True,
help_text=_("CSV file"),
validators=[FileExtensionValidator(allowed_extensions=["csv", "txt"])],
)
# _async = forms.BooleanField(
# label="Async",
# required=False,
# help_text=_("use Celery to run update in background"),
# )
_clean = forms.BooleanField(
label="Clean()", required=False, help_text=_("if checked calls obj.clean()")
)
Expand All @@ -55,20 +60,18 @@ class BulkUpdateForm(forms.Form):
help_text=_("if checked use obj.save() instead of manager.bulk_update()"),
)

_date_format = forms.CharField(
label="Date format", required=True, help_text=_("Date format")
)
_file = forms.FileField(
label="CSV File",
required=True,
help_text=_("CSV file"),
validators=[FileExtensionValidator(allowed_extensions=["csv", "txt"])],
)
# _date_format = forms.CharField(
# label="Date format", required=True, help_text=_("Date format")
# )


@property
def media(self):
"""Return all media required to render the widgets on this form."""
media = Media(js=["adminactions/js/bulkupdate.js"])
media = Media(js=["adminactions/js/bulkupdate.js"],
css={"all":
["adminactions/css/bulkupdate.css"]
})
for field in self.fields.values():
media = media + field.widget.media
return media
Expand Down Expand Up @@ -218,10 +221,10 @@ def bulk_update(modeladmin, request, queryset): # noqa
"map_form": map_form,
"action_short_description": bulk_update.short_description,
"title": "%s (%s)"
% (
bulk_update.short_description.capitalize(),
smart_str(modeladmin.opts.verbose_name_plural),
),
% (
bulk_update.short_description.capitalize(),
smart_str(modeladmin.opts.verbose_name_plural),
),
"change": True,
"is_popup": False,
"save_as": False,
Expand Down
37 changes: 37 additions & 0 deletions src/adminactions/static/adminactions/css/bulkupdate.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@

table.bulk-update {
border: 1px solid #c9c9c9;

td {
border-left: 1px solid #c9c9c9;
}

select.func_select {
min-width: 100px;
}
}
table{
th.title{
background-color: var(--header-bg);
}
}
#col1 {
float: left;
//padding-right: 10px;
width: 70%;
table{
width: 90%;
}
}

#col2 {
float: right;
width: 30%;
table{
width: 90%;
}
}

#col2 select {
width: 100%;
}
63 changes: 35 additions & 28 deletions src/adminactions/templates/adminactions/bulk_update.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,19 @@
</ol>
{% endif %}
{{ form.non_field_errors }}
<div id='col1'>
<form action="." method="post" enctype="multipart/form-data" id="bulk-update">
<div>Settings: <small>
<select id="sel-cmd">
<option></option>
<option>clear</option>
<option>default</option>
<option>saved</option>
</select>
</small></div>
<form action="." method="post" enctype="multipart/form-data" id="bulk-update">
<div id="col1">
{% csrf_token %}
<div>Configuration: <small>
<select id="sel-cmd">
<option></option>
<option>clear</option>
<option>default</option>
<option>saved</option>
</select>
</small></div>
<table class="mass-update">
<tr><th colspan="3" class="title">Configuration</th></tr>
{% for field in adminform.form %}
{% if field.field.widget.input_type == "hidden" %}
{{ field }}
Expand All @@ -48,22 +49,11 @@
{% endif %}
{% endfor %}
<tr>
<th colspan="4"><h3>CSV Options</h3></th>
</tr>
{% for field in csv_form %}
<tr>
<td>{{ field.label_tag }}</td>
<td colspan="4">
{{ field.errors }}
{{ field }}&nbsp;<span class="help">{{ field.help_text }}</span>
</td>
</tr>
{% endfor %}
<tr>
<th colspan="4"><h3>Columns Mapping</h3>
<div>{{ map_form.index_field.errors }}</div>
</th>
<th colspan="4" class="title">Columns Mapping</th>
</tr>
<tr>
<td colspan="4" class="title">{{ map_form.index_field.errors }}</td>
</tr>
<tr>
<th>field name</th>
<th>Use for index</th>
Expand All @@ -77,7 +67,8 @@
<td class='col_enabler'>
<input type="checkbox" name="fld-index_field" value="{{ field.name }}">
</td>
<td data-col="{{ field.name }}" class='col_field field-{{ map_form.prefix }}-{{ field.name }}-value'>{{ field.errors }}{{ field }}&nbsp;
<td data-col="{{ field.name }}" class='col_field field-{{ map_form.prefix }}-{{ field.name }}-value'>
{{ field.errors }}{{ field }}&nbsp;
</td>
</tr>
{% endif %}
Expand All @@ -87,6 +78,22 @@
{{ hidden }}
{% endfor %}
<input type="submit" name="apply" value="Update {{ selection.count }} records"/>
</form>
</div>
</div>
<div id="col2">
<table>
<tr>
<th colspan="2" class="title"><h3>CSV Options</h3></th>
</tr>
{% for field in csv_form %}
<tr>
<td>{{ field.label_tag }}</td>
<td colspan="4">
{{ field.errors }}
{{ field }}&nbsp;<span class="help">{{ field.help_text }}</span>
</td>
</tr>
{% endfor %}
</table>
</div>
</form>
{% endblock %}

0 comments on commit b843d48

Please sign in to comment.