MCPcopy
hub / github.com/ArchiveBox/ArchiveBox / add_view

Method add_view

archivebox/core/admin.py:385–422  ·  view source on GitHub ↗
(self, request)

Source from the content-addressed store, hash-verified

383 ] + super().get_urls()
384
385 def add_view(self, request):
386 if not request.user.is_authenticated:
387 return redirect(f'/admin/login/?next={request.path}')
388
389 request.current_app = self.name
390 context = {
391 **self.each_context(request),
392 'title': 'Add URLs',
393 }
394
395 if request.method == 'GET':
396 context['form'] = AddLinkForm()
397
398 elif request.method == 'POST':
399 form = AddLinkForm(request.POST)
400 if form.is_valid():
401 url = form.cleaned_data["url"]
402 print(f'[+] Adding URL: {url}')
403 depth = 0 if form.cleaned_data["depth"] == "0" else 1
404 input_kwargs = {
405 "urls": url,
406 "depth": depth,
407 "update_all": False,
408 "out_dir": OUTPUT_DIR,
409 }
410 add_stdout = StringIO()
411 with redirect_stdout(add_stdout):
412 add(**input_kwargs)
413 print(add_stdout.getvalue())
414
415 context.update({
416 "stdout": ansi_to_html(add_stdout.getvalue().strip()),
417 "form": AddLinkForm()
418 })
419 else:
420 context["form"] = form
421
422 return render(template_name='add.html', request=request, context=context)
423
424admin.site = ArchiveBoxAdmin()
425admin.site.register(get_user_model())

Callers

nothing calls this directly

Calls 3

AddLinkFormClass · 0.90
addFunction · 0.90
ansi_to_htmlFunction · 0.85

Tested by

no test coverage detected