@@ -74,6 +74,32 @@ def serialize(self):
7474 }
7575
7676
77+ def decoratedSerialize (func , inc_timelines , * args , ** kwargs ):
78+ serialized = func ()
79+ if kwargs .get ("timelines" ) and inc_timelines :
80+ # Whether to include the timelines or not.
81+ timelines = kwargs ["timelines" ]
82+ if timelines :
83+ serialized .update (
84+ {
85+ "timelines" : {
86+ # Serialize all the timelines.
87+ key : value .serialize ()
88+ for (key , value ) in self .timelines .items ()
89+ }
90+ }
91+ )
92+
93+ if kwargs .get ("state" ):
94+ state = kwargs ["state" ]
95+ serialized .update ({"state" : state })
96+
97+ if kwargs .get ("county" ):
98+ county = kwargs ["county" ]
99+ serialized .update ({"county" : county })
100+
101+ return serialized
102+
77103class TimelinedLocation (Location ):
78104 """
79105 A location with timelines.
@@ -96,29 +122,19 @@ def __init__(self, id, country, province, coordinates, last_updated, timelines):
96122
97123 # Set timelines.
98124 self .timelines = timelines
125+ self .inc_timelines = false
99126
100127 # pylint: disable=arguments-differ
101- def serialize (self , timelines = False ):
128+ @decoratedSerialize (timelines = self .timelines , inc_timelines = self .inc_timelines )
129+ def serialize (self , inc_timelines = false ):
102130 """
103131 Serializes the location into a dict.
104-
105- :param timelines: Whether to include the timelines.
132+ :param inc_timelines: Whether to include the timelines.
106133 :returns: The serialized location.
107134 :rtype: dict
108135 """
109136 serialized = super ().serialize ()
110-
111- # Whether to include the timelines or not.
112- if timelines :
113- serialized .update (
114- {
115- "timelines" : {
116- # Serialize all the timelines.
117- key : value .serialize ()
118- for (key , value ) in self .timelines .items ()
119- }
120- }
121- )
137+ self .inc_timelines = inc_timelines
122138
123139 # Return the serialized location.
124140 return serialized
0 commit comments