utils.py - Utility functions
Imports
These are listed in the order prescribed by PEP 8.
Standard library
Third-party imports
Local application imports
None.
Functions
Browsers are not consistent with how they format times with timezones for example Safari: Tue Sep 08 2020 21:13:00 GMT-0500 (CDT) Chrome: Tue Sep 08 2020 21:13:00 GMT-0500 (Central Daylight Time) This function tries to coerce the time string into the Safari format as it is more compatible with other time/date functions
x = re.search(r"\((.*)\)", tstring)
if x:
z = x.group(1)
y = z.split()
if len(y) == 1:
return tstring
else:
zstring = "".join([i[0] for i in y])
return re.sub(r"(.*)\((.*)\)", r"\1({})".format(zstring), tstring)
return tstring
def make_json_response(
status: int = status.HTTP_200_OK, detail: Any = None
) -> JSONResponse:
Omit the detail if it’s none.
Should be a list, the first element indicates where the error occurred for example in the path or in the body of the request. it could also be function I suppose. The second element in the list gives the name of the data element that is not valid.
a descriptive message about the error.
this is the specific error that was raised. e.g. value_error, type_error, integrity_error.