register device form and view

This commit is contained in:
Tom Irgang 2023-04-18 21:13:30 +02:00
parent d074818447
commit 92354201af
5 changed files with 69 additions and 10 deletions

View file

@ -8,7 +8,8 @@
"Reparateure",
"reparateur_id",
"organisator_id",
"Reparateurs"
"Reparateurs",
"repapp"
],
"ignoreWords": [],
"import": []

View file

@ -7,7 +7,9 @@
<ul class="list-group">
{% for cafe in object_list %}
<li class="list-group-item">
<a href="{% url 'register_device' cafe.id %}">
<button type="button" class="btn btn-primary">Repair-Café am {{ cafe.event_date|date }}, {{ cafe.location }}</button>
</a>
</li>
{% empty %}
<li class="list-group-item">Es gibt keine geplanten Repair-Cafés.</li>

View file

@ -0,0 +1,30 @@
{% extends "repapp/base.html" %}
{% block title %}- Gerät anmelden{% endblock title %}
{% block content %}
<form action="{% url 'register_device' cafe.id %}" method="post">
{% csrf_token %}
<div class="mb-3">
<label for="email_address" class="form-label">eMail Adresse</label>
<input type="text" class="form-control" id="email_address" name="email_address" aria-describedby="email_help">
<div id="email_help" class="form-text">Diese eMail-Adresse wird für Aktualisierungen zur Anfrage verwendet.</div>
</div>
<div class="mb-3">
<label for="device" class="form-label">Gerätebezeichnung</label>
<input type="text" class="form-control" id="device" name="device" aria-describedby="device_help">
<div id="device_help" class="form-text">Bitte geben Sie den Hersteller und die Gerätebezeichnung an.</div>
</div>
<div class="mb-3">
<label for="issue" class="form-label">Fehlerbeschreibung</label>
<textarea rows="6" cols="60" class="form-control" id="issue" name="issue" aria-describedby="issue_help"></textarea>
<div id="issue_help" class="form-text">Beschreiben Sie hier das Problem ihres Gerätes.</div>
</div>
<div class="mb-3 form-check">
<input type="checkbox" class="form-check-input" id="follow_up" name="follow_up" aria-describedby="follow_up_help">
<label class="form-check-label" for="follow_up">Folgetermin</label>
<div id="follow_up_help" class="form-text">Klicken Sie dieses Kästchen an wenn sie mit diesem Gerät bereits bei einem Repair-Café waren.</div>
</div>
<button type="submit" class="btn btn-primary">Absenden</button>
</form>
{% endblock content %}

View file

@ -1,7 +1,11 @@
"""
Urls of RepApp.
"""
from django.urls import path
from . import views
urlpatterns = [
path("", views.IndexView.as_view(), name="index"),
path("<int:cafe_id>/", views.register_device, name="register_device"),
]

View file

@ -1,15 +1,37 @@
from django.shortcuts import render
from django.http import HttpResponse
"""
Views of RepApp.
"""
import datetime
from django.shortcuts import get_object_or_404, render
from django.http import HttpResponse, HttpResponseRedirect
from django.views import generic
from .models import Cafe
def index(request):
return HttpResponse("Hello from RepApp.")
from .models import Cafe, Guest, Device
class IndexView(generic.ListView):
"""
The IndexView lists all future Repair-Cafés.
"""
template_name = "repapp/index.html"
def get_queryset(self):
return Cafe.objects.all()
return Cafe.objects.filter(event_date__gte=datetime.date.today())
def register_device(request, cafe_id):
if request.method == "POST":
mail = request.POST.get('email_address', '')
device = request.POST.get('device', '')
issue = request.POST.get('issue', ''),
follow_up = request.POST.get('follow_up', 'false') == 'on'
return HttpResponse(f"{mail} {device} {issue} {follow_up}")
# return HttpResponseRedirect(reverse("polls:results", args=(question.id,)))
else:
cafe = get_object_or_404(Cafe, pk=cafe_id)
return render(
request,
"repapp/register_device.html",
{
"cafe": cafe,
},
)