Enhanced time synchronization for drf views.
using strings for types
2 files changed, +11 -7
+2-0.gitignore
| @@ -25,3 +25,5 @@ db.sqlite3 | ||
| 25 | 25 | .coverage |
| 26 | 26 | .pytest_cache/ |
| 27 | 27 | |
| 28 | +/app | |
| 29 | + |
+9-7plusrequest/settings.py
| @@ -5,7 +5,7 @@ from django.conf import settings | ||
| 5 | 5 | from plusrequest.types import MissingAction |
| 6 | 6 | |
| 7 | 7 | |
| 8 | -def env(type: type, key: str, default: str): | |
| 8 | +def env(type: str, key: str, default: str): | |
| 9 | 9 | return getattr(e, str(type))(f"PLUSREQUEST_{key}", default) |
| 10 | 10 | |
| 11 | 11 | |
| @@ -13,17 +13,19 @@ def env(type: type, key: str, default: str): | ||
| 13 | 13 | class PlusRequestConf: |
| 14 | 14 | """Dataclass for configuring PlusRequest""" |
| 15 | 15 | |
| 16 | - header_timestamp_field: str = env(str, "HEADER_TIMESTAMP_FIELD", "lastUpdated") | |
| 16 | + header_timestamp_field: str = env("str", "HEADER_TIMESTAMP_FIELD", "lastUpdated") | |
| 17 | 17 | """Field in headers to use for client timestamp""" |
| 18 | - body_timestamp_field: str = env(str, "BODY_TIMESTAMP_FIELD", "lastUpdated") | |
| 18 | + body_timestamp_field: str = env("str", "BODY_TIMESTAMP_FIELD", "lastUpdated") | |
| 19 | 19 | """Field in request body to use for client timestamp""" |
| 20 | - instance_timestamp_field: str = env(str, "INSTANCE_TIMESTAMP_FIELD", "lastUpdated") | |
| 20 | + instance_timestamp_field: str = env( | |
| 21 | + "str", "INSTANCE_TIMESTAMP_FIELD", "lastUpdated" | |
| 22 | + ) | |
| 21 | 23 | """Field in model instance to use for server timestamp""" |
| 22 | - noupdate_code: str = env(str, "NOUPDATE_CODE", "418") | |
| 24 | + noupdate_code: str = env("str", "NOUPDATE_CODE", "418") | |
| 23 | 25 | """Status code for when the client is newer on a GET or client is older on a POST""" |
| 24 | - missing_action: MissingAction = env(str, "MISSING_ACTION", "noupdate") | |
| 26 | + missing_action: MissingAction = env("str", "MISSING_ACTION", "noupdate") | |
| 25 | 27 | """What do do when the client does not provide a timestamp""" |
| 26 | - datetime_format: str = env(str, "DATETIME_FORMAT", "%Y-%m-%dT%H:%M:%S%z") | |
| 28 | + datetime_format: str = env("str", "DATETIME_FORMAT", "%Y-%m-%dT%H:%M:%S%z") | |
| 27 | 29 | |
| 28 | 30 | |
| 29 | 31 | if hasattr(settings, "PLUSREQUEST_CONF"): |