Added more options for admin to change
authorGeorgios Atheridis <georgios@atheridis.org>
Mon, 23 Jan 2023 10:16:08 +0000 (10:16 +0000)
committerGeorgios Atheridis <georgios@atheridis.org>
Mon, 23 Jan 2023 10:16:08 +0000 (10:16 +0000)
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.

core/manager/migrations/0012_resetdata_ranks.py [new file with mode: 0644]
core/manager/models.py
core/manager/request_clip.py
core/manager/templates/manager/clip_viewer.html
core/manager/templates/manager/final.html
core/manager/templates/manager/index.html
core/manager/views.py
core/static/main.css
core/templates/base.html

diff --git a/core/manager/migrations/0012_resetdata_ranks.py b/core/manager/migrations/0012_resetdata_ranks.py
new file mode 100644 (file)
index 0000000..a4c260f
--- /dev/null
@@ -0,0 +1,18 @@
+# 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),
+        ),
+    ]
index 9053f1a5611c03797d44e79c80309891db4723a0..0f86ccbdb5998c59d0809e97019b5c793964e3df 100644 (file)
@@ -5,6 +5,7 @@ from django.contrib.auth.models import User
 class ResetData(models.Model):
     date_time = models.DateTimeField()
     max_clips = models.IntegerField(default=2)
+    ranks = models.IntegerField(default=5)
 
 
 class Clip(models.Model):
index cd5f2ece126117fa133f215e41e777188b92b9da..783ec8eaa359c84bb480e92f5d963ae5603f344b 100644 (file)
@@ -10,8 +10,9 @@ from django.contrib.auth.models import User
 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 (
index 1cf3ffe38a80e1cdba2b4e697ce856d4a962211b..c15202b5813f79ec688a71dc325bdfb910d34581 100644 (file)
@@ -5,16 +5,15 @@
             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>
index 846ee33bc94ef5adb5fd47eb79eefaef8efbda46..fb2357696b26c4b004dc5bc62ceff4745dec6085 100644 (file)
@@ -1,81 +1,24 @@
 {% 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 %}
 
index 6d51191090a774b339b03fadd6100edddbf7cc9e..6ffeaf2850769cb2b515b104874bf550a0e9b27c 100644 (file)
@@ -8,6 +8,7 @@
         <input id="clip" type="text" name="clip">
         <button>Submit Clip</button>
     </form>
+    {{ message }}
     {% else %}
     <h1>Welcome Friend, please log in</h1>
     {% endif %}
index 12aa9ad44617484cfd8452482d91f841022eefee..0835f806e91c843547ccf02b1ea93a479b939e54 100644 (file)
@@ -11,8 +11,9 @@ from .models import Clip, ResetData
 
 @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:
@@ -27,15 +28,18 @@ def show_clips(request, id):
             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),
     })
 
 
@@ -48,18 +52,23 @@ def get_name(request):
         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")
index 4ca4565b70999c3f9033b3d538354d1d1f194857..bfd3b233f36b8cfe271a1c2e78d5bfff0aac6eea 100644 (file)
@@ -97,6 +97,13 @@ a:active.btn {
 
 #buttons {
     padding-top: 2rem;
+    width: 1000px;
+}
+
+#buttons form {
+    width: 100%;
+    display: flex;
+    justify-content: space-between;
 }
 
 .rank-btn {
@@ -110,33 +117,45 @@ a:active.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;
 }
 
index d786b0370d4faf85f53af446bbf14f60cee664f0..e8cbf7eda55799083c68b0b6f8b0018880e2ee1d 100644 (file)
     <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 %}