From a79cc4c217f95571ab3afd3f1d647e61095de79c Mon Sep 17 00:00:00 2001 From: Colin Powell Date: Tue, 24 Mar 2026 15:45:10 -0400 Subject: [PATCH] [scrobbles] Clean up notes on webpages --- vrobbler/apps/scrobbles/dataclasses.py | 27 +++-- .../apps/scrobbles/templatetags/form_tags.py | 18 +++ vrobbler/apps/webpages/views.py | 4 + .../templates/webpages/webpage_detail.html | 103 +++++++++++++++--- 4 files changed, 126 insertions(+), 26 deletions(-) diff --git a/vrobbler/apps/scrobbles/dataclasses.py b/vrobbler/apps/scrobbles/dataclasses.py index 945c25e..9bc8a1e 100644 --- a/vrobbler/apps/scrobbles/dataclasses.py +++ b/vrobbler/apps/scrobbles/dataclasses.py @@ -50,20 +50,25 @@ class BaseLogData(JSONDataclass): def override_fields(cls) -> dict: return {} - def notes_as_str(self) -> str: - note_str = "" + def notes_as_str(self, separator: str = " | ") -> str: + import re if not self.notes: - return note_str + return "" - if self.notes: - if isinstance(self.notes, str): - note_str = self.notes.encode("utf-8").decode("unicode_escape") - if isinstance(self.notes, list): - note_str = ( - "\n".join(self.notes).encode("utf-8").decode("unicode_escape") - ) - return note_str + if isinstance(self.notes, str): + note_str = self.notes.encode("utf-8").decode("unicode_escape") + return re.sub(r"\s*\[start:\d+\|end:\d+\]$", "", note_str) + + if isinstance(self.notes, list): + cleaned_notes = [] + for note in self.notes: + cleaned = note.encode("utf-8").decode("unicode_escape") + cleaned = re.sub(r"\s*\[start:\d+\|end:\d+\]$", "", cleaned) + cleaned_notes.append(cleaned) + return separator.join(cleaned_notes) + + return "" def notes_as_html(self) -> str: if not self.notes: diff --git a/vrobbler/apps/scrobbles/templatetags/form_tags.py b/vrobbler/apps/scrobbles/templatetags/form_tags.py index 53c3d76..3caf53a 100644 --- a/vrobbler/apps/scrobbles/templatetags/form_tags.py +++ b/vrobbler/apps/scrobbles/templatetags/form_tags.py @@ -1,3 +1,4 @@ +import re from datetime import datetime from django import template @@ -15,3 +16,20 @@ def add_class(field, css_class): @register.simple_tag def current_date(format): return datetime.now().strftime(format) + + +@register.filter +def note_position(note, article_length): + if not article_length or article_length == 0: + return "" + match = re.search(r"start:(\d+)", note) + if match: + start = int(match.group(1)) + percentage = (start / article_length) * 100 + return f"style='top: {percentage}%'" + return "" + + +@register.filter +def note_text(note): + return re.sub(r"\s*\[start:\d+\|end:\d+\]$", "", note) diff --git a/vrobbler/apps/webpages/views.py b/vrobbler/apps/webpages/views.py index 9f6c5a2..ad9ed0d 100644 --- a/vrobbler/apps/webpages/views.py +++ b/vrobbler/apps/webpages/views.py @@ -73,6 +73,10 @@ class WebPageDetailView(ScrobbleableDetailView): context["latest_scrobble_uuid"] = str(latest.uuid) notes = latest.log.get("notes", []) if latest.log else [] context["latest_scrobble_notes"] = notes + context["latest_scrobble_notes_html"] = latest.logdata.notes_as_html() + context["article_length"] = ( + len(self.object.extract) if self.object.extract else 0 + ) return context diff --git a/vrobbler/templates/webpages/webpage_detail.html b/vrobbler/templates/webpages/webpage_detail.html index 0561ea7..0a289ba 100644 --- a/vrobbler/templates/webpages/webpage_detail.html +++ b/vrobbler/templates/webpages/webpage_detail.html @@ -1,18 +1,77 @@ {% extends "base_list.html" %} {% load static %} +{% load form_tags %} {% block title %}{{object.title}}{% endblock %} {% block head_extra %} {% endblock %} {% block extra_js %} +