from django.contrib import admin
from django.urls import path, include
from django.views.generic import TemplateView
-from manager.views import get_name
+from manager.views import get_name, show_clips, final_ranking
urlpatterns = [
path("admin/", admin.site.urls),
path('accounts/', include('allauth.urls')),
- path('', TemplateView.as_view(template_name="manager/index.html")),
+ path('', TemplateView.as_view(template_name="manager/index.html"), name='index'),
path('input/', get_name, name="input"),
+ path('show/<int:id>', show_clips, name="show"),
+ path('final', final_ranking, name="final"),
]
from django import forms
+class RankForm(forms.Form):
+ value = forms.IntegerField(label="rank")
+
+
class ClipForm(forms.Form):
clip = forms.CharField(label="clip", max_length=200)
--- /dev/null
+# Generated by Django 4.1.5 on 2023-01-22 16:24
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ("manager", "0010_rename_resettime_resetdata"),
+ ]
+
+ operations = [
+ migrations.AddField(
+ model_name="clip",
+ name="rank",
+ field=models.IntegerField(null=True),
+ ),
+ ]
vod_offset = models.IntegerField(null=True)
date_added = models.DateTimeField(null=True)
account = models.ForeignKey(User, on_delete=models.CASCADE)
+ rank = models.IntegerField(null=True)
--- /dev/null
+{% extends 'base.html' %}
+{% block content %}
+<div id="group">
+ <iframe
+ src="https://clips.twitch.tv/embed?clip={{ video.id }}&parent=localhost"
+ height="600"
+ width="1000"
+ 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>
+ </form>
+ </div>
+</div>
+{% endblock %}
+
--- /dev/null
+{% extends 'base.html' %}
+{% block content %}
+{% for video in videos %}
+{{ video.rank }}
+{% endfor %}
+{% endblock %}
+
-import requests
-
from django.http import HttpResponse
-from django.shortcuts import render
+from django.shortcuts import render, redirect
from django.core.exceptions import ValidationError
+from django.contrib.admin.views.decorators import staff_member_required
from .request_clip import request_clip
-from .forms import ClipForm
+from .forms import ClipForm, RankForm
from .errors import TooManyClips
+from .models import Clip, ResetData
+
+
+@staff_member_required
+def show_clips(request, id):
+ reset_data = ResetData.objects.first()
+ reset_time = reset_data.date_time
+ try:
+ video = Clip.objects.filter(date_added__gt=reset_time)[id - 1]
+ except IndexError:
+ print("hi")
+ return redirect(final_ranking)
+ if request.method == "POST":
+ form = RankForm(request.POST)
+ if form.is_valid():
+ print(f"post: {id} | {form.cleaned_data['value']}")
+ video.rank = form.cleaned_data["value"]
+ video.save()
+ return redirect(show_clips, id=id + 1)
+ return render(request, "manager/clip_viewer.html", context={
+ "video": video,
+ })
+
+
+@staff_member_required
+def final_ranking(request):
+ reset_data = ResetData.objects.first()
+ reset_time = reset_data.date_time
+ return render(request, "manager/final.html", context={
+ "videos": Clip.objects.filter(date_added__gt=reset_time),
+ })
def get_name(request):
padding-left: 20px;
}
+#group {
+ display: flex;
+ justify-content: center;
+ align-items: center;
+ min-height: 100vh;
+ flex-direction: column;
+
+}
+
+#buttons {
+ padding-top: 2rem;
+}
+
+.rank-btn {
+ border: none;
+ color: black;
+ padding: 15px 32px;
+ text-align: center;
+ text-decoration: none;
+ display: inline-block;
+ font-size: 24px;
+ cursor: pointer;
+}
+
+.rank-btn.r5 {
+ background-color: #4CAF50;
+}
+
+.rank-btn.r4 {
+ background-color: #8CAF50;
+}
+
+.rank-btn.r3 {
+ background-color: #FCAF50;
+}
+
+.rank-btn.r2 {
+ background-color: #FFAFF0;
+}
+
+.rank-btn.r1 {
+ background-color: #FC0F50;
+}
+
+.rank-btn:hover {
+ background-color: #EEEEEE;
+}
+
</head>
<body>
<div class="sidenav">
- <a class="btn" href="#">Home</a>
+ <a class="btn" href="{% url 'index' %}">Home</a>
{% if user.is_authenticated %}
- <a class="btn" href="#">Panel</a>
+ <a class="btn" href="{% url 'show' 1 %}">Rank</a>
{% endif %}
{% if user.is_superuser %}
<a class="btn" href="{% url 'admin:index' %}">Admin</a>
{% endif %}
- <a class="btn" href="#">About</a>
{% if user.is_authenticated %}
<form action="{% url 'account_logout' %}" method="post">
{% csrf_token %}