diff --git a/TODO.md b/TODO.md index 577c397..fda0e21 100644 --- a/TODO.md +++ b/TODO.md @@ -1,30 +1,36 @@ # To-Do List +## General + +[_] Make sure users can't access other users' data +[_] Allow configuration as single user instance + ## mood module [_] Missing mood views -[ ] Statistics / graphs +[_] Statistics / graphs ## cbt module -[ ] Complete thought record creation -[ ] Thought record editing (?) -[ ] Thought record deletion +[_] Complete thought record creation +[_] Thought record editing (?) +[_] Thought record deletion ## msgio module -[ ] Implement Telegram webhooks +[_] Implement Telegram webhooks ## dreams module [x] New dream page [x] Edit dream page [x] Delete dream page -[ ] Statistics / template tags -[ ] Check for copy-paste errors in pages +[x] Statistics / template tags +[_] Check for copy-paste errors in pages ## Frontend -[ ] Better icons for sidebar items -[ ] Sidebar auto-generation (?) -[ ] Fix sidebar highlighting for pages with same name \ No newline at end of file +[_] Better icons for sidebar items +[_] Sidebar auto-generation (?) +[_] Fix sidebar highlighting for pages with same name +[_] Move dashboard components to module templates \ No newline at end of file diff --git a/dreams/templatetags/__init__.py b/dreams/templatetags/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/dreams/templatetags/dream_stats.py b/dreams/templatetags/dream_stats.py new file mode 100644 index 0000000..2719aee --- /dev/null +++ b/dreams/templatetags/dream_stats.py @@ -0,0 +1,60 @@ +from django import template +from django.utils import timezone + +from collections import Counter + +register = template.Library() + +@register.simple_tag(takes_context=True) +def total_dreams(context): + return len(context["user"].dream_set.all()) + +@register.simple_tag(takes_context=True) +def weekly_dreams(context): + now = timezone.now() + start = now - timezone.timedelta(days=7) + + return len(context["user"].dream_set.filter(timestamp__gte=start, timestamp__lte=now)) + +@register.simple_tag(takes_context=True) +def most_common_theme(context, start, end=None): + dream_list = context["user"].dream_set.filter(timestamp__gte=start.date(), timestamp__lte=(end.date() if end else start.date())) + themes = list() + + for dream in dream_list: + for theme in dream.dreamtheme_set.all(): + themes.append(theme.theme) + + try: + most_common = Counter(themes).most_common(1)[0] + return most_common[0], most_common[1] + except: + return None, None + +@register.simple_tag(takes_context=True) +def most_common_theme_weekly(context): + now = timezone.now() + start = now - timezone.timedelta(days=7) + + return most_common_theme(context, start, now) + +@register.simple_tag(takes_context=True) +def special_dreams(context, start, end=None): + dream_list = context["user"].dream_set.filter(timestamp__gte=start.date(), timestamp__lte=(end.date() if end else start.date())) + wet = 0 + lucid = 0 + + for dream in dream_list: + if dream.lucid: + lucid += 1 + if dream.wet: + wet += 1 + + return lucid, wet + +@register.simple_tag(takes_context=True) +def special_dreams_weekly(context): + now = timezone.now() + start = now - timezone.timedelta(days=7) + + return special_dreams(context, start, now) \ No newline at end of file diff --git a/frontend/templates/frontend/dashboard.html b/frontend/templates/frontend/dashboard.html index 9487cbc..e807c8b 100644 --- a/frontend/templates/frontend/dashboard.html +++ b/frontend/templates/frontend/dashboard.html @@ -1,7 +1,9 @@ {% extends "frontend/base.html" %} {% load mood_stats %} +{% load dream_stats %} {% block "content" %} +