2
0
Fork 0

add initial shift reminder functionality

This commit is contained in:
Andreas (@xAndy) Zimmermann 2022-04-20 22:05:26 +02:00
parent c0ee3eea02
commit d1bdd2bc74
2 changed files with 32 additions and 0 deletions

View File

@ -0,0 +1,18 @@
# Generated by Django 4.0.4 on 2022-04-20 17:57
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
("app", "0003_message_created_at"),
]
operations = [
migrations.AddField(
model_name="shiftregistration",
name="reminder_sent",
field=models.BooleanField(default=False),
),
]

View File

@ -68,10 +68,24 @@ class ShiftRegistration(models.Model):
# 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)
reminder_sent = models.BooleanField(default=False)
def can_cancel(self):
return self.shift.start_at > (timezone.now() + timedelta(hours=4))
def send_reminder(self):
text = f"Deine Kontakt-Schicht begint um {self.shift.start_at.strftime('%H:%M')}, bitte komme eine halbe Stunde vorher an den Infopoint."
msg = Message(to=self.helper, text=text)
msg.save()
self.reminder_sent = True
self.save()
def get_unnotified_registrations():
return ShiftRegistration.objects.filter(
reminder_sent=False,
shift__start_at__lte=timezone.now() + timedelta(minutes=60),
)
class Message(models.Model):
# remove limit and send long messages in multiple messages?