From 3fb0880271986eaefa954f1a85becbf13cd288b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joakim=20Hells=C3=A9n?= Date: Thu, 10 Jul 2025 05:10:09 +0200 Subject: [PATCH] Refactor campaign name handling to use clean_name property for improved clarity and consistency across templates --- templates/twitch/campaign_detail.html | 6 +++--- templates/twitch/campaign_list.html | 2 +- templates/twitch/dashboard.html | 2 +- templates/twitch/game_detail.html | 6 +++--- twitch/models.py | 24 ++++++++++++++++++++++++ 5 files changed, 32 insertions(+), 8 deletions(-) diff --git a/templates/twitch/campaign_detail.html b/templates/twitch/campaign_detail.html index e131097..3b2eaae 100644 --- a/templates/twitch/campaign_detail.html +++ b/templates/twitch/campaign_detail.html @@ -1,6 +1,6 @@ {% extends "base.html" %} -{% block title %}{{ campaign.name }} - Twitch Drops Tracker{% endblock %} +{% block title %}{{ campaign.clean_name }} - Twitch Drops Tracker{% endblock %} {% block content %}
@@ -9,7 +9,7 @@
@@ -17,7 +17,7 @@
-

{{ campaign.name }}

+

{{ campaign.clean_name }}

{{ campaign.game.display_name }} diff --git a/templates/twitch/campaign_list.html b/templates/twitch/campaign_list.html index 36a74b8..c616a1d 100644 --- a/templates/twitch/campaign_list.html +++ b/templates/twitch/campaign_list.html @@ -79,7 +79,7 @@ alt="{{ campaign.name }}"> {% endif %}
-
{{ campaign.name }}
+
{{ campaign.clean_name }}
{{ campaign.game.display_name }}

{{ campaign.description|truncatewords:20 }}

diff --git a/templates/twitch/dashboard.html b/templates/twitch/dashboard.html index abdc843..ded57b1 100644 --- a/templates/twitch/dashboard.html +++ b/templates/twitch/dashboard.html @@ -38,7 +38,7 @@
- {{ campaign.name }}
+ {{ campaign.clean_name }}

{% for campaign in active_campaigns %} - {{ campaign.name }} + {{ campaign.clean_name }} {{ campaign.owner.name }} {% for campaign in upcoming_campaigns %} - {{ campaign.name }} + {{ campaign.clean_name }} {{ campaign.owner.name }} {% for campaign in expired_campaigns %} - {{ campaign.name }} + {{ campaign.clean_name }} {{ campaign.owner.name }} str: + """Return the campaign name without the game name prefix. + + Examples: + "Ravendawn - July 2" -> "July 2" + "Party Animals Twitch Drop" -> "Twitch Drop" + """ + if not self.game or not self.game.display_name: + return self.name + + game_name = self.game.display_name + + # Remove game name if it's at the beginning of the campaign name + if self.name.startswith(game_name): + # Check if it's followed by a separator like " - " + if self.name[len(game_name) :].startswith(" - "): + return self.name[len(game_name) + 3 :].strip() + # Or just remove the game name if it's followed by a space + if len(self.name) > len(game_name) and self.name[len(game_name)] == " ": + return self.name[len(game_name) + 1 :].strip() + + return self.name + class DropBenefit(models.Model): """Represents a benefit that can be earned from a drop."""