irongit

Enhanced time synchronization for drf views.

29 lines875 BPython
1from typing import Any
2from environs import env
3from django.conf import settings
4
5from timecheck.types import TimeCheckConf
6
7
8def e(type: type, key: str, default: str):
9 return getattr(env, type.__name__)(f"TIMECHECK_{key.upper()}", default)
10
11
12initial = getattr(settings, "TIMECHECK_CONF", {})
13
14
15def getval(t: type, k: str, d: Any):
16 return initial.get(k, e(t, k, d))
17
18
19conf = TimeCheckConf(
20 {
21 "body_field": getval(str, "body_field", "lastUpdated"),
22 "dt_fmt": getval(str, "dt_fmt", "%Y-%m-%dT%H:%M:%S%z"),
23 "header_field": getval(str, "header_field", "lastUpdated"),
24 "instance_field": getval(str, "instance_field", "lastUpdated"),
25 "missing_action": getval(str, "missing_action", "noupdate"),
26 "noupdate_code": getval(int, "noupdate_code", 418),
27 "raise_exception": getval(bool, "raise_exception", True),
28 }
29)