Oh no this is becoming too decent to be a Zeus project

This commit is contained in:
Midgard 2020-07-22 18:19:42 +02:00
parent f74cfc0352
commit ccb24d27e3
Signed by: midgard
GPG key ID: 511C112F1331BBB4
11 changed files with 58 additions and 52 deletions

View file

@ -1,6 +1,5 @@
# Generated by Django 3.0.8 on 2020-07-22 13:42
# Generated by Django 3.0.8 on 2020-07-22 16:03
from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion
@ -10,7 +9,6 @@ class Migration(migrations.Migration):
initial = True
dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
]
operations = [
@ -19,7 +17,7 @@ class Migration(migrations.Migration):
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('date', models.DateField()),
('time', models.IntegerField(choices=[(0, 'Voormiddag'), (1, 'Namiddag'), (2, 'Avond')], default=0)),
('time', models.IntegerField(choices=[(0, 'voormiddag'), (1, 'namiddag'), (2, 'avond')], default=0)),
('capacity', models.IntegerField(default=6)),
],
),
@ -27,13 +25,8 @@ class Migration(migrations.Migration):
name='EventRegistration',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('state', models.CharField(choices=[('I', 'Interested'), ('A', 'Admitted')], max_length=1)),
('state', models.CharField(choices=[('I', 'op wachtlijst'), ('A', 'bevestigd')], max_length=1)),
('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)),
],
),
migrations.AddConstraint(
model_name='eventregistration',
constraint=models.UniqueConstraint(fields=('event', 'user'), name='user can only register once per event'),
),
]

View file

@ -0,0 +1,27 @@
# Generated by Django 3.0.8 on 2020-07-22 16:03
from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
initial = True
dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
('events', '0001_initial'),
]
operations = [
migrations.AddField(
model_name='eventregistration',
name='user',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL),
),
migrations.AddConstraint(
model_name='eventregistration',
constraint=models.UniqueConstraint(fields=('event', 'user'), name='register_only_once'),
),
]

View file

@ -1,4 +1,5 @@
from django.db import models
from django.db.models import Q
from users.models import CustomUser
@ -61,8 +62,8 @@ class EventRegistration(models.Model):
class Meta:
constraints = [
models.UniqueConstraint(
fields=["event", "user"], name="user can only register once per event"
)
fields=["event", "user"], name="register_only_once"
),
]

View file

@ -3,6 +3,9 @@
{% block title %}Events{% endblock %}
{% block content %}
<h2>Events</h2>
{% if events %}
<ul>
{% for x in events %}
<li id="{{x.event.id}}">{{ x.event.date|date:"d F Y" }}, {{ x.event.time_str }}
@ -10,4 +13,7 @@
</li>
{% endfor %}
</ul>
{% else %}
<p>Geen events binnenkort</p>
{% endif %}
{% endblock %}

View file

@ -6,13 +6,13 @@
<p>{{ event.count_interested }} in wachtlijst</p>
{% endif %}
{% if user.is_authenticated %}
{% if not my_registration %}
<p><input type="submit" value="Ik wil komen"></p>
{% else %}
<p>Mijn status: {{ my_registration.state_str }} <input type="button" disabled="disabled" value="Uitschrijven (todo)"></input></p>
{% endif %}
{% if not user.is_authenticated %}
<p>Je moet inloggen voor je je kan inschrijven.</p>
{% elif not user.has_ugent_info %}
<p>Je moet je studentennummer en echte naam invullen in je profiel voor je je kan inschrijven.</p>
{% elif not my_registration %}
<p><input type="submit" value="Ik wil komen"></p>
{% else %}
<p>Je moet inloggen voor je je kan inschrijven</p>
<p>Mijn status: {{ my_registration.state_str }} <input type="button" disabled="disabled" value="Uitschrijven (todo)"></input></p>
{% endif %}
</form>

View file

@ -28,6 +28,9 @@ def view_score_stuff(request):
def register(request, event_id):
if request.method == "POST":
if not request.user.has_ugent_info:
raise ValueError("User has missing UGent info missing")
event = get_object_or_404(Event, id=event_id)
event.eventregistration_set.create(

View file

@ -48,14 +48,10 @@ nav a {
font-family: monospace;
}
nav a:hover, nav a:focus, nav button:hover, nav buttton:focus {
nav a:hover, nav a:focus {
background-color: rgba(255, 255, 255, 0.5);
}
button {
display: none;
}
/*change the layout of the navigation bar for all the screens
that have a width less or equal than 500px*/
@ -68,17 +64,6 @@ that have a width less or equal than 500px*/
nav a {
display: block;
}
button {
display: block;
padding: 2vw;
font-size: 3vh;
background-color: #ff8000;
border: none;
cursor: pointer;
}
}
@media only screen and (min-width: 750px) {

View file

@ -14,7 +14,6 @@
<h1 class="align">Zeus WPI Kelder&shy;registratie&shy;systeem™</h1>
<nav>
<div class="align">
<button id="nav-button"></button>
<ul class="alignLeft">
<li>
<a href="{% url 'events:index' %}">
@ -54,17 +53,5 @@
<main class="align">
{% block content %}{% endblock %}
</main>
<script>
document.addEventListener("DOMContentLoaded", function () {
let button = document.getElementById('nav-button')
button.addEventListener('click', () => {
if (button.innerText === "☰") {
button.innerText = "✖";
} else {
button.innerText = "☰";
}
})
});
</script>
</body>
</html>

View file

@ -1,4 +1,4 @@
# Generated by Django 3.0.8 on 2020-07-22 02:25
# Generated by Django 3.0.8 on 2020-07-22 16:03
from django.db import migrations, models
import django.utils.timezone

View file

@ -10,8 +10,8 @@ class CustomUser(AbstractBaseUser, PermissionsMixin):
zeus_id = models.IntegerField(unique=True, null=True)
is_staff = models.BooleanField(default=False)
username = models.CharField(max_length=50, unique=True) # zeus username
student_number = models.CharField(max_length=255)
real_name = models.CharField(max_length=100)
student_number = models.CharField(max_length=255, verbose_name="Studentennummer")
real_name = models.CharField(max_length=100, verbose_name="Echte naam")
date_joined = models.DateTimeField(default=timezone.now)
@ -22,3 +22,7 @@ class CustomUser(AbstractBaseUser, PermissionsMixin):
def __str__(self):
return self.username
@property
def has_ugent_info(self):
return self.real_name and self.student_number

View file

@ -3,7 +3,7 @@
{% block title %}Profiel{% endblock %}
{% block content %}
<h1>Profiel</h1>
<h2>Profiel</h2>
{% if user.is_authenticated %}
<p>Gebruikersnaam: {{ user.username }}</p>