From 7872e4f5b21a31c621320833bbd86caba272bfff Mon Sep 17 00:00:00 2001 From: Midgard Date: Tue, 21 Jul 2020 22:40:51 +0200 Subject: [PATCH 1/2] Add editorconfig --- .editorconfig | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 .editorconfig diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..912ad38 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,18 @@ +# https://editorconfig.org + +root = true + +[*] +charset = utf-8 +end_of_line = lf +insert_final_newline = true +indent_style = tab + +[*.py] +indent_style = space +indent_size = 4 + +# 2 spaces in YAML +[*.{yaml,yml}] +indent_style = space +indent_size = 2 From 313366413dbac4bd4a976599c605d04d27ae43ea Mon Sep 17 00:00:00 2001 From: Midgard Date: Wed, 22 Jul 2020 04:08:30 +0200 Subject: [PATCH 2/2] Start events frontend --- events/admin.py | 5 ++++- events/migrations/0001_initial.py | 7 ++++--- events/models.py | 26 +++++++++++++++++++++----- events/templates/events/detail.html | 10 ++++++++++ events/templates/events/index.html | 19 +++++++++++++++++++ events/urls.py | 4 +++- events/views.py | 24 ++++++++++++++++++++---- templates/base.html | 12 ++++++++++++ 8 files changed, 93 insertions(+), 14 deletions(-) create mode 100644 events/templates/events/detail.html create mode 100644 events/templates/events/index.html create mode 100644 templates/base.html diff --git a/events/admin.py b/events/admin.py index 8c38f3f..a1d2300 100644 --- a/events/admin.py +++ b/events/admin.py @@ -1,3 +1,6 @@ from django.contrib import admin -# Register your models here. +from .models import Event, EventRegistration + +admin.site.register(Event) +admin.site.register(EventRegistration) diff --git a/events/migrations/0001_initial.py b/events/migrations/0001_initial.py index f50a5f5..af3db1d 100644 --- a/events/migrations/0001_initial.py +++ b/events/migrations/0001_initial.py @@ -1,4 +1,4 @@ -# Generated by Django 3.0.8 on 2020-07-21 21:36 +# Generated by Django 3.0.8 on 2020-07-22 01:36 from django.conf import settings from django.db import migrations, models @@ -18,7 +18,8 @@ class Migration(migrations.Migration): name='Event', fields=[ ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('date', models.DateTimeField()), + ('date', models.DateField()), + ('time', models.IntegerField(choices=[(0, 'Voormiddag'), (1, 'Namiddag'), (2, 'Avond')])), ('capacity', models.IntegerField()), ], ), @@ -26,7 +27,7 @@ class Migration(migrations.Migration): name='EventRegistration', fields=[ ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('shirt_size', models.CharField(choices=[('I', 'Interested'), ('A', 'Admitted'), ('D', 'Denied')], max_length=1)), + ('state', models.CharField(choices=[('I', 'Interested'), ('A', 'Admitted'), ('D', 'Denied')], max_length=1)), ('event_id', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='events.Event')), ('user_id', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)), ], diff --git a/events/models.py b/events/models.py index b030d7f..f5c353a 100644 --- a/events/models.py +++ b/events/models.py @@ -4,16 +4,32 @@ from users.models import CustomUser class Event(models.Model): - date = models.DateTimeField() - capacity = models.IntegerField() + MORNING, AFTERNOON, EVENING = range(3) + TIME_SLOTS = { + MORNING: "Voormiddag", + AFTERNOON: "Namiddag", + EVENING: "Avond", + } + date = models.DateField() + time = models.IntegerField(choices=TIME_SLOTS.items(), default=MORNING) + capacity = models.IntegerField(default=6) + + def __str__(self): + return f"{self.date} {self.TIME_SLOTS[self.time]}" class EventRegistration(models.Model): + INTERESTED = "I" + ADMITTED = "A" + DENIED = "D" REGISTRATION_STATE = ( - ('I', 'Interested'), - ('A', 'Admitted'), - ('D', 'Denied'), + (INTERESTED, "Interested"), + (ADMITTED, "Admitted"), + (DENIED, "Denied"), ) event_id = models.ForeignKey(Event, on_delete=models.CASCADE) user_id = models.ForeignKey(CustomUser, on_delete=models.CASCADE) state = models.CharField(max_length=1, choices=REGISTRATION_STATE) + + def __str__(self): + return f"[{self.state}] {self.user.username}" diff --git a/events/templates/events/detail.html b/events/templates/events/detail.html new file mode 100644 index 0000000..1a144a8 --- /dev/null +++ b/events/templates/events/detail.html @@ -0,0 +1,10 @@ +{% extends "base.html" %} + +{% block content %} +

{{ event.date }} (maximum {{ event.capacity }} mensen)

+ +{% endblock %} diff --git a/events/templates/events/index.html b/events/templates/events/index.html new file mode 100644 index 0000000..2a03009 --- /dev/null +++ b/events/templates/events/index.html @@ -0,0 +1,19 @@ +{% extends "base.html" %} + +{% block content %} + +{% endblock %} diff --git a/events/urls.py b/events/urls.py index 88a9cac..030a579 100644 --- a/events/urls.py +++ b/events/urls.py @@ -2,6 +2,8 @@ from django.urls import path from . import views +app_name = "events" urlpatterns = [ - path('', views.index, name='index'), + path("", views.index, name="index"), + path("/", views.register, name="register"), ] diff --git a/events/views.py b/events/views.py index 769a8a0..89da8a9 100644 --- a/events/views.py +++ b/events/views.py @@ -1,8 +1,24 @@ -from django.shortcuts import render +from django.http import HttpResponseRedirect +from django.shortcuts import render, get_object_or_404 +from django.utils import timezone +from django.urls import reverse +import datetime -# Create your views here. -from django.http import HttpResponse +from .models import Event, EventRegistration, CustomUser def index(request): - return HttpResponse("Hello, world. You're at the polls index.") + events = Event.objects.filter(date__gte=timezone.now().date()).order_by("date")[:20] + return render(request, "events/index.html", {"events": events}) + + +def register(request, event_id): + if request.method == "POST": + event = get_object_or_404(Event, id=event_id) + + # registration = Event.entry_set.create( + # state=EventRegistration.INTERESTED, + # event=event, + # user=CustomUser.objects.get(), + # ) + return HttpResponseRedirect(reverse("events:index", args=(event.id,))) diff --git a/templates/base.html b/templates/base.html new file mode 100644 index 0000000..1babc4b --- /dev/null +++ b/templates/base.html @@ -0,0 +1,12 @@ + + + + + + Zeus WPI Kelderregistratiesysteemâ„¢ + + +

Zeus WPI Kelderregistratiesysteemâ„¢

+ {% block content %}{% endblock %} + +