Skip to content

Commit

Permalink
Feedback form working, update Navbar
Browse files Browse the repository at this point in the history
  • Loading branch information
leethobbit committed Nov 5, 2024
1 parent 693b346 commit 7651504
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 26 deletions.
8 changes: 7 additions & 1 deletion config/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,13 +256,19 @@
},
},
"handlers": {
"file": {
"level": "DEBUG",
"class": "logging.FileHandler",
"filename": "debug.log",
"formatter": "verbose",
},
"console": {
"level": "DEBUG",
"class": "logging.StreamHandler",
"formatter": "verbose",
},
},
"root": {"level": "INFO", "handlers": ["console"]},
"root": {"level": "DEBUG", "handlers": ["console", "file"]},
}


Expand Down
9 changes: 9 additions & 0 deletions dragonroost/business/forms.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from django import forms

from .models import Feedback


class FeedbackForm(forms.ModelForm):
class Meta:
model = Feedback
fields = ["name", "email_address", "feedback_type", "feedback"]
14 changes: 14 additions & 0 deletions dragonroost/business/views.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import logging

from django.contrib.auth.mixins import LoginRequiredMixin
from django.http import HttpResponse
from django.shortcuts import render
from django.urls import reverse_lazy
from django.views.generic import DetailView
from django.views.generic import ListView
Expand All @@ -9,12 +13,15 @@

from dragonroost.mixins import PageTitleViewMixin

from .forms import FeedbackForm
from .models import Feedback
from .models import Location
from .models import Meeting
from .tables import LocationListTable
from .tables import MeetingListTable

logger = logging.getLogger(__name__)


# Create your views here.
class LocationListView(
Expand Down Expand Up @@ -123,3 +130,10 @@ class FeedbackCreateView(LoginRequiredMixin, PageTitleViewMixin, CreateView):
title = "Submit Feedback"
template_name = "business/feedback_form.html"
fields = ("name", "email_address", "feedback_type", "feedback")

def post(self, request, *args, **kwargs):
form = FeedbackForm(request.POST)
if form.is_valid():
form.save()
return HttpResponse(status=204)
return render(request, "business/feedback_form.html", {"form": form})
13 changes: 8 additions & 5 deletions dragonroost/static/js/project.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,26 @@

/* Code from https://blog.benoitblanchon.fr/django-htmx-modal-form/
to help with doing forms inside of modals */
const modal = new bootstrap.Modal(document.getElementById("modal"))
; (function () {
const modal = new bootstrap.Modal(document.getElementById("modal"))

htmx.on("htmx:afterSwap", (e) => {
htmx.on("htmx:afterSwap", (e) => {
// Response targeting #dialog => show the modal
if (e.detail.target.id == "dialog") {
modal.show()
modal.show()
}
})
})

htmx.on("htmx:beforeSwap", (e) => {
htmx.on("htmx:beforeSwap", (e) => {
// Empty response targeting #dialog => hide the modal
if (e.detail.target.id == "dialog" && !e.detail.xhr.response) {
modal.hide()
e.detail.shouldSwap = false
}
})

// Remove dialog content after hiding
htmx.on("hidden.bs.modal", () => {
document.getElementById("dialog").innerHTML = ""
})
})()
20 changes: 4 additions & 16 deletions dragonroost/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
hx-headers='{"X-CSRFToken": "{{ csrf_token }}"}'>
{% block body %}
<div class="mb-2">
<nav class="navbar navbar-expand-md bg-primary" data-bs-theme="dark">
<nav class="navbar navbar-expand-lg bg-primary" data-bs-theme="dark">
<div class="container-fluid">
<button class="navbar-toggler navbar-toggler-right"
type="button"
Expand All @@ -59,21 +59,9 @@
</button>
<a class="navbar-brand" href="{% url 'home' %}">Dragonroost</a>
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav mr-auto">
<li class="nav-item active">
<a class="nav-link" href="{% url 'home' %}">Home <span class="visually-hidden">(current)</span></a>
</li>
<li class="nav-item">
<a class="nav-link" href="{% url 'home' %}">Animals</a>
</li>
<li class="nav-item">
<a class="nav-link" href="admin/">Admin</a>
</li>
<li class="nav-item">
<a class="nav-link" href="{% url 'home' %}">Medical</a>
</li>
<ul class="navbar-nav ms-auto">
<li class="nav-item">
<a class="nav-link" href="{% url 'home' %}">People</a>
<a class="nav-link" href="{% url 'admin:index' %}">Admin</a>
</li>
<li class="nav-item">
<a class="nav-link" href="{% url 'about' %}">About</a>
Expand Down Expand Up @@ -104,7 +92,7 @@
</div>
</nav>
</div>
<div class="d-flex flex-nowrap h-100" >
<div class="d-flex flex-nowrap" >
<div class="d-flex flex-column flex-shrink-0 p-3 rounded border bg-info-subtle">
<h2 class="mb-3 mb-md-0 text-center display-6">
<span class="fs-2 text-bold">Shelter Actions</span>
Expand Down
9 changes: 5 additions & 4 deletions dragonroost/templates/business/feedback_form.html
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
<form hx-post="{{ request.path }}" class="modal-content">
{% csrf_token %}
<form hx-post="{{ request.path }}"
hx-headers='{"X-CSRFToken":"{{ csrf_token }}"}'
class="modal-content">
<div class="modal-header">
<h5 class="modal-title">New Feedback</h5>
</div>
<div class="modal-body">{{ form.as_p }}</div>
<div class="modal-footer">
<button type="button" data-bs-dismiss="modal">Cancel</button>
<button type="submit">Save</button>
<button class="btn btn-primary" type="submit">Save</button>
<button class="btn btn-outline-danger" type="button" data-bs-dismiss="modal">Cancel</button>
</div>
</form>

0 comments on commit 7651504

Please sign in to comment.