Refactor models
This commit is contained in:
@ -1,106 +1,111 @@
|
||||
{% extends "base.html" %}
|
||||
{% load custom_filters static time_filters %}
|
||||
{% block content %}
|
||||
<div class="container mt-4">
|
||||
{% include "partials/info_box.html" %}
|
||||
<!-- Drop Campaigns Section -->
|
||||
<section class="drop-campaigns">
|
||||
<h2>
|
||||
Drop Campaigns -
|
||||
<span class="d-inline text-muted">{{ games.count }} game{{ games.count|pluralize }}</span>
|
||||
</h2>
|
||||
<!-- Loop through games -->
|
||||
{% for game in games %}
|
||||
<div class="card mb-4 shadow-sm">
|
||||
<div class="row g-0">
|
||||
<!-- Game Box Art -->
|
||||
<div class="col-md-2">
|
||||
<img src="{{ game.box_art_url|default:'https://static-cdn.jtvnw.net/ttv-static/404_boxart.jpg' }}"
|
||||
alt="{{ game.name|default:'Game name unknown' }} box art"
|
||||
class="img-fluid rounded-start"
|
||||
height="283"
|
||||
width="212"
|
||||
loading="lazy" />
|
||||
</div>
|
||||
<!-- Game Details -->
|
||||
<div class="col-md-10">
|
||||
<div class="card-body">
|
||||
<h2 class="card-title h5">
|
||||
<a href="{% url 'game' game.twitch_id %}" class="text-decoration-none">{{ game.name|default:'Unknown' }}</a>
|
||||
-
|
||||
<a href="https://www.twitch.tv/directory/category/{{ game.slug|default:'game-name-unknown' }}"
|
||||
class="text-decoration-none text-muted">Twitch</a>
|
||||
</h2>
|
||||
<!-- Loop through campaigns for each game -->
|
||||
{% for campaign in game.drop_campaigns.all %}
|
||||
<div class="mt-4">
|
||||
<h4 class="h6">{{ campaign.name }}</h4>
|
||||
<a href="{{ campaign.details_url }}" class="text-decoration-none">Details</a>
|
||||
{% if campaign.details_url != campaign.account_link_url %}
|
||||
| <a href="{{ campaign.account_link_url }}" class="text-decoration-none">Link Account</a>
|
||||
{% endif %}
|
||||
<p class="mb-2 text-muted">
|
||||
Ends in:
|
||||
<abbr title="{{ campaign.starts_at|date:'l d F H:i' }} - {{ campaign.ends_at|date:'l d F H:i' }}">
|
||||
{{ campaign.ends_at|timeuntil }}
|
||||
</abbr>
|
||||
</p>
|
||||
<!-- Drop Benefits Table -->
|
||||
<div class="table-responsive">
|
||||
<table class="table table-striped table-hover align-middle">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Benefit Image</th>
|
||||
<th>Benefit Name</th>
|
||||
<th>Required Minutes Watched</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for drop in campaign.drops.all %}
|
||||
{% if drop.benefits.exists %}
|
||||
{% for benefit in drop.benefits.all %}
|
||||
<tr>
|
||||
<td>
|
||||
<img src="{{ benefit.image_url|default:'https://static-cdn.jtvnw.net/ttv-static/404_boxart.jpg' }}"
|
||||
alt="{{ benefit.name|default:'Unknown' }}"
|
||||
class="img-fluid rounded"
|
||||
height="50"
|
||||
width="50"
|
||||
loading="lazy" />
|
||||
</td>
|
||||
<td>
|
||||
<abbr title="{{ drop.name|default:'Unknown' }}">
|
||||
{{ benefit.name|default:'Unknown' }}
|
||||
</abbr>
|
||||
</td>
|
||||
<td>{{ drop.required_minutes_watched|minutes_to_hours }}</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
{% else %}
|
||||
<tr>
|
||||
<td>
|
||||
<img src="https://static-cdn.jtvnw.net/ttv-static/404_boxart.jpg"
|
||||
alt="{{ drop.name|default:'Unknown' }}"
|
||||
class="img-fluid rounded"
|
||||
height="50"
|
||||
width="50"
|
||||
loading="lazy" />
|
||||
</td>
|
||||
<td>{{ drop.name|default:'Unknown' }}</td>
|
||||
<td>N/A</td>
|
||||
</tr>
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
</div>
|
||||
<div class="container mt-4">
|
||||
{% include "partials/info_box.html" %}
|
||||
<!-- Drop Campaigns Section -->
|
||||
<section class="drop-campaigns">
|
||||
<h2>
|
||||
Drop Campaigns -
|
||||
<span class="d-inline text-muted">{{ grouped_drops|length }} game{{ grouped_drops|length|pluralize }}</span>
|
||||
</h2>
|
||||
{% if grouped_drops %}
|
||||
{% for game, drops_list in grouped_drops.items %}
|
||||
{# Retain card structure for layout, replace table with list #}
|
||||
<div class="card mb-4 shadow-sm">
|
||||
<div class="row g-0">
|
||||
<!-- Game Box Art -->
|
||||
<div class="col-md-2">
|
||||
{% if game and game.box_art_url %}
|
||||
<img src="{{ game.box_art_url }}" alt="{{ game.display_name|default:'Game name unknown' }} box art"
|
||||
class="img-fluid rounded-start" height="283" width="212" loading="lazy" />
|
||||
{% else %}
|
||||
<img src="{% static 'images/404_boxart.jpg' %}"
|
||||
alt="{% if game %}{{ game.display_name }}{% else %}Unknown Game{% endif %} box art"
|
||||
class="img-fluid rounded-start" height="283" width="212" loading="lazy" />
|
||||
{% endif %}
|
||||
</div>
|
||||
<!-- Game Details -->
|
||||
<div class="col-md-10">
|
||||
<div class="card-body">
|
||||
<h2 class="card-title h5">
|
||||
{% if game %}
|
||||
<a href="{% if game.game_id %}{% url 'game_detail' game.game_id %}{% else %}#{% endif %}"
|
||||
class="text-decoration-none">{{ game.display_name|default:'Unknown Game' }}</a>
|
||||
{% if game.slug %}
|
||||
- <a href="https://www.twitch.tv/directory/category/{{ game.slug }}"
|
||||
class="text-decoration-none text-muted">Twitch</a>
|
||||
{% endif %}
|
||||
{% else %}
|
||||
Drops without an associated Game
|
||||
{% endif %}
|
||||
</h2>
|
||||
|
||||
{% if drops_list %}
|
||||
<!-- NEW Drop List Structure -->
|
||||
<ul class="list-unstyled mt-3">
|
||||
{% for drop in drops_list %}
|
||||
<li class="mb-3"> {# Add margin between list items #}
|
||||
<strong>{{ drop.name|default:'Unknown Drop' }}</strong>
|
||||
(Requires {{ drop.required_minutes_watched|minutes_to_hours }})
|
||||
<br>
|
||||
<em>Campaign:
|
||||
<a href="{{ drop.campaign.details_url|default:'#' }}" class="text-decoration-none"
|
||||
title="{{ drop.campaign.name|default:'Unknown Campaign' }}">
|
||||
{{ drop.campaign.name|truncatechars:40|default:'N/A' }} {# Adjusted truncate #}
|
||||
</a>
|
||||
{% if drop.campaign.details_url != drop.campaign.account_link_url and drop.campaign.account_link_url %}
|
||||
| <a href="{{ drop.campaign.account_link_url }}" class="text-decoration-none"
|
||||
title="Link Account for {{ drop.campaign.name }}">Link</a>
|
||||
{% endif %}
|
||||
</em>
|
||||
<br>
|
||||
Ends in: <abbr
|
||||
title="{{ drop.campaign.start_at|date:'l d F H:i' }} - {{ drop.campaign.end_at|date:'l d F H:i' }}">
|
||||
{{ drop.campaign.end_at|timeuntil }}
|
||||
</abbr>
|
||||
|
||||
{% if drop.benefits.exists %}
|
||||
<br>
|
||||
Benefits:
|
||||
<ul class="list-inline">
|
||||
{% for benefit in drop.benefits.all %}
|
||||
<li class="list-inline-item">
|
||||
<abbr title="{{ benefit.name|default:'Unknown Benefit' }}">
|
||||
{% if benefit.image_asset_url %}
|
||||
<img src="{{ benefit.image_asset_url|default:'https://static-cdn.jtvnw.net/ttv-static/404_boxart.jpg' }}"
|
||||
alt="{{ benefit.name|default:'Unknown Benefit' }}"
|
||||
class="img-fluid rounded me-1 align-middle" {# Added align-middle #}
|
||||
height="20" width="20" loading="lazy" />
|
||||
{% endif %}
|
||||
<small>{{ benefit.name|truncatechars:25|default:'Unknown Benefit' }}</small>
|
||||
{# Wrap text in small #}
|
||||
</abbr>
|
||||
</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
{% endif %}
|
||||
{# Removed hr, using li margin instead #}
|
||||
</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
{% else %}
|
||||
<p class="mt-3 text-muted">No active drops found for this game currently.</p>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
{% endfor %}
|
||||
</section>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% empty %}
|
||||
<div class="alert alert-info" role="alert">
|
||||
There are currently no active Twitch drops found matching the criteria.
|
||||
</div>
|
||||
{% endfor %}
|
||||
{% else %}
|
||||
<div class="alert alert-info" role="alert">
|
||||
There are currently no active Twitch drops found.
|
||||
</div>
|
||||
{% endif %}
|
||||
</section>
|
||||
</div>
|
||||
{% endblock content %}
|
||||
|
Reference in New Issue
Block a user