|
25 | 25 | import tempfile |
26 | 26 |
|
27 | 27 | from django.conf import settings |
| 28 | +from django.http import HttpResponseRedirect |
28 | 29 | from django.shortcuts import render |
29 | 30 | from django.views import generic |
30 | 31 |
|
31 | | -from scantext.forms import EditorForm |
| 32 | +from scantext.forms import LicenseForm |
32 | 33 |
|
33 | 34 | SCANCODE_BASE_URL = "https://github.com/nexB/scancode-toolkit/tree/develop/src/licensedcode/data/licenses" |
34 | 35 | SCANCODE_LICENSE_TEXT_URL = SCANCODE_BASE_URL + "/{}.LICENSE" |
|
39 | 40 |
|
40 | 41 |
|
41 | 42 | def license_scanview(request): |
42 | | - form = EditorForm() |
| 43 | + form = LicenseForm() |
43 | 44 | if request.method == "POST": |
44 | | - form = EditorForm(request.POST) |
| 45 | + form = LicenseForm(request.POST) |
45 | 46 | if form.is_valid(): |
46 | 47 | text = form.cleaned_data["input_text"] |
47 | | - # license_location = tempfile.NamedTemporaryFile(mode="w", prefix="license_scan_", dir=settings.SCANCODEIO_WORKSPACE_LOCATION) |
48 | | - # with license_location as f: |
49 | | - # f.write(text) |
50 | | - # f.flush() |
51 | | - # x=get_licenses(location=f) |
52 | | - # f.close() |
53 | | - # the get_licenses in the above code (line 56) returns this error |
54 | | - # error: |
55 | | - # expected str, bytes or os.PathLike object, not _TemporaryFileWrapper |
56 | | - # the below code just works |
57 | | - |
58 | | - expressions = get_licenses( |
59 | | - location="scantext/tests/data/LICENSES", |
60 | | - include_text=True, |
61 | | - license_text_diagnostics=True, |
62 | | - ) |
| 48 | + with tempfile.NamedTemporaryFile( |
| 49 | + mode="w", |
| 50 | + prefix="license_scan_", |
| 51 | + dir=settings.SCANCODEIO_WORKSPACE_LOCATION, |
| 52 | + ) as temp_file: |
| 53 | + temp_file.write(text) |
| 54 | + temp_file.flush() |
| 55 | + expressions = get_licenses( |
| 56 | + location=temp_file.name, |
| 57 | + include_text=True, |
| 58 | + license_text_diagnostics=True, |
| 59 | + ) |
| 60 | + temp_file.close() |
| 61 | + |
63 | 62 | return render( |
64 | 63 | request, |
65 | 64 | "scantext/license_detail.html", |
66 | 65 | { |
67 | 66 | "text": text, |
68 | | - "expr": expressions, |
| 67 | + "result": expressions, |
69 | 68 | }, |
70 | 69 | ) |
71 | | - return render(request, "scantext/license_scan.html", {"form": form}) |
| 70 | + return render(request, "scantext/license_scan_form.html", {"form": form}) |
72 | 71 |
|
73 | 72 |
|
74 | 73 | def get_licenses( |
|
0 commit comments