add initial shift reminder functionality
This commit is contained in:
parent
c0ee3eea02
commit
d1bdd2bc74
|
@ -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),
|
||||||
|
),
|
||||||
|
]
|
|
@ -68,10 +68,24 @@ class ShiftRegistration(models.Model):
|
||||||
# use restrict for now as Model.delete is not called
|
# use restrict for now as Model.delete is not called
|
||||||
shift = models.ForeignKey(Shift, on_delete=models.RESTRICT)
|
shift = models.ForeignKey(Shift, on_delete=models.RESTRICT)
|
||||||
helper = models.ForeignKey(Helper, on_delete=models.CASCADE)
|
helper = models.ForeignKey(Helper, on_delete=models.CASCADE)
|
||||||
|
reminder_sent = models.BooleanField(default=False)
|
||||||
|
|
||||||
def can_cancel(self):
|
def can_cancel(self):
|
||||||
return self.shift.start_at > (timezone.now() + timedelta(hours=4))
|
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):
|
class Message(models.Model):
|
||||||
# remove limit and send long messages in multiple messages?
|
# remove limit and send long messages in multiple messages?
|
||||||
|
|
Loading…
Reference in New Issue