.
@@ -22,6 +22,19 @@
|
||||
.table-container .table{min-width:1100px}
|
||||
</style>
|
||||
|
||||
<div style="margin-bottom:1rem">
|
||||
<form method="post" action="{% url 'cards:overview_create_images' %}" enctype="multipart/form-data" style="display:inline-block; margin-right:1rem">
|
||||
{% csrf_token %}
|
||||
<div class="file has-name">
|
||||
<label class="file-label">
|
||||
<input class="file-input" type="file" name="images" multiple>
|
||||
<span class="file-cta"><span class="file-icon">📁</span><span class="file-label">Select images…</span></span>
|
||||
</label>
|
||||
</div>
|
||||
<button class="button is-small is-link" type="submit">Create cards from images</button>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<form method="post" action="{% url 'cards:overview_bulk_update' %}">
|
||||
{% csrf_token %}
|
||||
<div class="table-container">
|
||||
|
||||
@@ -15,4 +15,5 @@ urlpatterns = [
|
||||
path('backgrounds/<int:pk>/delete/', views.background_delete, name='background_delete'),
|
||||
path('overview/', views.cards_overview, name='overview'),
|
||||
path('overview/bulk-update/', views.cards_bulk_update, name='overview_bulk_update'),
|
||||
path('overview/create-images/', views.cards_bulk_create_images, name='overview_create_images'),
|
||||
]
|
||||
|
||||
@@ -192,3 +192,26 @@ def cards_bulk_update(request):
|
||||
# If invalid, re-render the overview with errors
|
||||
backgrounds = BackgroundImage.objects.all()
|
||||
return render(request, 'cards/bulk_edit.html', {'formset': formset, 'backgrounds': backgrounds})
|
||||
|
||||
|
||||
def cards_bulk_create_images(request):
|
||||
"""Create multiple Dinosaur cards from uploaded images (one card per image).
|
||||
|
||||
Expects a multipart POST with one or more files in the `images` field.
|
||||
The card `name` is derived from the filename if not provided.
|
||||
"""
|
||||
if request.method != 'POST':
|
||||
return HttpResponseBadRequest('Only POST allowed')
|
||||
files = request.FILES.getlist('images')
|
||||
if not files:
|
||||
return HttpResponseBadRequest('No images uploaded')
|
||||
created = []
|
||||
for f in files:
|
||||
# derive a friendly name from filename
|
||||
base = os.path.splitext(getattr(f, 'name', '') or '')[0]
|
||||
name = base.replace('_', ' ').replace('-', ' ').strip().title() or 'New Dinosaur'
|
||||
d = Dinosaur(name=name, image=f)
|
||||
d.save()
|
||||
created.append(d)
|
||||
# Redirect back to overview
|
||||
return redirect('cards:overview')
|
||||
|
||||
|
After Width: | Height: | Size: 2.0 MiB |
|
After Width: | Height: | Size: 1.2 MiB |
|
After Width: | Height: | Size: 1.2 MiB |
|
After Width: | Height: | Size: 1.1 MiB |
|
After Width: | Height: | Size: 1.4 MiB |
|
After Width: | Height: | Size: 1.3 MiB |
|
After Width: | Height: | Size: 1.3 MiB |
|
After Width: | Height: | Size: 1.2 MiB |
|
After Width: | Height: | Size: 1.3 MiB |
|
After Width: | Height: | Size: 1.3 MiB |
|
After Width: | Height: | Size: 1.2 MiB |
|
After Width: | Height: | Size: 1.0 MiB |
|
After Width: | Height: | Size: 1.9 MiB |
|
After Width: | Height: | Size: 1.8 MiB |
|
After Width: | Height: | Size: 1.6 MiB |
|
After Width: | Height: | Size: 1.4 MiB |
|
After Width: | Height: | Size: 1.7 MiB |
|
After Width: | Height: | Size: 1.5 MiB |
|
After Width: | Height: | Size: 1.8 MiB |
|
After Width: | Height: | Size: 1.3 MiB |
|
After Width: | Height: | Size: 1.3 MiB |
|
After Width: | Height: | Size: 1.8 MiB |
|
After Width: | Height: | Size: 1.3 MiB |
|
After Width: | Height: | Size: 2.1 MiB |
|
After Width: | Height: | Size: 1.5 MiB |
|
After Width: | Height: | Size: 1.5 MiB |
|
After Width: | Height: | Size: 1.2 MiB |
@@ -21,6 +21,19 @@
|
||||
.table-container .table{min-width:1100px}
|
||||
</style>
|
||||
|
||||
<div style="margin-bottom:1rem">
|
||||
<form method="post" action="{% url 'cards:overview_create_images' %}" enctype="multipart/form-data" style="display:inline-block; margin-right:1rem">
|
||||
{% csrf_token %}
|
||||
<div class="file has-name">
|
||||
<label class="file-label">
|
||||
<input class="file-input" type="file" name="images" multiple>
|
||||
<span class="file-cta"><span class="file-icon">📁</span><span class="file-label">Select images…</span></span>
|
||||
</label>
|
||||
</div>
|
||||
<button class="button is-small is-link" type="submit">Create cards from images</button>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<form method="post" action="{% url 'cards:overview_bulk_update' %}">
|
||||
{% csrf_token %}
|
||||
<div class="table-container">
|
||||
|
||||