Skip to content

Commit 8ca2326

Browse files
committed
Store empty date objects instead of null in the JSON schema
1 parent 2ca3145 commit 8ca2326

File tree

10 files changed

+10
-46
lines changed

10 files changed

+10
-46
lines changed

gramps/gen/lib/address.py

+1-4
Original file line numberDiff line numberDiff line change
@@ -117,10 +117,7 @@ def get_schema(cls):
117117
"title": _("Notes"),
118118
"items": {"type": "string", "maxLength": 50},
119119
},
120-
"date": {
121-
"oneOf": [{"type": "null"}, Date.get_schema()],
122-
"title": _("Date"),
123-
},
120+
"date": Date.get_schema(),
124121
"street": {"type": "string", "title": _("Street")},
125122
"locality": {"type": "string", "title": _("Locality")},
126123
"city": {"type": "string", "title": _("City")},

gramps/gen/lib/baseobj.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,10 @@ def get_object_state(self):
6767
properties to be saved.
6868
6969
This method is called to provide the information required to serialize
70-
the object. If None is returned then the object will be represented as
71-
null in JSON.
70+
the object.
7271
7372
:returns: Returns a dictionary of attributes that represent the state
74-
of the object or None.
73+
of the object.
7574
:rtype: dict
7675
"""
7776
attr_dict = dict(

gramps/gen/lib/citation.py

+1-4
Original file line numberDiff line numberDiff line change
@@ -113,10 +113,7 @@ def get_schema(cls):
113113
"title": _("Handle"),
114114
},
115115
"gramps_id": {"type": "string", "title": _("Gramps ID")},
116-
"date": {
117-
"oneOf": [{"type": "null"}, Date.get_schema()],
118-
"title": _("Date"),
119-
},
116+
"date": Date.get_schema(),
120117
"page": {"type": "string", "title": _("Page")},
121118
"confidence": {
122119
"type": "integer",

gramps/gen/lib/date.py

-11
Original file line numberDiff line numberDiff line change
@@ -750,17 +750,6 @@ def unserialize(self, data):
750750
raise DateError("Invalid date to unserialize")
751751
return self
752752

753-
def get_object_state(self):
754-
"""
755-
Get the current object state as a dictionary.
756-
757-
We override this method to represent an empty date as null in JSON.
758-
"""
759-
if self.is_empty() and not self.text:
760-
return None
761-
else:
762-
return super().get_object_state()
763-
764753
def set_object_state(self, attr_dict):
765754
"""
766755
Set the current object state using information provided in the given

gramps/gen/lib/event.py

+1-4
Original file line numberDiff line numberDiff line change
@@ -183,10 +183,7 @@ def get_schema(cls):
183183
},
184184
"gramps_id": {"type": "string", "title": _("Gramps ID")},
185185
"type": EventType.get_schema(),
186-
"date": {
187-
"oneOf": [{"type": "null"}, Date.get_schema()],
188-
"title": _("Date"),
189-
},
186+
"date": Date.get_schema(),
190187
"description": {"type": "string", "title": _("Description")},
191188
"place": {
192189
"type": ["string", "null"],

gramps/gen/lib/ldsord.py

+1-4
Original file line numberDiff line numberDiff line change
@@ -196,10 +196,7 @@ def get_schema(cls):
196196
"title": _("Notes"),
197197
"items": {"type": "string", "maxLength": 50},
198198
},
199-
"date": {
200-
"oneOf": [{"type": "null"}, Date.get_schema()],
201-
"title": _("Date"),
202-
},
199+
"date": Date.get_schema(),
203200
"type": {"type": "integer", "title": _("Type")},
204201
"place": {"type": "string", "title": _("Place")},
205202
"famc": {"type": ["null", "string"], "title": _("Family")},

gramps/gen/lib/media.py

+1-4
Original file line numberDiff line numberDiff line change
@@ -169,10 +169,7 @@ def get_schema(cls):
169169
"title": _("Notes"),
170170
},
171171
"change": {"type": "integer", "title": _("Last changed")},
172-
"date": {
173-
"oneOf": [{"type": "null"}, Date.get_schema()],
174-
"title": _("Date"),
175-
},
172+
"date": Date.get_schema(),
176173
"tag_list": {
177174
"type": "array",
178175
"items": {"type": "string", "maxLength": 50},

gramps/gen/lib/name.py

+1-4
Original file line numberDiff line numberDiff line change
@@ -177,10 +177,7 @@ def get_schema(cls):
177177
"items": {"type": "string", "maxLength": 50},
178178
"title": _("Notes"),
179179
},
180-
"date": {
181-
"oneOf": [{"type": "null"}, Date.get_schema()],
182-
"title": _("Date"),
183-
},
180+
"date": Date.get_schema(),
184181
"first_name": {"type": "string", "title": _("Given name")},
185182
"surname_list": {
186183
"type": "array",

gramps/gen/lib/placename.py

+1-4
Original file line numberDiff line numberDiff line change
@@ -96,10 +96,7 @@ def get_schema(cls):
9696
"properties": {
9797
"_class": {"enum": [cls.__name__]},
9898
"value": {"type": "string", "title": _("Text")},
99-
"date": {
100-
"oneOf": [{"type": "null"}, Date.get_schema()],
101-
"title": _("Date"),
102-
},
99+
"date": Date.get_schema(),
103100
"lang": {"type": "string", "title": _("Language")},
104101
},
105102
}

gramps/gen/lib/placeref.py

+1-4
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,7 @@ def get_schema(cls):
9393
"title": _("Handle"),
9494
"maxLength": 50,
9595
},
96-
"date": {
97-
"oneOf": [{"type": "null"}, Date.get_schema()],
98-
"title": _("Date"),
99-
},
96+
"date": Date.get_schema(),
10097
},
10198
}
10299

0 commit comments

Comments
 (0)