mirror of
https://github.com/tubearchivist/tubearchivist
synced 2024-11-04 12:00:21 +00:00
validate add to queue form
This commit is contained in:
parent
266d3703cd
commit
aebf44ee7e
@ -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...",
|
||||
}
|
||||
),
|
||||
)
|
||||
|
@ -21,7 +21,8 @@
|
||||
<div class="show-form">
|
||||
<form id='hidden-form' action="/downloads/" method="post">
|
||||
{% csrf_token %}
|
||||
<textarea rows="4" placeholder="Enter Video Urls or IDs here..." id="vid-url" name="vid-url"></textarea>
|
||||
<!-- <textarea rows="4" placeholder="Enter Video Urls or IDs here..." id="vid-url" name="vid-url"></textarea> -->
|
||||
{{ add_form }}
|
||||
<button type="submit">Add to download queue</button>
|
||||
</form>
|
||||
</div>
|
||||
|
@ -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",
|
||||
|
Loading…
Reference in New Issue
Block a user