From aebf44ee7e04acba84c1e1e659a9c9f81db00a0a Mon Sep 17 00:00:00 2001 From: simon Date: Sat, 30 Oct 2021 14:14:16 +0700 Subject: [PATCH] validate add to queue form --- tubearchivist/home/forms.py | 14 ++++++++++++++ tubearchivist/home/templates/home/downloads.html | 3 ++- tubearchivist/home/views.py | 14 +++++++++----- 3 files changed, 25 insertions(+), 6 deletions(-) diff --git a/tubearchivist/home/forms.py b/tubearchivist/home/forms.py index 6fe53515..aa13f80a 100644 --- a/tubearchivist/home/forms.py +++ b/tubearchivist/home/forms.py @@ -84,3 +84,17 @@ class ChannelSearchForm(forms.Form): } ), ) + + +class AddToQueueForm(forms.Form): + """text area form to add to downloads""" + + vid_url = forms.CharField( + label=False, + widget=forms.Textarea( + attrs={ + "rows": 4, + "placeholder": "Enter Video Urls or IDs here...", + } + ), + ) diff --git a/tubearchivist/home/templates/home/downloads.html b/tubearchivist/home/templates/home/downloads.html index 92f611e0..71147f10 100644 --- a/tubearchivist/home/templates/home/downloads.html +++ b/tubearchivist/home/templates/home/downloads.html @@ -21,7 +21,8 @@
{% csrf_token %} - + + {{ add_form }}
diff --git a/tubearchivist/home/views.py b/tubearchivist/home/views.py index 5722483c..275831dc 100644 --- a/tubearchivist/home/views.py +++ b/tubearchivist/home/views.py @@ -16,6 +16,7 @@ from django.shortcuts import redirect, render from django.utils.http import urlencode from django.views import View from home.forms import ( + AddToQueueForm, ApplicationSettingsForm, ChannelSearchForm, CustomAuthForm, @@ -242,7 +243,9 @@ class DownloadView(View): all_video_hits = False pagination = False + add_form = AddToQueueForm() context = { + "add_form": add_form, "all_video_hits": all_video_hits, "max_hits": max_hits, "pagination": pagination, @@ -296,14 +299,15 @@ class DownloadView(View): @staticmethod def post(request): """handle post requests""" - download_post = dict(request.POST) - if "vid-url" in download_post.keys(): - url_str = download_post["vid-url"] + to_queue = AddToQueueForm(data=request.POST) + if to_queue.is_valid(): + vid_url_list = [request.POST.get("vid_url")] + print(vid_url_list) try: - youtube_ids = process_url_list(url_str) + youtube_ids = process_url_list(vid_url_list) except ValueError: # failed to process - print(f"failed to parse: {url_str}") + print(f"failed to parse: {vid_url_list}") mess_dict = { "status": "downloading", "level": "error",