improve error messages

This commit is contained in:
Jean-Marie Favreau 2023-12-23 12:56:50 +01:00
parent e02caa06d9
commit cc3ede4ed5

View File

@ -12,18 +12,36 @@ class EventsImporter:
try: try:
structure = json.loads(json_structure) structure = json.loads(json_structure)
self.url = structure["header"]["url"]
self.date = structure["header"]["date"]
except: except:
return (False, "JSON file is not correctly structured") return (False, "JSON file is not correctly structured")
if not "header" in structure:
return (False, "JSON is not correctly structured: missing header")
if "url" in structure["header"]:
self.url = structure["header"]["url"]
else:
return (False, "JSON is not correctly structured: missing url in header")
if "url" in structure["header"]:
self.date = structure["header"]["date"]
# load events # load events
for event in structure["events"]: for event in structure["events"]:
self.import_event(event) self.import_event(event)
# update object with infos from header, and with the list of imported objects
# TODO
# events that are missing from the import but in database are turned into drafts
# TODO
return (True, "")
def import_event(self, event): def import_event(self, event):
# TODO
pass pass