| 1 | from typing import Any |
| 2 | from environs import env |
| 3 | from django.conf import settings |
| 4 | |
| 5 | from timecheck.types import TimeCheckConf |
| 6 | |
| 7 | |
| 8 | def e(type: type, key: str, default: str): |
| 9 | return getattr(env, type.__name__)(f"TIMECHECK_{key.upper()}", default) |
| 10 | |
| 11 | |
| 12 | initial = getattr(settings, "TIMECHECK_CONF", {}) |
| 13 | |
| 14 | |
| 15 | def getval(t: type, k: str, d: Any): |
| 16 | return initial.get(k, e(t, k, d)) |
| 17 | |
| 18 | |
| 19 | conf = 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 | ) |