[templates] Cleaning up templates and datalog forms

This commit is contained in:
2025-09-11 18:55:45 -04:00
parent 92c0c668b3
commit a1ff82bfec
12 changed files with 44 additions and 16 deletions

View File

@ -1,5 +1,4 @@
from dataclasses import dataclass from dataclasses import dataclass
from typing import Optional
from django.apps import apps from django.apps import apps
from django.db import models from django.db import models
from django.urls import reverse from django.urls import reverse

View File

@ -1,11 +1,13 @@
from decimal import Decimal, getcontext
import logging import logging
from dataclasses import dataclass
from decimal import Decimal
from typing import Dict from typing import Dict
from django.contrib.auth import get_user_model
from django.conf import settings from django.conf import settings
from django.contrib.auth import get_user_model
from django.db import models from django.db import models
from django.urls import reverse from django.urls import reverse
from scrobbles.dataclasses import BaseLogData, WithPeopleLogData
from scrobbles.mixins import ScrobblableConstants, ScrobblableMixin from scrobbles.mixins import ScrobblableConstants, ScrobblableMixin
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@ -15,6 +17,9 @@ User = get_user_model()
GEOLOC_ACCURACY = int(getattr(settings, "GEOLOC_ACCURACY", 4)) GEOLOC_ACCURACY = int(getattr(settings, "GEOLOC_ACCURACY", 4))
GEOLOC_PROXIMITY = Decimal(getattr(settings, "GEOLOC_PROXIMITY", "0.0001")) GEOLOC_PROXIMITY = Decimal(getattr(settings, "GEOLOC_PROXIMITY", "0.0001"))
@dataclass
class GeoLocationLogData(BaseLogData, WithPeopleLogData):
pass
class GeoLocation(ScrobblableMixin): class GeoLocation(ScrobblableMixin):
COMPLETION_PERCENT = getattr(settings, "LOCATION_COMPLETION_PERCENT", 100) COMPLETION_PERCENT = getattr(settings, "LOCATION_COMPLETION_PERCENT", 100)
@ -39,6 +44,10 @@ class GeoLocation(ScrobblableMixin):
"locations:geolocation_detail", kwargs={"slug": self.uuid} "locations:geolocation_detail", kwargs={"slug": self.uuid}
) )
@property
def logdata_cls(self):
return GeoLocationLogData
@classmethod @classmethod
def find_or_create(cls, data_dict: Dict) -> "GeoLocation": def find_or_create(cls, data_dict: Dict) -> "GeoLocation":
"""Given a data dict from GPSLogger, does the heavy lifting of looking up """Given a data dict from GPSLogger, does the heavy lifting of looking up

View File

@ -42,7 +42,7 @@ class Mood(ScrobblableMixin):
return str(self.uuid) return str(self.uuid)
def get_absolute_url(self): def get_absolute_url(self):
return reverse("moods:mood-detail", kwargs={"slug": self.uuid}) return reverse("moods:mood_detail", kwargs={"slug": self.uuid})
@property @property
def subtitle(self) -> str: def subtitle(self) -> str:

View File

@ -5,10 +5,10 @@ app_name = "moods"
urlpatterns = [ urlpatterns = [
path("moods/", views.MoodListView.as_view(), name="mood-list"), path("moods/", views.MoodListView.as_view(), name="mood_list"),
path( path(
"moods/<slug:slug>/", "moods/<slug:slug>/",
views.MoodDetailView.as_view(), views.MoodDetailView.as_view(),
name="mood-detail", name="mood_detail",
), ),
] ]

View File

@ -1,6 +1,7 @@
from django.views import generic from django.views import generic
from podcasts.models import Podcast from podcasts.models import Podcast
from scrobbles.views import ScrobbleableListView, ScrobbleableDetailView
class PodcastListView(generic.ListView): class PodcastListView(generic.ListView):
model = Podcast model = Podcast

View File

@ -72,7 +72,7 @@ class MoodNtfyNotification(BasicNtfyNotification):
def __init__(self, profile, **kwargs): def __init__(self, profile, **kwargs):
super().__init__(profile) super().__init__(profile)
self.ntfy_str: str = "Would you like to check in about your mood?" self.ntfy_str: str = "Would you like to check in about your mood?"
self.click_url = self.url_tmpl.format(path=reverse("moods:mood-list")) self.click_url = self.url_tmpl.format(path=reverse("moods:mood_list"))
self.title = "Mood Check-in!" self.title = "Mood Check-in!"
def send(self): def send(self):

View File

@ -55,7 +55,7 @@
<thead> <thead>
<tr> <tr>
<th scope="col">Date</th> <th scope="col">Date</th>
<th scope="col">Publisher</th> <th scope="col">Location</th>
<th scope="col">Players</th> <th scope="col">Players</th>
</tr> </tr>
</thead> </thead>
@ -63,7 +63,7 @@
{% for scrobble in scrobbles.all|dictsortreversed:"timestamp" %} {% for scrobble in scrobbles.all|dictsortreversed:"timestamp" %}
<tr> <tr>
<td><a href={{scrobble.get_absolute_url}}>{{scrobble.local_timestamp}}</a></td> <td><a href={{scrobble.get_absolute_url}}>{{scrobble.local_timestamp}}</a></td>
<td>{{scrobble.media_obj.publisher}}</td> <td>{{scrobble.logdata.location }}</td>
<td>{% if scrobble.logdata.player_log %}{{scrobble.logdata.player_log}}{% else %}No data{% endif %}</td> <td>{% if scrobble.logdata.player_log %}{{scrobble.logdata.player_log}}{% else %}No data{% endif %}</td>
</tr> </tr>
{% endfor %} {% endfor %}

View File

@ -17,12 +17,16 @@
<thead> <thead>
<tr> <tr>
<th scope="col">Date</th> <th scope="col">Date</th>
<th scope="col">Calories</th>
<th scope="col">Notes</th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
{% for scrobble in scrobbles.all %} {% for scrobble in scrobbles.all %}
<tr> <tr>
<td><a href={{scrobble.get_absolute_url}}>{{scrobble.local_timestamp}}</a></td> <td><a href={{scrobble.get_absolute_url}}>{{scrobble.local_timestamp}}</a></td>
<td>{% if scrobble.logdata.calories %}{{scrobble.logdata.calories}}{% else %}{{scrobble.media_obj.calories}}{% endif %}</td>
<td>{% for note in scrobble.logdata.notes %}{{note}}{% if not forloop.last %}; {% endif%}{% endfor %}
</tr> </tr>
{% endfor %} {% endfor %}
</tbody> </tbody>

View File

@ -57,12 +57,16 @@
<thead> <thead>
<tr> <tr>
<th scope="col">Date</th> <th scope="col">Date</th>
<th scope="col">With</th>
<th scope="col">Notes</th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
{% for scrobble in scrobbles.all|dictsortreversed:"timestamp" %} {% for scrobble in object.scrobble_set.all|dictsortreversed:"timestamp" %}
<tr> <tr>
<td><a href={{scrobble.get_absolute_url}}>{{scrobble.local_timestamp}}</a></td> <td><a href={{scrobble.get_absolute_url}}>{{scrobble.local_timestamp}}</a></td>
<td>{% for person in scrobble.logdata.with_people%}{{person}}{% if not forloop.last %}, {% endif%}{% endfor %}</td>
<td>{% for note in scrobble.logdata.notes %}{{note}}{% if not forloop.last %}; {% endif%}{% endfor %}
</tr> </tr>
{% endfor %} {% endfor %}
</tbody> </tbody>

View File

@ -1,5 +1,6 @@
{% extends "base_list.html" %} {% extends "base_list.html" %}
{% block title %}Podcasts{% endblock %}
{% block lists %} {% block lists %}
<div class="row"> <div class="row">
<div class="col-md"> <div class="col-md">
@ -7,20 +8,19 @@
<table class="table table-striped table-sm"> <table class="table table-striped table-sm">
<thead> <thead>
<tr> <tr>
<th scope="col">Series</th>
<th scope="col">Episode</th> <th scope="col">Episode</th>
<th scope="col">Podcast</th>
<th scope="col">Scrobbles</th> <th scope="col">Scrobbles</th>
<th scope="col">All time</th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
{% for obj in object_list %} {% for obj in object_list.all %}
{% for episode in obj.episode_set.all %} {{obj.episodes}}
{% for episode in obj.podcastepisode_set.all %}
<tr> <tr>
<td><a href="{{episode.get_absolute_url}}">{{episode}}</a></td> <td><a href="{{episode.get_absolute_url}}">{{episode}}</a></td>
<td><a href="{{obj.get_absolute_url}}">{{obj}}</a></td> <td><a href="{{obj.get_absolute_url}}">{{obj}}</a></td>
<td>{{episode.scrobble_set.count}}</td> <td>{{episode.scrobble_set.count}}</td>
<td></td>
</tr> </tr>
{% endfor %} {% endfor %}
{% endfor %} {% endfor %}

View File

@ -123,7 +123,7 @@
{% include "scrobbles/_scrobble_table.html" %} {% include "scrobbles/_scrobble_table.html" %}
{% endwith %} {% endwith %}
{% else %} {% else %}
<p>No books today</p> <p>No books read today</p>
{% endif %} {% endif %}
<h3><a href="{% url 'locations:geolocation_list' %}">Locations</a></h3> <h3><a href="{% url 'locations:geolocation_list' %}">Locations</a></h3>
@ -135,5 +135,14 @@
<p>No locations visited today</p> <p>No locations visited today</p>
{% endif %} {% endif %}
<h3><a href="{% url 'moods:mood_list' %}">Moods</a></h3>
{% if Mood %}
{% with scrobbles=Mood count=Mood_count time=Mood_time %}
{% include "scrobbles/_scrobble_table.html" %}
{% endwith %}
{% else %}
<p>No moods felt today </p>
{% endif %}
</div> </div>
</div> </div>

View File

@ -48,12 +48,14 @@
<thead> <thead>
<tr> <tr>
<th scope="col">Date</th> <th scope="col">Date</th>
<th scope="col">Notes</th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
{% for scrobble in scrobbles.all %} {% for scrobble in scrobbles.all %}
<tr> <tr>
<td><a href={{scrobble.get_absolute_url}}>{{scrobble.local_timestamp}}</a></td> <td><a href={{scrobble.get_absolute_url}}>{{scrobble.local_timestamp}}</a></td>
<td>{% for note in scrobble.logdata.notes %}{{note}}{% if not forloop.last %}; {% endif%}{% endfor %}
</tr> </tr>
{% endfor %} {% endfor %}
</tbody> </tbody>