Refactor campaign name handling to use clean_name property for improved clarity and consistency across templates

This commit is contained in:
Joakim Hellsén 2025-07-10 05:10:09 +02:00
commit 3fb0880271
5 changed files with 32 additions and 8 deletions

View file

@ -1,6 +1,6 @@
{% extends "base.html" %} {% extends "base.html" %}
{% block title %}{{ campaign.name }} - Twitch Drops Tracker{% endblock %} {% block title %}{{ campaign.clean_name }} - Twitch Drops Tracker{% endblock %}
{% block content %} {% block content %}
<div class="row mb-4"> <div class="row mb-4">
@ -9,7 +9,7 @@
<ol class="breadcrumb"> <ol class="breadcrumb">
<li class="breadcrumb-item"><a href="{% url 'twitch:dashboard' %}">Dashboard</a></li> <li class="breadcrumb-item"><a href="{% url 'twitch:dashboard' %}">Dashboard</a></li>
<li class="breadcrumb-item"><a href="{% url 'twitch:campaign_list' %}">Campaigns</a></li> <li class="breadcrumb-item"><a href="{% url 'twitch:campaign_list' %}">Campaigns</a></li>
<li class="breadcrumb-item active" aria-current="page">{{ campaign.name }}</li> <li class="breadcrumb-item active" aria-current="page">{{ campaign.clean_name }}</li>
</ol> </ol>
</nav> </nav>
</div> </div>
@ -17,7 +17,7 @@
<div class="row mb-4"> <div class="row mb-4">
<div class="col-md-8"> <div class="col-md-8">
<h1 class="mb-3">{{ campaign.name }}</h1> <h1 class="mb-3">{{ campaign.clean_name }}</h1>
<div class="d-flex flex-wrap gap-2 mb-3"> <div class="d-flex flex-wrap gap-2 mb-3">
<a href="{% url 'twitch:game_detail' campaign.game.id %}" class="badge bg-primary text-decoration-none"> <a href="{% url 'twitch:game_detail' campaign.game.id %}" class="badge bg-primary text-decoration-none">
<i class="fas fa-gamepad me-1"></i>{{ campaign.game.display_name }} <i class="fas fa-gamepad me-1"></i>{{ campaign.game.display_name }}

View file

@ -79,7 +79,7 @@
alt="{{ campaign.name }}"> alt="{{ campaign.name }}">
{% endif %} {% endif %}
<div class="card-body"> <div class="card-body">
<h5 class="card-title">{{ campaign.name }}</h5> <h5 class="card-title">{{ campaign.clean_name }}</h5>
<h6 class="card-subtitle mb-2 text-muted">{{ campaign.game.display_name }} <h6 class="card-subtitle mb-2 text-muted">{{ campaign.game.display_name }}
</h6> </h6>
<p class="card-text small">{{ campaign.description|truncatewords:20 }}</p> <p class="card-text small">{{ campaign.description|truncatewords:20 }}</p>

View file

@ -38,7 +38,7 @@
<div class="title-wrapper" style="min-height: 2.4rem;"> <div class="title-wrapper" style="min-height: 2.4rem;">
<h6 class="mb-1" title="{{ campaign.name }}" <h6 class="mb-1" title="{{ campaign.name }}"
style="display: -webkit-box; display: box; -webkit-line-clamp: 2; line-clamp: 2; -webkit-box-orient: vertical; box-orient: vertical; overflow: hidden; font-size: 0.9rem;"> style="display: -webkit-box; display: box; -webkit-line-clamp: 2; line-clamp: 2; -webkit-box-orient: vertical; box-orient: vertical; overflow: hidden; font-size: 0.9rem;">
{{ campaign.name }}</h6> {{ campaign.clean_name }}</h6>
</div> </div>
<p class="mb-1 small text-muted text-truncate"> <p class="mb-1 small text-muted text-truncate">
<a href="{% url 'twitch:game_detail' campaign.game.id %}" <a href="{% url 'twitch:game_detail' campaign.game.id %}"

View file

@ -39,7 +39,7 @@
<tbody> <tbody>
{% for campaign in active_campaigns %} {% for campaign in active_campaigns %}
<tr> <tr>
<td>{{ campaign.name }}</td> <td>{{ campaign.clean_name }}</td>
<td>{{ campaign.owner.name }}</td> <td>{{ campaign.owner.name }}</td>
<td> <td>
<span class="badge bg-success" data-bs-toggle="tooltip" <span class="badge bg-success" data-bs-toggle="tooltip"
@ -85,7 +85,7 @@
<tbody> <tbody>
{% for campaign in upcoming_campaigns %} {% for campaign in upcoming_campaigns %}
<tr> <tr>
<td>{{ campaign.name }}</td> <td>{{ campaign.clean_name }}</td>
<td>{{ campaign.owner.name }}</td> <td>{{ campaign.owner.name }}</td>
<td> <td>
<span class="badge bg-info text-dark" data-bs-toggle="tooltip" <span class="badge bg-info text-dark" data-bs-toggle="tooltip"
@ -131,7 +131,7 @@
<tbody> <tbody>
{% for campaign in expired_campaigns %} {% for campaign in expired_campaigns %}
<tr> <tr>
<td>{{ campaign.name }}</td> <td>{{ campaign.clean_name }}</td>
<td>{{ campaign.owner.name }}</td> <td>{{ campaign.owner.name }}</td>
<td> <td>
<span class="badge bg-secondary" data-bs-toggle="tooltip" <span class="badge bg-secondary" data-bs-toggle="tooltip"

View file

@ -67,6 +67,30 @@ class DropCampaign(models.Model):
now = timezone.now() now = timezone.now()
return self.start_at <= now <= self.end_at and self.status == "ACTIVE" return self.start_at <= now <= self.end_at and self.status == "ACTIVE"
@property
def clean_name(self) -> 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): class DropBenefit(models.Model):
"""Represents a benefit that can be earned from a drop.""" """Represents a benefit that can be earned from a drop."""