mirror of
https://github.com/ArchiveBox/ArchiveBox.git
synced 2025-05-13 14:44:29 -04:00
feat: Allow feed loading from the add links view
This commit is contained in:
parent
f373df7bd4
commit
8bdfa18a3f
3 changed files with 38 additions and 12 deletions
7
archivebox/core/forms.py
Normal file
7
archivebox/core/forms.py
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
from django import forms
|
||||||
|
|
||||||
|
CHOICES = (('url', 'URL'), ('feed', 'Feed'))
|
||||||
|
|
||||||
|
class AddLinkForm(forms.Form):
|
||||||
|
url = forms.URLField()
|
||||||
|
source = forms.ChoiceField(choices=CHOICES, widget=forms.RadioSelect, initial='url')
|
|
@ -22,6 +22,8 @@ from ..config import (
|
||||||
from ..util import base_url, ansi_to_html
|
from ..util import base_url, ansi_to_html
|
||||||
from .. main import add
|
from .. main import add
|
||||||
|
|
||||||
|
from .forms import AddLinkForm
|
||||||
|
|
||||||
|
|
||||||
class MainIndex(View):
|
class MainIndex(View):
|
||||||
template = 'main_index.html'
|
template = 'main_index.html'
|
||||||
|
@ -51,28 +53,39 @@ class AddLinks(View):
|
||||||
if not request.user.is_authenticated and not PUBLIC_INDEX:
|
if not request.user.is_authenticated and not PUBLIC_INDEX:
|
||||||
return redirect(f'/admin/login/?next={request.path}')
|
return redirect(f'/admin/login/?next={request.path}')
|
||||||
|
|
||||||
context = {}
|
context = {
|
||||||
|
"form": AddLinkForm()
|
||||||
|
}
|
||||||
|
|
||||||
return render(template_name=self.template, request=request, context=context)
|
return render(template_name=self.template, request=request, context=context)
|
||||||
|
|
||||||
def post(self, request):
|
def post(self, request):
|
||||||
url = request.POST['url']
|
#url = request.POST['url']
|
||||||
if url:
|
#if url:
|
||||||
|
form = AddLinkForm(request.POST)
|
||||||
|
if form.is_valid():
|
||||||
|
url = form.cleaned_data["url"]
|
||||||
print(f'[+] Adding URL: {url}')
|
print(f'[+] Adding URL: {url}')
|
||||||
|
if form.cleaned_data["source"] == "url":
|
||||||
|
key = "import_str"
|
||||||
|
else:
|
||||||
|
key = "import_path"
|
||||||
|
input_kwargs = {
|
||||||
|
key: url,
|
||||||
|
"update_all": False,
|
||||||
|
"out_dir": OUTPUT_DIR,
|
||||||
|
}
|
||||||
add_stdout = StringIO()
|
add_stdout = StringIO()
|
||||||
with redirect_stdout(add_stdout):
|
with redirect_stdout(add_stdout):
|
||||||
extracted_links = add(
|
extracted_links = add(**input_kwargs)
|
||||||
import_str=url,
|
|
||||||
update_all=False,
|
|
||||||
out_dir=OUTPUT_DIR,
|
|
||||||
)
|
|
||||||
print(add_stdout.getvalue())
|
print(add_stdout.getvalue())
|
||||||
|
|
||||||
context = {
|
context = {
|
||||||
"stdout": ansi_to_html(add_stdout.getvalue())
|
"stdout": ansi_to_html(add_stdout.getvalue()),
|
||||||
|
"form": AddLinkForm()
|
||||||
}
|
}
|
||||||
else:
|
else:
|
||||||
context = {"stdout": "Please enter a URL"}
|
context = {"form": form}
|
||||||
|
|
||||||
return render(template_name=self.template, request=request, context=context)
|
return render(template_name=self.template, request=request, context=context)
|
||||||
|
|
||||||
|
|
|
@ -159,6 +159,12 @@
|
||||||
.title-col a {
|
.title-col a {
|
||||||
color: black;
|
color: black;
|
||||||
}
|
}
|
||||||
|
.ul-form {
|
||||||
|
list-style: none;
|
||||||
|
}
|
||||||
|
.ul-form li {
|
||||||
|
list-style: none;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
<link rel="stylesheet" href="{% static 'bootstrap.min.css' %}">
|
<link rel="stylesheet" href="{% static 'bootstrap.min.css' %}">
|
||||||
<link rel="stylesheet" href="{% static 'jquery.dataTables.min.css' %}"/>
|
<link rel="stylesheet" href="{% static 'jquery.dataTables.min.css' %}"/>
|
||||||
|
@ -199,9 +205,9 @@
|
||||||
<center>
|
<center>
|
||||||
{{ stdout | safe }}
|
{{ stdout | safe }}
|
||||||
<br/><br/>
|
<br/><br/>
|
||||||
<form action="?" method="POST">{% csrf_token %}
|
<form action="?" method="POST" class="ul-form">{% csrf_token %}
|
||||||
Add new links...<br/>
|
Add new links...<br/>
|
||||||
<input type="text" name="url" placeholder="URL of page or feed..."/><br/>
|
{{ form.as_ul }}
|
||||||
<button role="submit">Add</button>
|
<button role="submit">Add</button>
|
||||||
</form>
|
</form>
|
||||||
</center>
|
</center>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue