(self, request)
| 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 | |
| 424 | admin.site = ArchiveBoxAdmin() |
| 425 | admin.site.register(get_user_model()) |
nothing calls this directly
no test coverage detected