mirror of
https://github.com/tubearchivist/tubearchivist-frontend.git
synced 2024-11-22 11:50:14 +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">
|
<div class="show-form">
|
||||||
<form id='hidden-form' action="/downloads/" method="post">
|
<form id='hidden-form' action="/downloads/" method="post">
|
||||||
{% csrf_token %}
|
{% 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>
|
<button type="submit">Add to download queue</button>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
|
@ -16,6 +16,7 @@ from django.shortcuts import redirect, render
|
|||||||
from django.utils.http import urlencode
|
from django.utils.http import urlencode
|
||||||
from django.views import View
|
from django.views import View
|
||||||
from home.forms import (
|
from home.forms import (
|
||||||
|
AddToQueueForm,
|
||||||
ApplicationSettingsForm,
|
ApplicationSettingsForm,
|
||||||
ChannelSearchForm,
|
ChannelSearchForm,
|
||||||
CustomAuthForm,
|
CustomAuthForm,
|
||||||
@ -242,7 +243,9 @@ class DownloadView(View):
|
|||||||
all_video_hits = False
|
all_video_hits = False
|
||||||
pagination = False
|
pagination = False
|
||||||
|
|
||||||
|
add_form = AddToQueueForm()
|
||||||
context = {
|
context = {
|
||||||
|
"add_form": add_form,
|
||||||
"all_video_hits": all_video_hits,
|
"all_video_hits": all_video_hits,
|
||||||
"max_hits": max_hits,
|
"max_hits": max_hits,
|
||||||
"pagination": pagination,
|
"pagination": pagination,
|
||||||
@ -296,14 +299,15 @@ class DownloadView(View):
|
|||||||
@staticmethod
|
@staticmethod
|
||||||
def post(request):
|
def post(request):
|
||||||
"""handle post requests"""
|
"""handle post requests"""
|
||||||
download_post = dict(request.POST)
|
to_queue = AddToQueueForm(data=request.POST)
|
||||||
if "vid-url" in download_post.keys():
|
if to_queue.is_valid():
|
||||||
url_str = download_post["vid-url"]
|
vid_url_list = [request.POST.get("vid_url")]
|
||||||
|
print(vid_url_list)
|
||||||
try:
|
try:
|
||||||
youtube_ids = process_url_list(url_str)
|
youtube_ids = process_url_list(vid_url_list)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
# failed to process
|
# failed to process
|
||||||
print(f"failed to parse: {url_str}")
|
print(f"failed to parse: {vid_url_list}")
|
||||||
mess_dict = {
|
mess_dict = {
|
||||||
"status": "downloading",
|
"status": "downloading",
|
||||||
"level": "error",
|
"level": "error",
|
||||||
|
Loading…
Reference in New Issue
Block a user