black formatting
This commit is contained in:
parent
d041914c0f
commit
ff481a41c1
|
@ -4,16 +4,21 @@ from .models import Room, Shift, Helper, ShiftRegistration, Message, LoginToken
|
|||
|
||||
admin.site.register(Room)
|
||||
|
||||
|
||||
@admin.register(Shift)
|
||||
class ShiftAdmin(admin.ModelAdmin):
|
||||
list_display = ('room_name', 'start_at', 'free_slots')
|
||||
list_display = ("room_name", "start_at", "free_slots")
|
||||
|
||||
def room_name(self, object):
|
||||
return object.room.name
|
||||
#def helpers(self, object):
|
||||
|
||||
# def helpers(self, object):
|
||||
# object.helpers.count()
|
||||
def free_slots(self, object):
|
||||
return object.room.required_helpers - object.shiftregistration_set.count()
|
||||
#admin.site.register(Shift)
|
||||
return object.room.required_helpers - object.shiftregistration_set.count()
|
||||
|
||||
|
||||
# admin.site.register(Shift)
|
||||
|
||||
|
||||
admin.site.register(Helper)
|
||||
|
|
|
@ -2,5 +2,5 @@ from django.apps import AppConfig
|
|||
|
||||
|
||||
class AppConfig(AppConfig):
|
||||
default_auto_field = 'django.db.models.BigAutoField'
|
||||
name = 'shiftregister.app'
|
||||
default_auto_field = "django.db.models.BigAutoField"
|
||||
name = "shiftregister.app"
|
||||
|
|
|
@ -1,11 +1,16 @@
|
|||
from django import forms
|
||||
from .models import Helper
|
||||
|
||||
|
||||
class RegisterForm(forms.Form):
|
||||
name = forms.CharField(max_length=Helper.name.field.max_length, label="Name")
|
||||
name = forms.CharField(max_length=Helper.name.field.max_length, label="Name")
|
||||
# actually verify phone number, lol
|
||||
phone = forms.CharField(max_length=Helper.phone.field.max_length, label='Handynummer für Benachrichtigungen')
|
||||
okf = forms.BooleanField(label='Ich möchte SMS erhalten')
|
||||
phone = forms.CharField(
|
||||
max_length=Helper.phone.field.max_length,
|
||||
label="Handynummer für Benachrichtigungen",
|
||||
)
|
||||
okf = forms.BooleanField(label="Ich möchte SMS erhalten")
|
||||
|
||||
|
||||
# placeholder form for simple submit button use cases so we get csrf protection
|
||||
class EmptyForm(forms.Form):
|
||||
|
|
|
@ -9,58 +9,121 @@ class Migration(migrations.Migration):
|
|||
|
||||
initial = True
|
||||
|
||||
dependencies = [
|
||||
]
|
||||
dependencies = []
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='Helper',
|
||||
name="Helper",
|
||||
fields=[
|
||||
('phone', models.CharField(max_length=200, primary_key=True, serialize=False)),
|
||||
('name', models.CharField(max_length=200)),
|
||||
('number_validated', models.BooleanField(default=False)),
|
||||
(
|
||||
"phone",
|
||||
models.CharField(max_length=200, primary_key=True, serialize=False),
|
||||
),
|
||||
("name", models.CharField(max_length=200)),
|
||||
("number_validated", models.BooleanField(default=False)),
|
||||
],
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='Room',
|
||||
name="Room",
|
||||
fields=[
|
||||
('name', models.CharField(max_length=200, primary_key=True, serialize=False)),
|
||||
('required_helpers', models.IntegerField()),
|
||||
(
|
||||
"name",
|
||||
models.CharField(max_length=200, primary_key=True, serialize=False),
|
||||
),
|
||||
("required_helpers", models.IntegerField()),
|
||||
],
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='Shift',
|
||||
name="Shift",
|
||||
fields=[
|
||||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('start_at', models.DateTimeField()),
|
||||
('duration', models.DurationField()),
|
||||
('room', models.ForeignKey(on_delete=django.db.models.deletion.RESTRICT, to='app.room')),
|
||||
(
|
||||
"id",
|
||||
models.BigAutoField(
|
||||
auto_created=True,
|
||||
primary_key=True,
|
||||
serialize=False,
|
||||
verbose_name="ID",
|
||||
),
|
||||
),
|
||||
("start_at", models.DateTimeField()),
|
||||
("duration", models.DurationField()),
|
||||
(
|
||||
"room",
|
||||
models.ForeignKey(
|
||||
on_delete=django.db.models.deletion.RESTRICT, to="app.room"
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='Message',
|
||||
name="Message",
|
||||
fields=[
|
||||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('text', models.CharField(max_length=160)),
|
||||
('to', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='app.helper')),
|
||||
(
|
||||
"id",
|
||||
models.BigAutoField(
|
||||
auto_created=True,
|
||||
primary_key=True,
|
||||
serialize=False,
|
||||
verbose_name="ID",
|
||||
),
|
||||
),
|
||||
("text", models.CharField(max_length=160)),
|
||||
(
|
||||
"to",
|
||||
models.ForeignKey(
|
||||
on_delete=django.db.models.deletion.CASCADE, to="app.helper"
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='LoginToken',
|
||||
name="LoginToken",
|
||||
fields=[
|
||||
('id', models.CharField(default=shiftregister.app.models.gen_token, editable=False, max_length=20, primary_key=True, serialize=False)),
|
||||
('helper', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='app.helper')),
|
||||
(
|
||||
"id",
|
||||
models.CharField(
|
||||
default=shiftregister.app.models.gen_token,
|
||||
editable=False,
|
||||
max_length=20,
|
||||
primary_key=True,
|
||||
serialize=False,
|
||||
),
|
||||
),
|
||||
(
|
||||
"helper",
|
||||
models.ForeignKey(
|
||||
on_delete=django.db.models.deletion.CASCADE, to="app.helper"
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='ShiftRegistration',
|
||||
name="ShiftRegistration",
|
||||
fields=[
|
||||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('helper', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='app.helper')),
|
||||
('shift', models.ForeignKey(on_delete=django.db.models.deletion.RESTRICT, to='app.shift')),
|
||||
(
|
||||
"id",
|
||||
models.BigAutoField(
|
||||
auto_created=True,
|
||||
primary_key=True,
|
||||
serialize=False,
|
||||
verbose_name="ID",
|
||||
),
|
||||
),
|
||||
(
|
||||
"helper",
|
||||
models.ForeignKey(
|
||||
on_delete=django.db.models.deletion.CASCADE, to="app.helper"
|
||||
),
|
||||
),
|
||||
(
|
||||
"shift",
|
||||
models.ForeignKey(
|
||||
on_delete=django.db.models.deletion.RESTRICT, to="app.shift"
|
||||
),
|
||||
),
|
||||
],
|
||||
options={
|
||||
'unique_together': {('shift', 'helper')},
|
||||
"unique_together": {("shift", "helper")},
|
||||
},
|
||||
),
|
||||
]
|
||||
|
|
|
@ -4,12 +4,15 @@ from django.shortcuts import reverse
|
|||
from datetime import timedelta
|
||||
from django.utils import timezone
|
||||
|
||||
|
||||
class Room(models.Model):
|
||||
name = models.CharField(max_length=200, primary_key=True)
|
||||
required_helpers = models.IntegerField()
|
||||
|
||||
def __str__(self):
|
||||
return self.name
|
||||
|
||||
|
||||
class Shift(models.Model):
|
||||
room = models.ForeignKey(Room, on_delete=models.RESTRICT)
|
||||
start_at = models.DateTimeField()
|
||||
|
@ -18,14 +21,17 @@ class Shift(models.Model):
|
|||
def __str__(self):
|
||||
return f"{self.room.name}: {self.start_at}"
|
||||
|
||||
|
||||
class Helper(models.Model):
|
||||
# todo: add propper phone number validation, maybe even country code?
|
||||
phone = models.CharField(max_length=200, primary_key=True)
|
||||
name = models.CharField(max_length=200)
|
||||
# change this to a generic state variable to allow for number blocking/account deactivation?
|
||||
number_validated = models.BooleanField(default=False)
|
||||
|
||||
def __str__(self):
|
||||
return self.name
|
||||
|
||||
def send_confirmation(self):
|
||||
(token, created) = LoginToken.objects.get_or_create(helper=self)
|
||||
text = f"Hallo {self.name}, hier ist dein Registrierungslink zum Kontaktfestival http://short.url{token.get_absolute_url()}"
|
||||
|
@ -33,27 +39,37 @@ class Helper(models.Model):
|
|||
msg.save()
|
||||
return token
|
||||
|
||||
|
||||
class ShiftRegistration(models.Model):
|
||||
class Meta:
|
||||
unique_together = (('shift', 'helper'),)
|
||||
unique_together = (("shift", "helper"),)
|
||||
|
||||
# use restrict for now as Model.delete is not called
|
||||
shift = models.ForeignKey(Shift, on_delete=models.RESTRICT)
|
||||
helper = models.ForeignKey(Helper, on_delete=models.CASCADE)
|
||||
|
||||
def can_cancel(self):
|
||||
return self.shift.start_at>(timezone.now()+timedelta(hours=4))
|
||||
return self.shift.start_at > (timezone.now() + timedelta(hours=4))
|
||||
|
||||
|
||||
class Message(models.Model):
|
||||
# remove limit and send long messages in multiple messages?
|
||||
text = models.CharField(max_length=160)
|
||||
to = models.ForeignKey(Helper, on_delete=models.CASCADE)
|
||||
|
||||
def __str__(self):
|
||||
return f"{self.to.name}: {self.text}"
|
||||
|
||||
|
||||
def gen_token():
|
||||
return secrets.token_urlsafe(20)
|
||||
|
||||
|
||||
class LoginToken(models.Model):
|
||||
id = models.CharField(max_length=20, primary_key=True, default=gen_token, editable=False)
|
||||
id = models.CharField(
|
||||
max_length=20, primary_key=True, default=gen_token, editable=False
|
||||
)
|
||||
helper = models.ForeignKey(Helper, on_delete=models.CASCADE)
|
||||
|
||||
def get_absolute_url(self):
|
||||
return reverse('token_login', kwargs={'token':self.id})
|
||||
return reverse("token_login", kwargs={"token": self.id})
|
||||
|
|
|
@ -3,10 +3,10 @@ from django.urls import path
|
|||
from . import views
|
||||
|
||||
urlpatterns = [
|
||||
path('', views.index, name='index'),
|
||||
path('login/<slug:token>', views.login, name='token_login'),
|
||||
path('logout', views.logout, name='token_logout'),
|
||||
path('register', views.register, name='register'),
|
||||
path('shift/<int:shiftid>', views.shift, name='shift'),
|
||||
path('shift/<int:shiftid>/cancel', views.cancel, name='cancel'),
|
||||
path("", views.index, name="index"),
|
||||
path("login/<slug:token>", views.login, name="token_login"),
|
||||
path("logout", views.logout, name="token_logout"),
|
||||
path("register", views.register, name="register"),
|
||||
path("shift/<int:shiftid>", views.shift, name="shift"),
|
||||
path("shift/<int:shiftid>/cancel", views.cancel, name="cancel"),
|
||||
]
|
||||
|
|
|
@ -5,105 +5,139 @@ from .forms import RegisterForm, EmptyForm
|
|||
from django.db.models.fields import DateTimeField
|
||||
from django.utils import timezone
|
||||
|
||||
|
||||
def index(request):
|
||||
if request.session.get('last_seen_shift'):
|
||||
del request.session['last_seen_shift']
|
||||
if request.session.get("last_seen_shift"):
|
||||
del request.session["last_seen_shift"]
|
||||
# dont show shifts starting in <60 minutes?
|
||||
# currently only sorts by date
|
||||
context = {}
|
||||
helper = None
|
||||
if request.session.get('token'):
|
||||
helper = LoginToken.objects.get(pk=request.session['token']).helper
|
||||
context['helper'] = helper
|
||||
context['my_shifts'] = helper.shiftregistration_set.filter(shift__start_at__gt=timezone.now()).order_by('shift__start_at')
|
||||
context['current_shift'] = next(iter(helper.shiftregistration_set.annotate(shift_end=ExpressionWrapper(F('shift__start_at')+F('shift__duration'), output_field=DateTimeField())).filter(shift__start_at__lte=timezone.now(), shift_end__gte=timezone.now()).order_by('shift__start_at')[:1]), None)
|
||||
free_shifts = Shift.objects.annotate(reg_count=Count('shiftregistration')).filter(start_at__gt=timezone.now(),
|
||||
room__required_helpers__gt=F('reg_count')).order_by('start_at')
|
||||
if request.session.get("token"):
|
||||
helper = LoginToken.objects.get(pk=request.session["token"]).helper
|
||||
context["helper"] = helper
|
||||
context["my_shifts"] = helper.shiftregistration_set.filter(
|
||||
shift__start_at__gt=timezone.now()
|
||||
).order_by("shift__start_at")
|
||||
context["current_shift"] = next(
|
||||
iter(
|
||||
helper.shiftregistration_set.annotate(
|
||||
shift_end=ExpressionWrapper(
|
||||
F("shift__start_at") + F("shift__duration"),
|
||||
output_field=DateTimeField(),
|
||||
)
|
||||
)
|
||||
.filter(
|
||||
shift__start_at__lte=timezone.now(), shift_end__gte=timezone.now()
|
||||
)
|
||||
.order_by("shift__start_at")[:1]
|
||||
),
|
||||
None,
|
||||
)
|
||||
free_shifts = (
|
||||
Shift.objects.annotate(reg_count=Count("shiftregistration"))
|
||||
.filter(start_at__gt=timezone.now(), room__required_helpers__gt=F("reg_count"))
|
||||
.order_by("start_at")
|
||||
)
|
||||
if helper:
|
||||
free_shifts = Shift.objects.annotate(reg_count=Count('shiftregistration')).filter(start_at__gt=timezone.now(),
|
||||
room__required_helpers__gt=F('reg_count')).filter( ~Q(shiftregistration__helper=helper)).order_by('start_at')
|
||||
context['free_shifts']= free_shifts
|
||||
return render(request, 'shiftlist.html', context)
|
||||
free_shifts = (
|
||||
Shift.objects.annotate(reg_count=Count("shiftregistration"))
|
||||
.filter(
|
||||
start_at__gt=timezone.now(), room__required_helpers__gt=F("reg_count")
|
||||
)
|
||||
.filter(~Q(shiftregistration__helper=helper))
|
||||
.order_by("start_at")
|
||||
)
|
||||
context["free_shifts"] = free_shifts
|
||||
return render(request, "shiftlist.html", context)
|
||||
|
||||
|
||||
def login(request, token):
|
||||
tk = get_object_or_404(LoginToken,pk=token)
|
||||
tk = get_object_or_404(LoginToken, pk=token)
|
||||
if not tk.helper.number_validated:
|
||||
tk.helper.number_validated=True
|
||||
tk.helper.number_validated = True
|
||||
tk.helper.save()
|
||||
request.session['token'] = token
|
||||
# if the user was viewing a single shift before registering, they probably want to register for that
|
||||
request.session["token"] = token
|
||||
# if the user was viewing a single shift before registering, they probably want to register for that
|
||||
# shift so we redirect them there.
|
||||
if request.session.get('last_seen_shift'):
|
||||
return redirect('shift', shiftid=request.session['last_seen_shift'])
|
||||
return redirect('index')
|
||||
if request.session.get("last_seen_shift"):
|
||||
return redirect("shift", shiftid=request.session["last_seen_shift"])
|
||||
return redirect("index")
|
||||
|
||||
|
||||
def logout(request):
|
||||
if request.session.get('token'):
|
||||
del request.session['token']
|
||||
return redirect('index')
|
||||
if request.session.get("token"):
|
||||
del request.session["token"]
|
||||
return redirect("index")
|
||||
|
||||
|
||||
def register(request):
|
||||
# handle number already being registered(resend message?)
|
||||
if request.session.get('token'):
|
||||
return redirect('index')
|
||||
if request.session.get("token"):
|
||||
return redirect("index")
|
||||
context = {}
|
||||
if request.method == 'POST':
|
||||
if request.method == "POST":
|
||||
form = RegisterForm(request.POST)
|
||||
if not form.is_valid():
|
||||
context['form']=form
|
||||
return render(request, 'register.html', context)
|
||||
helper = Helper(name = form.cleaned_data['name'], phone=form.cleaned_data['phone'])
|
||||
context["form"] = form
|
||||
return render(request, "register.html", context)
|
||||
helper = Helper(
|
||||
name=form.cleaned_data["name"], phone=form.cleaned_data["phone"]
|
||||
)
|
||||
helper.save()
|
||||
token = helper.send_confirmation()
|
||||
request.session['token'] = token.pk
|
||||
return render(request, 'wait_confirmation.html', {'helper':helper})
|
||||
context['form']=RegisterForm()
|
||||
return render(request, 'register.html', context)
|
||||
request.session["token"] = token.pk
|
||||
return render(request, "wait_confirmation.html", {"helper": helper})
|
||||
context["form"] = RegisterForm()
|
||||
return render(request, "register.html", context)
|
||||
|
||||
|
||||
def shift(request, shiftid):
|
||||
shift = get_object_or_404(Shift, pk=shiftid)
|
||||
helper = None
|
||||
context = { 'can_register':False,
|
||||
'is_registered':False,
|
||||
'can_cancel': False,
|
||||
'shift':shift,
|
||||
'shift_form': EmptyForm,
|
||||
}
|
||||
context = {
|
||||
"can_register": False,
|
||||
"is_registered": False,
|
||||
"can_cancel": False,
|
||||
"shift": shift,
|
||||
"shift_form": EmptyForm,
|
||||
}
|
||||
# this currently ignores date/time
|
||||
request.session['last_seen_shift'] = shiftid
|
||||
if shift.room.required_helpers>shift.shiftregistration_set.count():
|
||||
context['can_register'] = True
|
||||
if request.session.get('token'):
|
||||
helper = LoginToken.objects.get(pk=request.session['token']).helper
|
||||
context['helper'] =helper
|
||||
reg = ShiftRegistration.objects.filter(shift=shift, helper=helper)
|
||||
request.session["last_seen_shift"] = shiftid
|
||||
if shift.room.required_helpers > shift.shiftregistration_set.count():
|
||||
context["can_register"] = True
|
||||
if request.session.get("token"):
|
||||
helper = LoginToken.objects.get(pk=request.session["token"]).helper
|
||||
context["helper"] = helper
|
||||
reg = ShiftRegistration.objects.filter(shift=shift, helper=helper)
|
||||
if reg:
|
||||
context['is_registered']=True
|
||||
context['can_register']=False
|
||||
context["is_registered"] = True
|
||||
context["can_register"] = False
|
||||
if reg[0].can_cancel():
|
||||
context['can_cancel'] = True
|
||||
if request.method=='POST':
|
||||
context["can_cancel"] = True
|
||||
if request.method == "POST":
|
||||
if EmptyForm(request.POST).is_valid():
|
||||
if not helper:
|
||||
# todo: add flash message that signup is required?
|
||||
return redirect('register')
|
||||
if context['can_register']:
|
||||
return redirect("register")
|
||||
if context["can_register"]:
|
||||
s = ShiftRegistration(helper=helper, shift=shift)
|
||||
s.save()
|
||||
# redirect so page can be reloaded without resending post data
|
||||
return redirect('shift', shiftid=shift.pk)
|
||||
return render(request, 'shift.html', context)
|
||||
return redirect("shift", shiftid=shift.pk)
|
||||
return render(request, "shift.html", context)
|
||||
|
||||
|
||||
def cancel(request, shiftid):
|
||||
if request.method!='POST':
|
||||
return redirect('shift', shiftid=shiftid)
|
||||
if request.method != "POST":
|
||||
return redirect("shift", shiftid=shiftid)
|
||||
if not EmptyForm(request.POST).is_valid():
|
||||
return redirect('shift', shiftid=shiftid)
|
||||
if not request.session.get('token'):
|
||||
return redirect('shift', shiftid=shiftid)
|
||||
helper = LoginToken.objects.get(pk=request.session['token']).helper
|
||||
return redirect("shift", shiftid=shiftid)
|
||||
if not request.session.get("token"):
|
||||
return redirect("shift", shiftid=shiftid)
|
||||
helper = LoginToken.objects.get(pk=request.session["token"]).helper
|
||||
shift = get_object_or_404(Shift, pk=shiftid)
|
||||
reg = get_object_or_404(ShiftRegistration, helper=helper, shift=shift)
|
||||
if reg.can_cancel():
|
||||
reg.delete()
|
||||
return redirect('shift', shiftid=shiftid)
|
||||
return redirect("shift", shiftid=shiftid)
|
||||
|
|
|
@ -11,6 +11,6 @@ import os
|
|||
|
||||
from django.core.asgi import get_asgi_application
|
||||
|
||||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'shiftregister.settings')
|
||||
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "shiftregister.settings")
|
||||
|
||||
application = get_asgi_application()
|
||||
|
|
|
@ -21,69 +21,71 @@ BASE_DIR = Path(__file__).resolve().parent.parent
|
|||
# See https://docs.djangoproject.com/en/4.0/howto/deployment/checklist/
|
||||
|
||||
# SECURITY WARNING: keep the secret key used in production secret!
|
||||
SECRET_KEY = getenv('SECRET_KEY', 'django-insecure-pdgzgd_!w&&cfqc%r&!v_^6pgf!sza=2wim67()!(kaf7_6-5)')
|
||||
SECRET_KEY = getenv(
|
||||
"SECRET_KEY", "django-insecure-pdgzgd_!w&&cfqc%r&!v_^6pgf!sza=2wim67()!(kaf7_6-5)"
|
||||
)
|
||||
|
||||
# SECURITY WARNING: don't run with debug turned on in production!
|
||||
DEBUG = getenv('ENVIRONMENT', 'development') != 'production'
|
||||
DEBUG = getenv("ENVIRONMENT", "development") != "production"
|
||||
|
||||
ALLOWED_HOSTS = list(filter(lambda s: s != '', getenv('ALLOWED_HOSTS', '').split(',')))
|
||||
ALLOWED_HOSTS = list(filter(lambda s: s != "", getenv("ALLOWED_HOSTS", "").split(",")))
|
||||
|
||||
|
||||
# Application definition
|
||||
|
||||
INSTALLED_APPS = [
|
||||
'shiftregister.app.apps.AppConfig',
|
||||
'shiftregister.team.apps.TeamConfig',
|
||||
'django.contrib.admin',
|
||||
'django.contrib.auth',
|
||||
'django.contrib.contenttypes',
|
||||
'django.contrib.sessions',
|
||||
'django.contrib.messages',
|
||||
'django.contrib.staticfiles',
|
||||
"shiftregister.app.apps.AppConfig",
|
||||
"shiftregister.team.apps.TeamConfig",
|
||||
"django.contrib.admin",
|
||||
"django.contrib.auth",
|
||||
"django.contrib.contenttypes",
|
||||
"django.contrib.sessions",
|
||||
"django.contrib.messages",
|
||||
"django.contrib.staticfiles",
|
||||
]
|
||||
|
||||
MIDDLEWARE = [
|
||||
'django.middleware.security.SecurityMiddleware',
|
||||
'django.contrib.sessions.middleware.SessionMiddleware',
|
||||
'django.middleware.common.CommonMiddleware',
|
||||
'django.middleware.csrf.CsrfViewMiddleware',
|
||||
'django.contrib.auth.middleware.AuthenticationMiddleware',
|
||||
'django.contrib.messages.middleware.MessageMiddleware',
|
||||
'django.middleware.clickjacking.XFrameOptionsMiddleware',
|
||||
"django.middleware.security.SecurityMiddleware",
|
||||
"django.contrib.sessions.middleware.SessionMiddleware",
|
||||
"django.middleware.common.CommonMiddleware",
|
||||
"django.middleware.csrf.CsrfViewMiddleware",
|
||||
"django.contrib.auth.middleware.AuthenticationMiddleware",
|
||||
"django.contrib.messages.middleware.MessageMiddleware",
|
||||
"django.middleware.clickjacking.XFrameOptionsMiddleware",
|
||||
]
|
||||
|
||||
ROOT_URLCONF = 'shiftregister.urls'
|
||||
ROOT_URLCONF = "shiftregister.urls"
|
||||
|
||||
TEMPLATES = [
|
||||
{
|
||||
'BACKEND': 'django.template.backends.django.DjangoTemplates',
|
||||
'DIRS': [Path(BASE_DIR,Path("templates"))],
|
||||
'APP_DIRS': True,
|
||||
'OPTIONS': {
|
||||
'context_processors': [
|
||||
'django.template.context_processors.debug',
|
||||
'django.template.context_processors.request',
|
||||
'django.contrib.auth.context_processors.auth',
|
||||
'django.contrib.messages.context_processors.messages',
|
||||
"BACKEND": "django.template.backends.django.DjangoTemplates",
|
||||
"DIRS": [Path(BASE_DIR, Path("templates"))],
|
||||
"APP_DIRS": True,
|
||||
"OPTIONS": {
|
||||
"context_processors": [
|
||||
"django.template.context_processors.debug",
|
||||
"django.template.context_processors.request",
|
||||
"django.contrib.auth.context_processors.auth",
|
||||
"django.contrib.messages.context_processors.messages",
|
||||
],
|
||||
},
|
||||
},
|
||||
]
|
||||
|
||||
WSGI_APPLICATION = 'shiftregister.wsgi.application'
|
||||
WSGI_APPLICATION = "shiftregister.wsgi.application"
|
||||
|
||||
|
||||
# Database
|
||||
# https://docs.djangoproject.com/en/4.0/ref/settings/#databases
|
||||
|
||||
DATABASES = {
|
||||
'default': {
|
||||
'ENGINE': 'django.db.backends.'+getenv('DB_ENGINE', 'sqlite3'),
|
||||
'NAME': getenv('DB_NAME', BASE_DIR / 'db.sqlite3'),
|
||||
'USER': getenv('DB_USER', ''),
|
||||
'PASSWORD': getenv('DB_PASSWORD', ''),
|
||||
'HOST': getenv('DB_HOST', ''),
|
||||
'PORT': getenv('DB_PORT', ''),
|
||||
"default": {
|
||||
"ENGINE": "django.db.backends." + getenv("DB_ENGINE", "sqlite3"),
|
||||
"NAME": getenv("DB_NAME", BASE_DIR / "db.sqlite3"),
|
||||
"USER": getenv("DB_USER", ""),
|
||||
"PASSWORD": getenv("DB_PASSWORD", ""),
|
||||
"HOST": getenv("DB_HOST", ""),
|
||||
"PORT": getenv("DB_PORT", ""),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -93,16 +95,16 @@ DATABASES = {
|
|||
|
||||
AUTH_PASSWORD_VALIDATORS = [
|
||||
{
|
||||
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
|
||||
"NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator",
|
||||
},
|
||||
{
|
||||
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
|
||||
"NAME": "django.contrib.auth.password_validation.MinimumLengthValidator",
|
||||
},
|
||||
{
|
||||
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
|
||||
"NAME": "django.contrib.auth.password_validation.CommonPasswordValidator",
|
||||
},
|
||||
{
|
||||
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
|
||||
"NAME": "django.contrib.auth.password_validation.NumericPasswordValidator",
|
||||
},
|
||||
]
|
||||
|
||||
|
@ -110,9 +112,9 @@ AUTH_PASSWORD_VALIDATORS = [
|
|||
# Internationalization
|
||||
# https://docs.djangoproject.com/en/4.0/topics/i18n/
|
||||
|
||||
LANGUAGE_CODE = 'de-de'
|
||||
LANGUAGE_CODE = "de-de"
|
||||
|
||||
TIME_ZONE = 'Europe/Berlin'
|
||||
TIME_ZONE = "Europe/Berlin"
|
||||
|
||||
USE_I18N = True
|
||||
|
||||
|
@ -122,10 +124,10 @@ USE_TZ = True
|
|||
# Static files (CSS, JavaScript, Images)
|
||||
# https://docs.djangoproject.com/en/4.0/howto/static-files/
|
||||
|
||||
STATIC_ROOT = '/opt/shiftregister/static'
|
||||
STATIC_URL = 'static/'
|
||||
STATIC_ROOT = "/opt/shiftregister/static"
|
||||
STATIC_URL = "static/"
|
||||
|
||||
# Default primary key field type
|
||||
# https://docs.djangoproject.com/en/4.0/ref/settings/#default-auto-field
|
||||
|
||||
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
|
||||
DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"
|
||||
|
|
|
@ -2,5 +2,5 @@ from django.apps import AppConfig
|
|||
|
||||
|
||||
class TeamConfig(AppConfig):
|
||||
default_auto_field = 'django.db.models.BigAutoField'
|
||||
name = 'shiftregister.team'
|
||||
default_auto_field = "django.db.models.BigAutoField"
|
||||
name = "shiftregister.team"
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
from django.db import models
|
||||
from shiftregister.app.models import *
|
||||
|
||||
# Create your models here.
|
||||
|
|
|
@ -1,11 +1,12 @@
|
|||
from django.urls import path
|
||||
|
||||
from . import views
|
||||
app_name = 'team'
|
||||
|
||||
app_name = "team"
|
||||
urlpatterns = [
|
||||
path('', views.shift_overview, name='index'),
|
||||
path('overview/', views.shift_overview, name='shift_overview'),
|
||||
path('shifts/', views.ShiftList.as_view(), name='shift_all'),
|
||||
path('shift/<int:pk>', views.ShiftDetail.as_view(), name='shift'),
|
||||
path('helper/<int:pk>', views.HelperDetail.as_view(), name='helper'),
|
||||
path("", views.shift_overview, name="index"),
|
||||
path("overview/", views.shift_overview, name="shift_overview"),
|
||||
path("shifts/", views.ShiftList.as_view(), name="shift_all"),
|
||||
path("shift/<int:pk>", views.ShiftDetail.as_view(), name="shift"),
|
||||
path("helper/<int:pk>", views.HelperDetail.as_view(), name="helper"),
|
||||
]
|
||||
|
|
|
@ -11,24 +11,47 @@ from django.contrib.auth.mixins import LoginRequiredMixin
|
|||
def index(request):
|
||||
pass
|
||||
|
||||
|
||||
@login_required
|
||||
def shift_overview(request):
|
||||
context = {}
|
||||
context['running_shifts'] = (reg.shift for reg in ShiftRegistration.objects.annotate(shift_end=ExpressionWrapper(F('shift__start_at')+F('shift__duration'), output_field=DateTimeField())).filter(shift__start_at__lte=timezone.now(), shift_end__gte=timezone.now()).order_by('shift__start_at'))
|
||||
|
||||
context["running_shifts"] = (
|
||||
reg.shift
|
||||
for reg in ShiftRegistration.objects.annotate(
|
||||
shift_end=ExpressionWrapper(
|
||||
F("shift__start_at") + F("shift__duration"),
|
||||
output_field=DateTimeField(),
|
||||
)
|
||||
)
|
||||
.filter(shift__start_at__lte=timezone.now(), shift_end__gte=timezone.now())
|
||||
.order_by("shift__start_at")
|
||||
)
|
||||
|
||||
# probably can do some distinct/group by stuff but not sure how tih django queries
|
||||
context['next_shifts'] = (next(iter(Shift.objects.filter(room=room, start_at__gt=timezone.now()).order_by('start_at'))) for room in Room.objects.all())
|
||||
|
||||
return render(request, 'shift_overview.html', context)
|
||||
context["next_shifts"] = (
|
||||
next(
|
||||
iter(
|
||||
Shift.objects.filter(room=room, start_at__gt=timezone.now()).order_by(
|
||||
"start_at"
|
||||
)
|
||||
)
|
||||
)
|
||||
for room in Room.objects.all()
|
||||
)
|
||||
|
||||
return render(request, "shift_overview.html", context)
|
||||
|
||||
|
||||
class ShiftDetail(LoginRequiredMixin, DetailView):
|
||||
template_name = "shift_detail.html"
|
||||
model= Shift
|
||||
model = Shift
|
||||
|
||||
|
||||
class HelperDetail(LoginRequiredMixin, DetailView):
|
||||
template_name = "helper_detail.html"
|
||||
model= Helper
|
||||
model = Helper
|
||||
|
||||
|
||||
class ShiftList(LoginRequiredMixin, ListView):
|
||||
template_name = "shift_list.html"
|
||||
model= Shift
|
||||
model = Shift
|
||||
|
|
|
@ -17,7 +17,7 @@ from django.contrib import admin
|
|||
from django.urls import include, path
|
||||
|
||||
urlpatterns = [
|
||||
path('', include('shiftregister.app.urls')),
|
||||
path('team/', include('shiftregister.team.urls')),
|
||||
path('admin/', admin.site.urls),
|
||||
path("", include("shiftregister.app.urls")),
|
||||
path("team/", include("shiftregister.team.urls")),
|
||||
path("admin/", admin.site.urls),
|
||||
]
|
||||
|
|
|
@ -11,6 +11,6 @@ import os
|
|||
|
||||
from django.core.wsgi import get_wsgi_application
|
||||
|
||||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'shiftregister.settings')
|
||||
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "shiftregister.settings")
|
||||
|
||||
application = get_wsgi_application()
|
||||
|
|
Loading…
Reference in New Issue