@@ -146,6 +146,8 @@ class HabitTracked(Event):
146146
147147 note = models .TextField (null = True , blank = True )
148148
149+ template = "tree/events/habit_tracked.html"
150+
149151 def __str__ (self ):
150152 return "{} {}" .format (self .habit , self .published )
151153
@@ -258,12 +260,30 @@ def copy(self, as_new=True):
258260def coalesce (value , default = '' ):
259261 return value if value is not None else default
260262
261- class ObservationEventMixin :
263+ class ObservationPropertyEventMixin :
262264 @property
263265 def observation (self ):
264266 return Observation .objects .get (event_stream_id = self .event_stream_id )
265267
266- class ObservationMade (Event , ObservationEventMixin ):
268+ class ObservationEventMixin :
269+ def situation (self ):
270+ ### XXX Situation at the time of the event or current?
271+ ### For now, current is implemented here
272+ event = Event .objects .instance_of (
273+ ObservationMade ,
274+ ObservationRecontextualized
275+ ).filter (
276+ event_stream_id = self .event_stream_id
277+ ).order_by (
278+ '-published'
279+ ).first ()
280+
281+ if not event :
282+ raise Observation .DoesNotExist
283+
284+ return event .situation
285+
286+ class ObservationMade (Event , ObservationEventMixin , ObservationPropertyEventMixin ):
267287 # event_stream_id <- Observation
268288 # thread <- Observation (can be updated)
269289
@@ -273,6 +293,8 @@ class ObservationMade(Event, ObservationEventMixin):
273293 interpretation = models .TextField (help_text = _ ("How you saw it, what you felt?" ), null = True , blank = True )
274294 approach = models .TextField (help_text = _ ("How should you approach it in the future?" ), null = True , blank = True )
275295
296+ template = "tree/events/observation_made.html"
297+
276298 @staticmethod
277299 def from_observation (observation , published = None ):
278300 return ObservationMade (
@@ -292,21 +314,21 @@ def __str__(self):
292314 self .thread
293315 )
294316
295- class ObservationUpdated (Event ):
317+ class ObservationUpdated (Event , ObservationEventMixin ):
296318 observation = models .ForeignKey (Observation , on_delete = models .SET_NULL , null = True , blank = True )
297319
298- ### TODO add template
320+ template = "tree/events/observation_updated.html"
299321
300322 comment = models .TextField (help_text = _ ("Update" ))
301323
302324 def __str__ (self ):
303325 return self .comment
304326
305- class ObservationRecontextualized (Event , ObservationEventMixin ):
327+ class ObservationRecontextualized (Event , ObservationEventMixin , ObservationPropertyEventMixin ):
306328 old_situation = models .TextField (blank = True )
307329 situation = models .TextField ()
308330
309- ### TODO add template
331+ template = "tree/events/observation_recontextualized.html"
310332
311333 @staticmethod
312334 def from_observation (observation , old , published = None ):
@@ -318,7 +340,7 @@ def from_observation(observation, old, published=None):
318340 situation = coalesce (observation .situation ),
319341 )
320342
321- class ObservationReinterpreted (Event , ObservationEventMixin ):
343+ class ObservationReinterpreted (Event , ObservationEventMixin , ObservationPropertyEventMixin ):
322344 old_interpretation = models .TextField (blank = True )
323345 interpretation = models .TextField ()
324346
@@ -334,11 +356,11 @@ def from_observation(observation, old, published=None):
334356 interpretation = coalesce (observation .interpretation ),
335357 )
336358
337- class ObservationReflectedUpon (Event , ObservationEventMixin ):
359+ class ObservationReflectedUpon (Event , ObservationEventMixin , ObservationPropertyEventMixin ):
338360 old_approach = models .TextField (blank = True )
339361 approach = models .TextField ()
340362
341- ### TODO add template
363+ template = "tree/events/observation_reflectedupon.html"
342364
343365 @staticmethod
344366 def from_observation (observation , old , published = None ):
@@ -350,14 +372,14 @@ def from_observation(observation, old, published=None):
350372 approach = coalesce (observation .approach ),
351373 )
352374
353- class ObservationClosed (Event , ObservationEventMixin ):
375+ class ObservationClosed (Event , ObservationEventMixin , ObservationPropertyEventMixin ):
354376 type = models .ForeignKey (ObservationType , on_delete = models .CASCADE )
355377
356378 situation = models .TextField (help_text = _ ("What happened?" ), null = True , blank = True )
357379 interpretation = models .TextField (help_text = _ ("How you saw it, what you felt?" ), null = True , blank = True )
358380 approach = models .TextField (help_text = _ ("How should you approach it in the future?" ), null = True , blank = True )
359381
360- ### TODO add template
382+ template = "tree/events/observation_closed.html"
361383
362384 @staticmethod
363385 def from_observation (observation , published = None ):
@@ -410,6 +432,8 @@ def on_observation_thread_change_update_events(sender, instance, *args, **kwargs
410432class JournalAdded (Event ):
411433 comment = models .TextField (help_text = _ ("Update" ))
412434
435+ template = "tree/events/journal_added.html"
436+
413437 def __str__ (self ):
414438 return self .comment
415439
0 commit comments