Skip to content

Commit

Permalink
H: Display form instead of text details
Browse files Browse the repository at this point in the history
  • Loading branch information
hmpf committed Jan 10, 2025
1 parent 890d4ed commit 1480f56
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 50 deletions.
14 changes: 12 additions & 2 deletions src/argus/htmx/notificationprofile/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"""

from django import forms
from django.shortcuts import redirect
from django.urls import reverse
from django.views.generic import CreateView, DeleteView, DetailView, ListView, UpdateView

Expand Down Expand Up @@ -78,11 +79,20 @@ def form_valid(self, form):


class NotificationProfileListView(NotificationProfileMixin, ListView):
pass
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
forms = []
for obj in self.get_queryset():
form = NotificationProfileForm(None, user=self.request.user, instance=obj)
forms.append(form)
context["form_list"] = forms
return context


class NotificationProfileDetailView(NotificationProfileMixin, DetailView):
pass
def dispatch(self, request, *args, **kwargs):
object = self.get_object()
return redirect("htmx:notificationprofile-update", pk=object.pk)


class NotificationProfileCreateView(ChangeMixin, NotificationProfileMixin, CreateView):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,5 @@
<div style="border: 2px solid pink"
class="card-actions justify-end"
>
{% if show_view %}
<button class="contents">
<a class="btn btn-primary"
href="{% url "htmx:notificationprofile-detail" pk=object.pk %}">View</a>
</button>
{% endif %}
<button class="contents">
<a class="btn btn-primary"
href="{% url "htmx:notificationprofile-update" pk=object.pk %}">Update</a>
</button>
<div style="border: 2px solid pink" class="card-actions justify-end">
<input class="btn btn-primary" type="submit" value="Save">
<button class="contents">
<a class="btn btn-primary"
href="{% url "htmx:notificationprofile-delete" pk=object.pk %}">Delete</a>
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<section class="card-body">
<form method="post"
action="{% url "htmx:notificationprofile-update" pk=form.instance.pk %}"
class="flex flex-row gap-4">
{% csrf_token %}
{{ form.as_div }}
{% include "./_notificationprofile_buttons.html" with object=form.instance %}
</form>
</section>

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
{% extends "./base.html" %}
{% block profile_main %}
<form method="post" class="flex flex-row gap-4">
{% csrf_token %}
{{ form.as_div }}
<input class="btn btn-primary" type="submit" value="Save">
</form>
<section class="card my-4 bg-base-100 glass shadow-2xl">
{% include "./_notificationprofile_form.html" %}
</section>
{% endblock profile_main %}
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
<a class="btn btn-primary"
href="{% url "htmx:notificationprofile-create" %}">Create new profile</a>
</button>
{% for object in object_list %}
<div class="card my-4 bg-base-100 glass shadow-2xl">{% include "./_notificationprofile_detail.html" with show_view=True %}</div>
{% for form in form_list %}
<div class="card my-4 bg-base-100 glass shadow-2xl">{% include "./_notificationprofile_form.html" %}</div>
{% endfor %}
</div>
{% endblock profile_main %}

0 comments on commit 1480f56

Please sign in to comment.