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 diff --git a/KeRS/urls.py b/KeRS/urls.py index 06c0f77..5407fb3 100644 --- a/KeRS/urls.py +++ b/KeRS/urls.py @@ -20,4 +20,5 @@ urlpatterns = [ path('', include('events.urls')), path('admin/', admin.site.urls), path('login/zeus/', include('oauth.urls')), + path('user/', include('users.urls')) ] 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 046f480..7036031 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-22 00:49 +# Generated by Django 3.0.8 on 2020-07-22 02:25 from django.conf import settings from django.db import migrations, models @@ -18,8 +18,9 @@ class Migration(migrations.Migration): name='Event', fields=[ ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('date', models.DateTimeField()), - ('capacity', models.IntegerField()), + ('date', models.DateField()), + ('time', models.IntegerField(choices=[(0, 'Voormiddag'), (1, 'Namiddag'), (2, 'Avond')], default=0)), + ('capacity', models.IntegerField(default=6)), ], ), migrations.CreateModel( @@ -27,8 +28,8 @@ class Migration(migrations.Migration): fields=[ ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), ('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)), + ('event', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='events.Event')), + ('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)), ], ), ] diff --git a/events/migrations/0002_auto_20200722_0101.py b/events/migrations/0002_auto_20200722_0101.py deleted file mode 100644 index ab3ddbc..0000000 --- a/events/migrations/0002_auto_20200722_0101.py +++ /dev/null @@ -1,23 +0,0 @@ -# Generated by Django 3.0.8 on 2020-07-22 01:01 - -from django.db import migrations - - -class Migration(migrations.Migration): - - dependencies = [ - ('events', '0001_initial'), - ] - - operations = [ - migrations.RenameField( - model_name='eventregistration', - old_name='event_id', - new_name='event', - ), - migrations.RenameField( - model_name='eventregistration', - old_name='user_id', - new_name='user', - ), - ] diff --git a/events/models.py b/events/models.py index 54cc830..6dceccb 100644 --- a/events/models.py +++ b/events/models.py @@ -4,19 +4,43 @@ 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]}" + + + @property + def time_str(self): + return 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 = models.ForeignKey(Event, on_delete=models.CASCADE) user = models.ForeignKey(CustomUser, on_delete=models.CASCADE) state = models.CharField(max_length=1, choices=REGISTRATION_STATE) def __str__(self): - return f'Reservation[{self.user.username}:{self.event.date}:{self.state}]' + return f"Reservation[{self.user.username}:{self.event.date}:{self.state}]" + + + @property + def state_str(self): + return self.TIME_SLOTS[self.time] 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 %} +
{{ username }}
+{% else %} +Not logged in
+ Login + {% endif %} + + diff --git a/users/urls.py b/users/urls.py new file mode 100644 index 0000000..88d0fbc --- /dev/null +++ b/users/urls.py @@ -0,0 +1,7 @@ +from django.urls import path + +from . import views + +urlpatterns = [ + path('profile', views.profile), +] diff --git a/users/views.py b/users/views.py new file mode 100644 index 0000000..693e1d4 --- /dev/null +++ b/users/views.py @@ -0,0 +1,6 @@ +from django.http import HttpResponse +from django.shortcuts import render + + +def profile(request): + return render(request, "profile.html", {"username": request.user.username})