mirror of
https://github.com/ArchiveBox/ArchiveBox
synced 2025-02-18 14:28:25 +00:00
unify public archive view
This commit is contained in:
parent
3288f8579b
commit
5e8c115f3f
3 changed files with 36 additions and 41 deletions
|
@ -5,7 +5,7 @@ from django.views import static
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.views.generic.base import RedirectView
|
from django.views.generic.base import RedirectView
|
||||||
|
|
||||||
from core.views import MainIndex, OldIndex, LinkDetails, PublicArchiveView, SearchResultsView, add_view
|
from core.views import MainIndex, OldIndex, LinkDetails, PublicArchiveView, add_view
|
||||||
|
|
||||||
|
|
||||||
# print('DEBUG', settings.DEBUG)
|
# print('DEBUG', settings.DEBUG)
|
||||||
|
@ -32,5 +32,4 @@ urlpatterns = [
|
||||||
path('index.json', static.serve, {'document_root': settings.OUTPUT_DIR, 'path': 'index.json'}),
|
path('index.json', static.serve, {'document_root': settings.OUTPUT_DIR, 'path': 'index.json'}),
|
||||||
path('', MainIndex.as_view(), name='Home'),
|
path('', MainIndex.as_view(), name='Home'),
|
||||||
path('public/', PublicArchiveView.as_view(), name='public-index'),
|
path('public/', PublicArchiveView.as_view(), name='public-index'),
|
||||||
path('search_results/', SearchResultsView.as_view(), name='search-results'),
|
|
||||||
]
|
]
|
||||||
|
|
|
@ -123,6 +123,9 @@ class PublicArchiveView(ListView):
|
||||||
|
|
||||||
def get_queryset(self, **kwargs):
|
def get_queryset(self, **kwargs):
|
||||||
qs = super().get_queryset(**kwargs)
|
qs = super().get_queryset(**kwargs)
|
||||||
|
query = self.request.GET.get('q')
|
||||||
|
if query:
|
||||||
|
qs = Snapshot.objects.filter(title__icontains=query)
|
||||||
for snapshot in qs:
|
for snapshot in qs:
|
||||||
snapshot.icons = get_icons(snapshot)
|
snapshot.icons = get_icons(snapshot)
|
||||||
return qs
|
return qs
|
||||||
|
@ -134,45 +137,38 @@ class PublicArchiveView(ListView):
|
||||||
else:
|
else:
|
||||||
return redirect(f'/admin/login/?next={self.request.path}')
|
return redirect(f'/admin/login/?next={self.request.path}')
|
||||||
|
|
||||||
class SearchResultsView(PublicArchiveView):
|
|
||||||
def get_queryset(self):
|
|
||||||
query = self.request.GET.get('q')
|
|
||||||
results = Snapshot.objects.filter(title__icontains=query)
|
|
||||||
for snapshot in results:
|
|
||||||
snapshot.icons = get_icons(snapshot)
|
|
||||||
return results
|
|
||||||
|
|
||||||
def add_view(request):
|
def add_view(request):
|
||||||
if PUBLIC_ADD_VIEW or request.user.is_authenticated:
|
if PUBLIC_ADD_VIEW or request.user.is_authenticated:
|
||||||
context = {
|
context = {
|
||||||
'title': 'Add URLs',
|
'title': 'Add URLs',
|
||||||
}
|
}
|
||||||
if request.method == 'GET':
|
if request.method == 'GET':
|
||||||
context['form'] = AddLinkForm()
|
context['form'] = AddLinkForm()
|
||||||
|
|
||||||
elif request.method == 'POST':
|
elif request.method == 'POST':
|
||||||
form = AddLinkForm(request.POST)
|
form = AddLinkForm(request.POST)
|
||||||
if form.is_valid():
|
if form.is_valid():
|
||||||
url = form.cleaned_data["url"]
|
url = form.cleaned_data["url"]
|
||||||
print(f'[+] Adding URL: {url}')
|
print(f'[+] Adding URL: {url}')
|
||||||
depth = 0 if form.cleaned_data["depth"] == "0" else 1
|
depth = 0 if form.cleaned_data["depth"] == "0" else 1
|
||||||
input_kwargs = {
|
input_kwargs = {
|
||||||
"urls": url,
|
"urls": url,
|
||||||
"depth": depth,
|
"depth": depth,
|
||||||
"update_all": False,
|
"update_all": False,
|
||||||
"out_dir": OUTPUT_DIR,
|
"out_dir": OUTPUT_DIR,
|
||||||
}
|
}
|
||||||
add_stdout = StringIO()
|
add_stdout = StringIO()
|
||||||
with redirect_stdout(add_stdout):
|
with redirect_stdout(add_stdout):
|
||||||
add(**input_kwargs)
|
add(**input_kwargs)
|
||||||
print(add_stdout.getvalue())
|
print(add_stdout.getvalue())
|
||||||
|
|
||||||
context.update({
|
context.update({
|
||||||
"stdout": ansi_to_html(add_stdout.getvalue().strip()),
|
"stdout": ansi_to_html(add_stdout.getvalue().strip()),
|
||||||
"form": AddLinkForm()
|
"form": AddLinkForm()
|
||||||
})
|
})
|
||||||
else:
|
else:
|
||||||
context["form"] = form
|
context["form"] = form
|
||||||
return render(template_name='add_links.html', request=request, context=context)
|
return render(template_name='add_links.html', request=request, context=context)
|
||||||
else:
|
else:
|
||||||
return redirect(f'/admin/login/?next={request.path}')
|
return redirect(f'/admin/login/?next={request.path}')
|
|
@ -232,7 +232,7 @@
|
||||||
</div>
|
</div>
|
||||||
</header>
|
</header>
|
||||||
<br>
|
<br>
|
||||||
<form action="{% url 'search-results' %}" method="get">
|
<form action="{% url 'public-index' %}" method="get">
|
||||||
<input name="q" type="text" placeholder="Search...">
|
<input name="q" type="text" placeholder="Search...">
|
||||||
<button type="submit">Search</button>
|
<button type="submit">Search</button>
|
||||||
<button onclick="location.href='{% url 'public-index' %}'" type="button">
|
<button onclick="location.href='{% url 'public-index' %}'" type="button">
|
||||||
|
|
Loading…
Add table
Reference in a new issue