Skip to content

Commit

Permalink
feat: Event Archive (#90)
Browse files Browse the repository at this point in the history
* WIP: event archive pages

* WIP: add observation_event_meta.html template

* WIP: Update event models with situation field

* feat: Restrict observation quote to one line

* feat: Add event templates for ObservationMade and ObservationClosed

* fix: Remove add_published
  • Loading branch information
dragonee committed Sep 23, 2024
1 parent 6d29053 commit 0e25f5d
Show file tree
Hide file tree
Showing 19 changed files with 320 additions and 62 deletions.
5 changes: 5 additions & 0 deletions DECISION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Decision tree

## If I want to listen for keyboard shortcuts in Vue

Use [GlobalEvents](https://github.com/shentao/vue-global-events/tree/v1).
14 changes: 14 additions & 0 deletions PROD.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@




The following code is used to find and display instances where there are multiple ObservationUpdated entries with the same published date and observation_id, but only when the published time is not exactly midnight. This could be useful for identifying potential data inconsistencies or duplicate entries in the database.

```python
k = ObservationUpdated.objects.values('published', 'observation_id').annotate(cnt=Count('published')).order_by()
t = list(filter(lambda x: x['cnt'] > 1, k))
u = list(filter(lambda x: x['published'].hour != 0 and x['published'].minute != 0, t))
for i in u:
print(i)

```
3 changes: 2 additions & 1 deletion TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@
- [ ] Implement $ on tasks, so that only part of information is shown on the task list, all can be edited
- [x] Add a Journal archive view set
- [ ] Add an event archive view set
- [ ] Remove add_published from templatetags
- [x] Remove add_published from templatetags
- [ ] Check #253 – is ObservationMade done here?
- [x] Add a special symbol in journal to add a line to a reflection
- Symbols: [x] [~] [^]
- How about [ ] for Plan?
Expand Down
46 changes: 35 additions & 11 deletions tasks/apps/tree/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,8 @@ class HabitTracked(Event):

note = models.TextField(null=True, blank=True)

template = "tree/events/habit_tracked.html"

def __str__(self):
return "{} {}".format(self.habit, self.published)

Expand Down Expand Up @@ -258,12 +260,30 @@ def copy(self, as_new=True):
def coalesce(value, default=''):
return value if value is not None else default

class ObservationEventMixin:
class ObservationPropertyEventMixin:
@property
def observation(self):
return Observation.objects.get(event_stream_id=self.event_stream_id)

class ObservationMade(Event, ObservationEventMixin):
class ObservationEventMixin:
def situation(self):
### XXX Situation at the time of the event or current?
### For now, current is implemented here
event = Event.objects.instance_of(
ObservationMade,
ObservationRecontextualized
).filter(
event_stream_id=self.event_stream_id
).order_by(
'-published'
).first()

if not event:
raise Observation.DoesNotExist

return event.situation

class ObservationMade(Event, ObservationEventMixin, ObservationPropertyEventMixin):
# event_stream_id <- Observation
# thread <- Observation (can be updated)

Expand All @@ -273,6 +293,8 @@ class ObservationMade(Event, ObservationEventMixin):
interpretation = models.TextField(help_text=_("How you saw it, what you felt?"), null=True, blank=True)
approach = models.TextField(help_text=_("How should you approach it in the future?"), null=True, blank=True)

template = "tree/events/observation_made.html"

@staticmethod
def from_observation(observation, published=None):
return ObservationMade(
Expand All @@ -292,21 +314,21 @@ def __str__(self):
self.thread
)

class ObservationUpdated(Event):
class ObservationUpdated(Event, ObservationEventMixin):
observation = models.ForeignKey(Observation, on_delete=models.SET_NULL, null=True, blank=True)

### TODO add template
template = "tree/events/observation_updated.html"

comment = models.TextField(help_text=_("Update"))

def __str__(self):
return self.comment

class ObservationRecontextualized(Event, ObservationEventMixin):
class ObservationRecontextualized(Event, ObservationEventMixin, ObservationPropertyEventMixin):
old_situation = models.TextField(blank=True)
situation = models.TextField()

### TODO add template
template = "tree/events/observation_recontextualized.html"

@staticmethod
def from_observation(observation, old, published=None):
Expand All @@ -318,7 +340,7 @@ def from_observation(observation, old, published=None):
situation=coalesce(observation.situation),
)

class ObservationReinterpreted(Event, ObservationEventMixin):
class ObservationReinterpreted(Event, ObservationEventMixin, ObservationPropertyEventMixin):
old_interpretation = models.TextField(blank=True)
interpretation = models.TextField()

Expand All @@ -334,11 +356,11 @@ def from_observation(observation, old, published=None):
interpretation=coalesce(observation.interpretation),
)

class ObservationReflectedUpon(Event, ObservationEventMixin):
class ObservationReflectedUpon(Event, ObservationEventMixin, ObservationPropertyEventMixin):
old_approach = models.TextField(blank=True)
approach = models.TextField()

### TODO add template
template = "tree/events/observation_reflectedupon.html"

@staticmethod
def from_observation(observation, old, published=None):
Expand All @@ -350,14 +372,14 @@ def from_observation(observation, old, published=None):
approach=coalesce(observation.approach),
)

class ObservationClosed(Event, ObservationEventMixin):
class ObservationClosed(Event, ObservationEventMixin, ObservationPropertyEventMixin):
type = models.ForeignKey(ObservationType, on_delete=models.CASCADE)

situation = models.TextField(help_text=_("What happened?"), null=True, blank=True)
interpretation = models.TextField(help_text=_("How you saw it, what you felt?"), null=True, blank=True)
approach = models.TextField(help_text=_("How should you approach it in the future?"), null=True, blank=True)

### TODO add template
template = "tree/events/observation_closed.html"

@staticmethod
def from_observation(observation, published=None):
Expand Down Expand Up @@ -410,6 +432,8 @@ def on_observation_thread_change_update_events(sender, instance, *args, **kwargs
class JournalAdded(Event):
comment = models.TextField(help_text=_("Update"))

template = "tree/events/journal_added.html"

def __str__(self):
return self.comment

Expand Down
15 changes: 7 additions & 8 deletions tasks/apps/tree/templatetags/model_presenters.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,18 @@

from django.template.defaultfilters import linebreaks
from django.utils.safestring import mark_safe
from django.template.defaultfilters import stringfilter


register = template.Library()


@register.filter
def add_published(object):
linebreaks_str = linebreaks(object.comment)

time_str = '<p data-time="{}">'.format(
object.published.strftime('%H:%M')
)

return mark_safe(linebreaks_str.replace('<p>', time_str, 1))
@stringfilter
def first_line(text):
splitted = text.split('\n')

if len(splitted) > 1:
return splitted[0].rstrip().rstrip('.…') + '…'

return text
2 changes: 2 additions & 0 deletions tasks/apps/tree/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
path('observations/closed/', views.ObservationClosedListView.as_view(), name='public-observation-list-closed'),
path('diary/<int:year>/<int:month>/', views.JournalArchiveMonthView.as_view(month_format="%m"), name='public-diary-archive-month'),
path('diary/', views.JournalCurrentMonthArchiveView.as_view(month_format="%m"), name='public-diary-archive-current-month'),
path('events/', views.EventCurrentMonthArchiveView.as_view(month_format="%m"), name='public-event-archive-current-month'),
path('events/<int:year>/<int:month>/', views.EventArchiveMonthView.as_view(month_format="%m"), name='public-event-archive-month'),
re_path(r'^observations/closed/(?P<event_stream_id>[a-f0-9\-]+)/$', views.observation_closed_detail, name='public-observation-closed-detail'),

re_path(r'^observations/(?P<observation_id>[a-f0-9\-]+)/close/$', views.observation_close, name='public-observation-close'),
Expand Down
36 changes: 29 additions & 7 deletions tasks/apps/tree/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -614,23 +614,45 @@ def get_context_data(self, **kwargs):
)
return context

class EventArchiveContextMixin:
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context['dates'] = Event.objects.dates(
'published',
'month',
order='DESC'
)
return context

class CurrentMonthArchiveView(MonthArchiveView):
def get_month(self):
return timezone.now().month

def get_year(self):
return timezone.now().year

class JournalCurrentMonthArchiveView(JournalArchiveContextMixin, MonthArchiveView):

class JournalCurrentMonthArchiveView(JournalArchiveContextMixin, CurrentMonthArchiveView):
model = JournalAdded
date_field = 'published'
allow_future = True


template_name = 'tree/journaladded_archive_month.html'

def get_month(self):
return timezone.now().month

def get_year(self):
return timezone.now().year


class JournalArchiveMonthView(JournalArchiveContextMixin, MonthArchiveView):
model = JournalAdded
date_field = 'published'
allow_future = True


class EventCurrentMonthArchiveView(EventArchiveContextMixin, CurrentMonthArchiveView):
model = Event
date_field = 'published'
allow_future = True

class EventArchiveMonthView(EventArchiveContextMixin, MonthArchiveView):
model = Event
date_field = 'published'
allow_future = True
53 changes: 37 additions & 16 deletions tasks/assets/styles/example.scss
Original file line number Diff line number Diff line change
Expand Up @@ -942,32 +942,48 @@ article.quest {

.event {
margin: 0.4em 0;

.event-meta {
margin: 1em 0;
}

.minus {
border-left: 8px solid salmon;
border-left: 4px solid salmon;
color: salmon;
padding-left: 0.2em;
padding-left: 1rem;
display: block;
}

.plus {
border-left: 8px solid lightseagreen;
border-left: 4px solid lightseagreen;
color: lightseagreen;
padding-left: 0.2em;
padding-left: 1rem;
display: block;
}

.minus p, .plus p {
margin: 0;
}

ins.empty, del.empty {
opacity: 0.5;
margin: 1em 0;
text-decoration: none;
font-style:italic;
}

ins, del {
display: block;
padding: 0.2em 0;
}

.observation-ref, .observation-ref a {
font-size: 0.875em;
color: #999;
}

blockquote.situation {
border-left: 4px solid #eee;
padding-left: 1rem;
margin-left: 0;
}
}

Expand Down Expand Up @@ -1008,17 +1024,22 @@ section.journal {
margin-top: 0;
list-style: none;
}

}
}

p[data-time]::before {
content: attr(data-time);
font-size: 0.875em;
font-weight: bold;
color: #999;
margin-right: 0.25em;
position: absolute;
left: -3.24rem;
[data-time] {
&::before {
content: attr(data-time);
font-size: 0.875em;
font-weight: bold;
color: #999;
margin-right: 0.25em;
position: absolute;
left: -3.24rem;
}

time {
display: none;
}
}
}
}
Expand Down
Loading

0 comments on commit 0e25f5d

Please sign in to comment.