From 7245bbb746aede543cd8334401d0e3400cf71716 Mon Sep 17 00:00:00 2001 From: dnns01 <github@dnns01.de> Date: Wed, 10 Nov 2021 19:04:23 +0100 Subject: [PATCH] Make clip controls optional --- strolchguru/templates/strolchguru_home.html | 4 +++- strolchguru/views.py | 17 ++++++++++------- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/strolchguru/templates/strolchguru_home.html b/strolchguru/templates/strolchguru_home.html index a29f630..e3ce41b 100644 --- a/strolchguru/templates/strolchguru_home.html +++ b/strolchguru/templates/strolchguru_home.html @@ -37,12 +37,14 @@ <body style="background: black;"> <video id="clip" autoplay - controls + {% if controls %}controls{% endif %} + {% if mode == "loop" %} loop {% else %} onended="window.location.reload(true)" {% endif %} + src="/media/clips/{{ clip.clip_id }}.mp4"> </video> <div id="caption"> diff --git a/strolchguru/views.py b/strolchguru/views.py index 4392320..da48f9d 100644 --- a/strolchguru/views.py +++ b/strolchguru/views.py @@ -1,21 +1,28 @@ import random from django.forms.models import model_to_dict -from django.http import HttpResponse, JsonResponse +from django.http import HttpResponse, JsonResponse, Http404 from django.shortcuts import render, get_object_or_404 from .models import Clip def home(request) -> HttpResponse: + controls = True if request.GET.get("controls") == "1" else False clips = list(Clip.objects.filter(is_published=True, is_downloaded=True)) clip = random.choice(clips) - return render(request, 'strolchguru_home.html', context={'clip': clip, 'mode': "random_clips"}) + return render(request, 'strolchguru_home.html', + context={'clip': clip, 'mode': "random_clips", 'controls': controls}) def clip(request, id) -> HttpResponse: + controls = True if request.GET.get("controls") == "1" else False clip = get_object_or_404(Clip, pk=id) - return render(request, 'strolchguru_home.html', context={'clip': clip, 'mode': "loop"}) + + if not clip.is_published: + raise Http404() + + return render(request, 'strolchguru_home.html', context={'clip': clip, 'mode': "loop", 'controls': controls}) def clip_json(request, id) -> JsonResponse: @@ -25,7 +32,3 @@ def clip_json(request, id) -> JsonResponse: return JsonResponse(json) except Clip.DoesNotExist: return JsonResponse({"error": "Clip with this id does not exist"}) - -# def clips_today(request) -> HttpResponse: -# clips = twitch_api.get_clips(today=True) -# return render(request, 'strolchguru_home.html', context={'clip': clip, 'url_name': "clips_today"}) -- GitLab