Add Twitch directory URL property to Game model and update dashboard to handle channel display logic
This commit is contained in:
parent
fc52a94284
commit
c8cc6d83df
2 changed files with 44 additions and 24 deletions
|
|
@ -85,20 +85,19 @@ Hover over the end time to see the exact date and time.
|
|||
text-align: left">
|
||||
Duration: {{ campaign.start_at|timesince:campaign.end_at }}
|
||||
</time>
|
||||
{% if campaign.allow_channels.all %}
|
||||
<div style="margin-top: 0.5rem; font-size: 0.8rem; color: #444;">
|
||||
<strong>Channels:</strong>
|
||||
<ul style="margin: 0.25rem 0 0 0;
|
||||
padding-left: 1rem;
|
||||
list-style-type: none">
|
||||
{% if campaign.allow_is_enabled %}
|
||||
{% if campaign.allow_channels.all %}
|
||||
{% for channel in campaign.allow_channels.all %}
|
||||
{% if forloop.counter <= 5 %}
|
||||
<li style="margin-bottom: 0.1rem;">
|
||||
<a href="https://twitch.tv/{{ channel.name }}"
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
style="color: #9146ff;
|
||||
text-decoration: none"
|
||||
title="Watch {{ channel.display_name }} on Twitch">
|
||||
{{ channel.display_name }}
|
||||
</a>
|
||||
|
|
@ -110,9 +109,23 @@ Hover over the end time to see the exact date and time.
|
|||
... and {{ campaign.allow_channels.all|length|add:"-5" }} more
|
||||
</li>
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
{% else %}
|
||||
{% if campaign.game.twitch_directory_url %}
|
||||
<li>
|
||||
<a href="{{ campaign.game.twitch_directory_url }}"
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
title="Find streamers playing {{ campaign.game.display_name }} with drops enabled">
|
||||
Go to a participating live channel
|
||||
</a>
|
||||
</li>
|
||||
{% else %}
|
||||
<li>Failed to get Twitch directory URL :(</li>
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
</ul>
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
</article>
|
||||
{% endfor %}
|
||||
|
|
|
|||
|
|
@ -172,6 +172,13 @@ class Game(models.Model):
|
|||
return self.slug
|
||||
return self.id
|
||||
|
||||
@property
|
||||
def twitch_directory_url(self) -> str:
|
||||
"""Return the Twitch directory URL for this game with drops filter if slug is available."""
|
||||
if self.slug:
|
||||
return f"https://www.twitch.tv/directory/category/{self.slug}?filter=drops"
|
||||
return ""
|
||||
|
||||
|
||||
class Channel(models.Model):
|
||||
"""Represents a Twitch channel that can participate in drop campaigns."""
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue