add more dynamic settings
This commit is contained in:
parent
11854ab1ce
commit
3a27d32ce5
|
@ -1,17 +1,38 @@
|
||||||
from dynamic_preferences.registries import global_preferences_registry
|
from dynamic_preferences.registries import global_preferences_registry
|
||||||
from dynamic_preferences.types import MultipleChoicePreference
|
from dynamic_preferences import types
|
||||||
from dynamic_preferences.types import Section
|
|
||||||
import phonenumbers
|
import phonenumbers
|
||||||
|
import datetime
|
||||||
|
|
||||||
registration = Section("registation")
|
helper = types.Section("helper")
|
||||||
|
|
||||||
|
|
||||||
@global_preferences_registry.register
|
@global_preferences_registry.register
|
||||||
class AllowedPhoneCountries(MultipleChoicePreference):
|
class AllowedPhoneCountries(types.MultipleChoicePreference):
|
||||||
section = registration
|
section = helper
|
||||||
name = "allowed_countries"
|
name = "allowed_countries"
|
||||||
choices = [
|
choices = [
|
||||||
(f"{phonenumbers.country_code_for_region(cc)}", cc)
|
(f"{phonenumbers.country_code_for_region(cc)}", cc)
|
||||||
for cc in phonenumbers.SUPPORTED_REGIONS
|
for cc in phonenumbers.SUPPORTED_REGIONS
|
||||||
]
|
]
|
||||||
default = [49, 41, 43]
|
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):
|
def validate_allowed_countries(value):
|
||||||
if (
|
if not f"{value.country_code}" in global_preferences["helper__allowed_countries"]:
|
||||||
not f"{value.country_code}"
|
|
||||||
in global_preferences["registation__allowed_countries"]
|
|
||||||
):
|
|
||||||
raise ValidationError(
|
raise ValidationError(
|
||||||
"Vorwahl nicht Erlaubt, bitte wende dich an den Infodesk oder schicke uns eine Mail"
|
"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.utils import timezone
|
||||||
from django.db.models import F, Count, Q, ExpressionWrapper
|
from django.db.models import F, Count, Q, ExpressionWrapper
|
||||||
from phonenumber_field.modelfields import PhoneNumberField
|
from phonenumber_field.modelfields import PhoneNumberField
|
||||||
|
from dynamic_preferences.registries import global_preferences_registry
|
||||||
|
|
||||||
|
global_preferences = global_preferences_registry.manager()
|
||||||
|
|
||||||
|
|
||||||
class Room(models.Model):
|
class Room(models.Model):
|
||||||
|
@ -73,7 +76,9 @@ class ShiftRegistration(models.Model):
|
||||||
reminder_sent = models.BooleanField(default=False)
|
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() + global_preferences["helper__min_cancel_time"],
|
||||||
|
)
|
||||||
|
|
||||||
def send_reminder(self):
|
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."
|
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():
|
def get_unnotified_registrations():
|
||||||
return ShiftRegistration.objects.filter(
|
return ShiftRegistration.objects.filter(
|
||||||
reminder_sent=False,
|
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):
|
def __str__(self):
|
||||||
|
|
Loading…
Reference in New Issue