Skip to content

Commit 96dbf40

Browse files
author
Martin J. Laubach
committed
Prepare overwriting of imported files
1 parent 935bb68 commit 96dbf40

3 files changed

Lines changed: 14 additions & 2 deletions

File tree

feincms/module/medialibrary/models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,7 @@ def bulk_upload(request):
435435

436436
if request.method == 'POST' and 'data' in request.FILES:
437437
try:
438-
count = import_zipfile(request.POST.get('category'), request.FILES['data'])
438+
count = import_zipfile(request.POST.get('category'), request.POST.get('overwrite', False), request.FILES['data'])
439439
messages.info(request, _("%d files imported") % count)
440440
except Exception, e:
441441
messages.error(request, _("ZIP import failed: %s") % str(e))

feincms/module/medialibrary/zip.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,15 @@
2626
export_magic = 'feincms-export-01'
2727

2828
# ------------------------------------------------------------------------
29-
def import_zipfile(category_id, data):
29+
def import_zipfile(category_id, overwrite, data):
30+
"""
31+
Import a collection of media files from a zip file.
32+
33+
category_id: if set, the pk of a Category that all uploaded
34+
files will have added (eg. cathegory "newly uploaded files")
35+
overwrite: attempt to overwrite existing files. This might
36+
not work with non-trivial storage handlers
37+
"""
3038
category = None
3139
if category_id:
3240
category = Category.objects.get(pk=int(category_id))

feincms/templates/admin/medialibrary/mediafile/change_list.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,16 @@
1212
<label for="data">{% trans "Bulk upload a ZIP file:" %}
1313
<input type="file" name="data">
1414
</label>
15+
| {% trans "Category" %}
1516
<select name="category">
1617
<option value="">---</option>
1718
{% for cat in categories %}
1819
<option value="{{ cat.id }}">{{ cat.path }}</option>
1920
{% endfor %}
2021
</select>
22+
| {% trans "Overwrite" %}
23+
<input type="checkbox" name="overwrite">
24+
|
2125
<input type="submit" value="{% trans "Send" %}">
2226
</p>
2327
</form>

0 commit comments

Comments
 (0)