Merge branch 'master' of ssh://git.zeus.gent:2222/bestuur/kers

This commit is contained in:
Francis 2020-07-22 04:32:49 +02:00
commit 5e6e2120cf
No known key found for this signature in database
GPG key ID: 071BEA4C2B10077C
18 changed files with 165 additions and 63 deletions

18
.editorconfig Normal file
View file

@ -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

View file

@ -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'))
]

View file

@ -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)

View file

@ -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)),
],
),
]

View file

@ -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',
),
]

View file

@ -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]

View file

@ -0,0 +1,10 @@
{% extends "base.html" %}
{% block content %}
<h2>{{ event.date }} (maximum {{ event.capacity }} mensen)</h2>
<ul>
{% for regi in event.registration %}
{{ regi.user.username }}: {{regi.state}}
{% endfor %}
</ul>
{% endblock %}

View file

@ -0,0 +1,19 @@
{% extends "base.html" %}
{% block content %}
<ul>
{% for event in events %}
<li id="{{event.id}}">{{ event.date }} {{ event.time_str }} (maximum {{ event.capacity }} mensen)
<ul>
<form action="{% url 'events:register' event.id %}" method="post">
{% csrf_token %}
{% for regi in event.registration %}
{{ regi.user.username }}: {{regi.state_str}}
{% endfor %}
<li><input type="submit" value="Ik wil komen"></li>
</form>
</ul>
</li>
{% endfor %}
</ul>
{% endblock %}

View file

@ -2,7 +2,9 @@ from django.urls import path
from . import views
app_name = "events"
urlpatterns = [
path('', views.index, name='index'),
path('test/', views.view_score_stuff, name='score_stuff'),
path("", views.index, name="index"),
path("<int:event_id>/", views.register, name="register"),
path("test/", views.view_score_stuff, name="score_stuff"),
]

View file

@ -1,17 +1,32 @@
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
from events.tasks import assign_reservations
def index(request):
return HttpResponse(
events = Event.objects.filter(date__gte=timezone.now().date()).order_by("date")[:20]
return render(request, "events/index.html", {"events": events})
)
def view_score_stuff(request):
return HttpResponse(
assign_reservations()
)
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") + f"#{event.id}")

View file

@ -40,7 +40,7 @@ def register_callback(req: HttpRequest):
raise OAuthException(f'username and id are expected values: {user}')
else:
logger.debug(f'Succesfully authenticated user: {user["username"]} with id: {user["id"]}')
validated_user = validate_user(user['zeus_id'], user['username'])
validated_user = validate_user(user['id'], user['username'])
login(req, validated_user)
redirect('/')
else:

View file

@ -2,12 +2,22 @@ amqp==2.6.0
asgiref==3.2.10
billiard==3.6.3.0
celery==4.4.6
certifi==2020.6.20
chardet==3.0.4
Django==3.0.8
django-celery-beat==2.0.0
django-timezone-field==4.0
future==0.18.2
idna==2.10
kombu==4.6.11
mysqlclient==2.0.1
python-crontab==2.5.1
python-dateutil==2.8.1
pytz==2020.1
PyYAML==5.3.1
redis==3.5.3
requests==2.24.0
six==1.15.0
sqlparse==0.3.1
urllib3==1.25.9
vine==1.3.0

12
templates/base.html Normal file
View file

@ -0,0 +1,12 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<meta name="viewport" content="width=device-width"/>
<title>Zeus WPI Kelderregistratiesysteem™</title>
</head>
<body>
<h1>Zeus WPI Kelderregistratiesysteem™</h1>
{% block content %}{% endblock %}
</body>
</html>

View file

@ -1,4 +1,4 @@
# Generated by Django 3.0.8 on 2020-07-21 22:48
# Generated by Django 3.0.8 on 2020-07-22 02:25
from django.db import migrations, models
import django.utils.timezone
@ -20,7 +20,7 @@ class Migration(migrations.Migration):
('password', models.CharField(max_length=128, verbose_name='password')),
('last_login', models.DateTimeField(blank=True, null=True, verbose_name='last login')),
('is_superuser', models.BooleanField(default=False, help_text='Designates that this user has all permissions without explicitly assigning them.', verbose_name='superuser status')),
('zeus_id', models.IntegerField()),
('zeus_id', models.IntegerField(null=True, unique=True)),
('is_staff', models.BooleanField(default=False)),
('username', models.CharField(max_length=50, unique=True)),
('student_number', models.CharField(max_length=255)),

View file

@ -1,18 +0,0 @@
# Generated by Django 3.0.8 on 2020-07-21 22:49
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('users', '0001_initial'),
]
operations = [
migrations.AlterField(
model_name='customuser',
name='zeus_id',
field=models.IntegerField(null=True, unique=True),
),
]

View file

@ -0,0 +1,15 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Profile</title>
</head>
<body>
{% if user.is_authenticated %}
<p>{{ username }}</p>
{% else %}
<p>Not logged in</p>
<a href="/login/zeus/register">Login</a>
{% endif %}
</body>
</html>

7
users/urls.py Normal file
View file

@ -0,0 +1,7 @@
from django.urls import path
from . import views
urlpatterns = [
path('profile', views.profile),
]

6
users/views.py Normal file
View file

@ -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})