From f33a7705d188319e55c3de8f1f84dd880927bb98 Mon Sep 17 00:00:00 2001 From: Ross Date: Sat, 6 Dec 2025 18:36:14 +0000 Subject: [PATCH] . --- .../cards/_background_title_form.html | 20 +++++++++++ cards/templates/cards/_backgrounds_list.html | 1 + cards/urls.py | 1 + cards/views.py | 31 ++++++++++++++++++ db.sqlite3 | Bin 151552 -> 151552 bytes 5 files changed, 53 insertions(+) create mode 100644 cards/templates/cards/_background_title_form.html diff --git a/cards/templates/cards/_background_title_form.html b/cards/templates/cards/_background_title_form.html new file mode 100644 index 0000000..caddc76 --- /dev/null +++ b/cards/templates/cards/_background_title_form.html @@ -0,0 +1,20 @@ +
+
+
+ {% csrf_token %} +
+
+
+
+ {{ form.title }} +
+
+
Uploaded {{ bg.uploaded_at }}
+
+ + +
+
+
+
+
diff --git a/cards/templates/cards/_backgrounds_list.html b/cards/templates/cards/_backgrounds_list.html index d4690b1..6dec239 100644 --- a/cards/templates/cards/_backgrounds_list.html +++ b/cards/templates/cards/_backgrounds_list.html @@ -8,6 +8,7 @@ {{ bg.title }}
Uploaded {{ bg.uploaded_at }}
+ {% if not bg.is_active %} {% else %} diff --git a/cards/urls.py b/cards/urls.py index 75c397e..4c20092 100644 --- a/cards/urls.py +++ b/cards/urls.py @@ -11,6 +11,7 @@ urlpatterns = [ path('preview//', views.preview_card, name='preview'), path('backgrounds/', views.background_list, name='backgrounds'), path('backgrounds/create/', views.background_create, name='background_create'), + path('backgrounds//edit/', views.background_edit, name='background_edit'), path('backgrounds/download-all/', views.backgrounds_download_all, name='backgrounds_download_all'), path('backgrounds//activate/', views.background_activate, name='background_activate'), path('backgrounds//delete/', views.background_delete, name='background_delete'), diff --git a/cards/views.py b/cards/views.py index 8449c96..36bcf9b 100644 --- a/cards/views.py +++ b/cards/views.py @@ -241,6 +241,37 @@ def background_delete(request, pk): return redirect('cards:backgrounds') +def background_edit(request, pk): + """Edit an existing BackgroundImage's metadata (title, image, is_active). + + Designed to work with HTMX: GET returns a small edit form fragment which + replaces the background card. POST saves and returns the updated + backgrounds list fragment so the UI stays in sync. + """ + bg = get_object_or_404(BackgroundImage, pk=pk) + if request.method == 'POST': + form = BackgroundImageForm(request.POST, request.FILES, instance=bg) + if form.is_valid(): + bg = form.save() + # If marked active, unset others + if bg.is_active: + BackgroundImage.objects.exclude(pk=bg.pk).update(is_active=False) + if is_htmx(request): + list_html = render_to_string('cards/_backgrounds_list.html', {'backgrounds': BackgroundImage.objects.all(), 'form': BackgroundImageForm()}, request=request) + return HttpResponse(list_html) + return redirect('cards:backgrounds') + else: + if is_htmx(request): + form_html = render_to_string('cards/_background_title_form.html', {'bg': bg, 'form': form}, request=request) + return HttpResponse(form_html) + return render(request, 'cards/backgrounds_list.html', {'backgrounds': BackgroundImage.objects.all(), 'form': form}) + else: + form = BackgroundImageForm(instance=bg) + if is_htmx(request): + return render(request, 'cards/_background_title_form.html', {'bg': bg, 'form': form}) + return render(request, 'cards/backgrounds_list.html', {'backgrounds': BackgroundImage.objects.all(), 'form': form}) + + def preview_card(request, pk): """Render a full preview of a card. HTMX loads the modal fragment into #modal-root.""" card = get_object_or_404(Dinosaur, pk=pk) diff --git a/db.sqlite3 b/db.sqlite3 index 2e40566279697a57a15ea5922aa9a8eae89a67f9..2d79712cab6d622747ce848216b5370d3e1d2ee3 100644 GIT binary patch delta 397 zcmZozz}c{XbAmKu*F+g-#;(SM)&$0_2}}$5MR{K_u=B(*@Wk=^@xA0Z&8x*{!P~Q0 zQNe>pCYzCs!L*vg(JeDIC#6^+F)u}-EI%hXF)u&0c=~#Ira-<}7B&V+pbD?jy!4z@ zkeKrH<8n-Tf(fi_4Dvt;&*W5v9H2(9dgbYPK)LBXvP^L-d~+E5rZ13VQlBm=$D}Nr z#Ky*;T+Qj|l$w~Fp-`Nhng=xvD67Z9znsArq}W3=C7GFxK^16lP=0cDrGiUpacWTs z$X=D{itFqN?@0M+p^sLRUpIx{jdIyOcN@gwol*%>GE&9a<+)}6_Nk$1YN2a_iw L`}RB!rb+AoVqIon delta 272 zcmZozz}c{XbAmKu{X`jO#`?yD)&$0_2}}$5MHv_v*m-*x_?Pqh@qOi+!{^NVinnL8 zqCy$(^d4EJIHqv6=>hUgn$z>-nDm&!Ss|P_SrCT>!ucZu;xI!v3i3?tOyP_W&Rn33 z0vG>t25J6OM*frhyZA5jpW}bTf0zFT{}KNE{9E}q@UNaOr@$n?-Cltyho6OonSpWo zdVMBqK@m2f!$g?DBFsQ0=l0+FOl$(&9B~YSj9VD^71^7%^Efb-u?sXt3h^_j%gXaQ uGcqzdHl|MInPolwwmXx@bQKRKPXVA_0ac)^BO?=|BQHC{_B;=!N$dcDg+QDD