Skip to content

Commit

Permalink
Store empty date objects instead of null in the JSON schema
Browse files Browse the repository at this point in the history
  • Loading branch information
Nick-Hall committed Oct 30, 2024
1 parent 2ca3145 commit 8ca2326
Show file tree
Hide file tree
Showing 10 changed files with 10 additions and 46 deletions.
5 changes: 1 addition & 4 deletions gramps/gen/lib/address.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,7 @@ def get_schema(cls):
"title": _("Notes"),
"items": {"type": "string", "maxLength": 50},
},
"date": {
"oneOf": [{"type": "null"}, Date.get_schema()],
"title": _("Date"),
},
"date": Date.get_schema(),
"street": {"type": "string", "title": _("Street")},
"locality": {"type": "string", "title": _("Locality")},
"city": {"type": "string", "title": _("City")},
Expand Down
5 changes: 2 additions & 3 deletions gramps/gen/lib/baseobj.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,10 @@ def get_object_state(self):
properties to be saved.
This method is called to provide the information required to serialize
the object. If None is returned then the object will be represented as
null in JSON.
the object.
:returns: Returns a dictionary of attributes that represent the state
of the object or None.
of the object.
:rtype: dict
"""
attr_dict = dict(
Expand Down
5 changes: 1 addition & 4 deletions gramps/gen/lib/citation.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,7 @@ def get_schema(cls):
"title": _("Handle"),
},
"gramps_id": {"type": "string", "title": _("Gramps ID")},
"date": {
"oneOf": [{"type": "null"}, Date.get_schema()],
"title": _("Date"),
},
"date": Date.get_schema(),
"page": {"type": "string", "title": _("Page")},
"confidence": {
"type": "integer",
Expand Down
11 changes: 0 additions & 11 deletions gramps/gen/lib/date.py
Original file line number Diff line number Diff line change
Expand Up @@ -750,17 +750,6 @@ def unserialize(self, data):
raise DateError("Invalid date to unserialize")
return self

def get_object_state(self):
"""
Get the current object state as a dictionary.
We override this method to represent an empty date as null in JSON.
"""
if self.is_empty() and not self.text:
return None
else:
return super().get_object_state()

def set_object_state(self, attr_dict):
"""
Set the current object state using information provided in the given
Expand Down
5 changes: 1 addition & 4 deletions gramps/gen/lib/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,10 +183,7 @@ def get_schema(cls):
},
"gramps_id": {"type": "string", "title": _("Gramps ID")},
"type": EventType.get_schema(),
"date": {
"oneOf": [{"type": "null"}, Date.get_schema()],
"title": _("Date"),
},
"date": Date.get_schema(),
"description": {"type": "string", "title": _("Description")},
"place": {
"type": ["string", "null"],
Expand Down
5 changes: 1 addition & 4 deletions gramps/gen/lib/ldsord.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,10 +196,7 @@ def get_schema(cls):
"title": _("Notes"),
"items": {"type": "string", "maxLength": 50},
},
"date": {
"oneOf": [{"type": "null"}, Date.get_schema()],
"title": _("Date"),
},
"date": Date.get_schema(),
"type": {"type": "integer", "title": _("Type")},
"place": {"type": "string", "title": _("Place")},
"famc": {"type": ["null", "string"], "title": _("Family")},
Expand Down
5 changes: 1 addition & 4 deletions gramps/gen/lib/media.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,10 +169,7 @@ def get_schema(cls):
"title": _("Notes"),
},
"change": {"type": "integer", "title": _("Last changed")},
"date": {
"oneOf": [{"type": "null"}, Date.get_schema()],
"title": _("Date"),
},
"date": Date.get_schema(),
"tag_list": {
"type": "array",
"items": {"type": "string", "maxLength": 50},
Expand Down
5 changes: 1 addition & 4 deletions gramps/gen/lib/name.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,10 +177,7 @@ def get_schema(cls):
"items": {"type": "string", "maxLength": 50},
"title": _("Notes"),
},
"date": {
"oneOf": [{"type": "null"}, Date.get_schema()],
"title": _("Date"),
},
"date": Date.get_schema(),
"first_name": {"type": "string", "title": _("Given name")},
"surname_list": {
"type": "array",
Expand Down
5 changes: 1 addition & 4 deletions gramps/gen/lib/placename.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,7 @@ def get_schema(cls):
"properties": {
"_class": {"enum": [cls.__name__]},
"value": {"type": "string", "title": _("Text")},
"date": {
"oneOf": [{"type": "null"}, Date.get_schema()],
"title": _("Date"),
},
"date": Date.get_schema(),
"lang": {"type": "string", "title": _("Language")},
},
}
Expand Down
5 changes: 1 addition & 4 deletions gramps/gen/lib/placeref.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,7 @@ def get_schema(cls):
"title": _("Handle"),
"maxLength": 50,
},
"date": {
"oneOf": [{"type": "null"}, Date.get_schema()],
"title": _("Date"),
},
"date": Date.get_schema(),
},
}

Expand Down

0 comments on commit 8ca2326

Please sign in to comment.