add more dynamic settings

pull/1/head
parent 11854ab1ce
commit 3a27d32ce5

@ -1,17 +1,38 @@
from dynamic_preferences.registries import global_preferences_registry
from dynamic_preferences.types import MultipleChoicePreference
from dynamic_preferences.types import Section
from dynamic_preferences import types
import phonenumbers
import datetime
registration = Section("registation")
helper = types.Section("helper")
@global_preferences_registry.register
class AllowedPhoneCountries(MultipleChoicePreference):
section = registration
class AllowedPhoneCountries(types.MultipleChoicePreference):
section = helper
name = "allowed_countries"
choices = [
(f"{phonenumbers.country_code_for_region(cc)}", cc)
for cc in phonenumbers.SUPPORTED_REGIONS
]
default = [49, 41, 43]
@global_preferences_registry.register
class SendSMS(types.BooleanPreference):
section = helper
name = "send_sms"
default = True
@global_preferences_registry.register
class ShiftReminder(types.DurationPreference):
section = helper
name = "reminder_time"
default = datetime.timedelta(minutes=30)
@global_preferences_registry.register
class CancelMin(types.DurationPreference):
section = helper
name = "min_cancel_time"
default = datetime.timedelta(hours=6)

@ -17,10 +17,7 @@ def text_input(type=None):
def validate_allowed_countries(value):
if (
not f"{value.country_code}"
in global_preferences["registation__allowed_countries"]
):
if not f"{value.country_code}" in global_preferences["helper__allowed_countries"]:
raise ValidationError(
"Vorwahl nicht Erlaubt, bitte wende dich an den Infodesk oder schicke uns eine Mail"
)

@ -5,6 +5,9 @@ from datetime import timedelta
from django.utils import timezone
from django.db.models import F, Count, Q, ExpressionWrapper
from phonenumber_field.modelfields import PhoneNumberField
from dynamic_preferences.registries import global_preferences_registry
global_preferences = global_preferences_registry.manager()
class Room(models.Model):
@ -73,7 +76,9 @@ class ShiftRegistration(models.Model):
reminder_sent = models.BooleanField(default=False)
def can_cancel(self):
return self.shift.start_at > (timezone.now() + timedelta(hours=4))
return self.shift.start_at > (
timezone.now() + global_preferences["helper__min_cancel_time"],
)
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."
@ -85,7 +90,8 @@ class ShiftRegistration(models.Model):
def get_unnotified_registrations():
return ShiftRegistration.objects.filter(
reminder_sent=False,
shift__start_at__lte=timezone.now() + timedelta(minutes=60),
shift__start_at__lte=timezone.now()
+ global_preferences["helper__reminder_time"],
)
def __str__(self):

Loading…
Cancel
Save