Admin can choose different amount of ranks for every ranking timeline.
Ranking timelines are now appended to the database, allowing for a
ranking timeline history.
Message is now sent under the form when sending a clip, rather than
going to a new page.
Staff now has admin access, not just super user.
--- /dev/null
+# Generated by Django 4.1.5 on 2023-01-23 00:22
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ("manager", "0011_clip_rank"),
+ ]
+
+ operations = [
+ migrations.AddField(
+ model_name="resetdata",
+ name="ranks",
+ field=models.IntegerField(default=5),
+ ),
+ ]
class ResetData(models.Model):
date_time = models.DateTimeField()
max_clips = models.IntegerField(default=2)
+ ranks = models.IntegerField(default=5)
class Clip(models.Model):
def request_clip(user, clip: str):
id = urlparse(clip).path.split("/")[-1]
user = User.objects.get(id=user.id)
- reset_data = ResetData.objects.first()
+ reset_data = ResetData.objects.latest('date_time')
reset_time = reset_data.date_time
+ print(reset_time)
max_clips = reset_data.max_clips
if (
src="https://clips.twitch.tv/embed?clip={{ video.id }}&parent=localhost"
height="600"
width="1000"
+ preload="auto"
allowfullscreen>
</iframe>
<div id="buttons">
<form method="post">
{% csrf_token %}
- <button class="rank-btn r5" name="value" value="5">Rank 5</button>
- <button class="rank-btn r4" name="value" value="4">Rank 4</button>
- <button class="rank-btn r3" name="value" value="3">Rank 3</button>
- <button class="rank-btn r2" name="value" value="2">Rank 2</button>
- <button class="rank-btn r1" name="value" value="1">Rank 1</button>
+ {% for i in ranks %}
+ <button class="rank-btn r{{ i }}" name="value" value="{{ i }}">Rank {{ i }}</button>
+ {% endfor %}
</form>
</div>
</div>
{% extends 'base.html' %}
{% block content %}
<table id="final-ranks">
+ {% for i in ranks %}
<tr>
- <th>Rank 5</th>
+ <th>Rank {{ i }}</th>
{% for video in videos %}
- {% if video.rank == 5 %}
- <td>
- <iframe
- src="https://clips.twitch.tv/embed?clip={{ video.id }}&parent=localhost"
- height="180"
- width="320"
- allowfullscreen>
- </iframe>
- </td>
- {% endif %}
- {% endfor %}
- </tr>
- <tr>
- <th>Rank 4</th>
- {% for video in videos %}
- {% if video.rank == 4 %}
- <td>
- <iframe
- src="https://clips.twitch.tv/embed?clip={{ video.id }}&parent=localhost"
- height="180"
- width="320"
- allowfullscreen>
- </iframe>
- </td>
- {% endif %}
- {% endfor %}
- </tr>
- <tr>
- <th>Rank 3</th>
- {% for video in videos %}
- {% if video.rank == 3 %}
- <td>
- <iframe
- src="https://clips.twitch.tv/embed?clip={{ video.id }}&parent=localhost"
- height="180"
- width="320"
- allowfullscreen>
- </iframe>
- </td>
- {% endif %}
- {% endfor %}
- </tr>
- <tr>
- <th>Rank 2</th>
- {% for video in videos %}
- {% if video.rank == 2 %}
- <td>
- <iframe
- src="https://clips.twitch.tv/embed?clip={{ video.id }}&parent=localhost"
- height="180"
- width="320"
- allowfullscreen>
- </iframe>
- </td>
- {% endif %}
- {% endfor %}
- </tr>
- <tr>
- <th>Rank 1</th>
- {% for video in videos %}
- {% if video.rank == 1 %}
+ {% if video.rank == i %}
<td>
<iframe
src="https://clips.twitch.tv/embed?clip={{ video.id }}&parent=localhost"
height="180"
width="320"
+ preload="none"
allowfullscreen>
</iframe>
</td>
{% endif %}
{% endfor %}
</tr>
+ {% endfor %}
</table>
{% endblock %}
<input id="clip" type="text" name="clip">
<button>Submit Clip</button>
</form>
+ {{ message }}
{% else %}
<h1>Welcome Friend, please log in</h1>
{% endif %}
@staff_member_required
def show_clips(request, id):
- reset_data = ResetData.objects.first()
+ reset_data = ResetData.objects.latest('date_time')
reset_time = reset_data.date_time
+ print(reset_time)
try:
video = Clip.objects.filter(date_added__gt=reset_time)[id - 1]
except IndexError:
return redirect(show_clips, id=id + 1)
return render(request, "manager/clip_viewer.html", context={
"video": video,
+ "ranks": range(reset_data.ranks, 0, -1),
})
@staff_member_required
def final_ranking(request):
- reset_data = ResetData.objects.first()
+ reset_data = ResetData.objects.latest('date_time')
reset_time = reset_data.date_time
+ print(reset_time)
return render(request, "manager/final.html", context={
"videos": Clip.objects.filter(date_added__gt=reset_time),
+ "ranks": range(reset_data.ranks, 0, -1),
})
if form.is_valid():
try:
request_clip(user=request.user, clip=form.cleaned_data["clip"])
- except ValidationError as e:
- print(e)
- return HttpResponse(b"<h1>Clip already exists</h1>")
+ except ValidationError:
+ message = "Sorry, clip already exists. Please send another clip."
+ return render(request, "manager/index.html", {"message": message})
+ # return HttpResponse(b"<h1>Clip already exists</h1>")
except TooManyClips:
- return HttpResponse(b"<h1>You have submitted the maximum number of clips</h1>")
- except Exception as e:
- print(e)
- return HttpResponse(b"<h1>NOPE</h1>")
+ message = "Sorry, you have already reached the clip limit."
+ return render(request, "manager/index.html", {"message": message})
+ # return HttpResponse(b"<h1>You have submitted the maximum number of clips</h1>")
+ except Exception:
+ message = "Something went wrong."
+ return render(request, "manager/index.html", {"message": message})
+ # return HttpResponse(b"<h1>NOPE</h1>")
# process the data in form.cleaned_data as required
# ...
# redirect to a new URL:
- return HttpResponse(b"<h1>THANKS</h1>")
+ message = "Thank you for submitting a clip."
+ return render(request, "manager/index.html", {"message": message})
# return HttpResponseRedirect("/thanks/")
else:
print("invalid")
#buttons {
padding-top: 2rem;
+ width: 1000px;
+}
+
+#buttons form {
+ width: 100%;
+ display: flex;
+ justify-content: space-between;
}
.rank-btn {
cursor: pointer;
}
+.rank-btn.r8 {
+ background-color: #9BED72;
+}
+
+.rank-btn.r7 {
+ background-color: #72ED73;
+}
+
+.rank-btn.r6 {
+ background-color: #72ED9D;
+}
+
.rank-btn.r5 {
- background-color: #4CAF50;
+ background-color: #72EDC8;
}
.rank-btn.r4 {
- background-color: #8CAF50;
+ background-color: #72E8ED;
}
.rank-btn.r3 {
- background-color: #FCAF50;
+ background-color: #72BEED;
}
.rank-btn.r2 {
- background-color: #FFAFF0;
+ background-color: #7294ED;
}
.rank-btn.r1 {
- background-color: #FC0F50;
+ background-color: #7A72ED;
}
.rank-btn:hover {
- background-color: #EEEEEE;
+ background-color: #EAFCFA;
}
.rank-btn:active {
- background-color: #111111;
+ background-color: #84EEE0;
color: #DDD;
}
<body>
<div class="sidenav">
<a class="btn" href="{% url 'index' %}">Home</a>
- {% if user.is_superuser %}
+ {% if user.is_staff %}
<a class="btn" href="{% url 'show' 1 %}">Rank</a>
{% endif %}
- {% if user.is_superuser %}
+ {% if user.is_staff %}
<a class="btn" href="{% url 'admin:index' %}">Admin</a>
{% endif %}
- {% if user.is_superuser %}
+ {% if user.is_staff %}
<a class="btn" href="{% url 'final' %}">Results</a>
{% endif %}
{% if user.is_authenticated %}