-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1372672
commit de32e0b
Showing
8 changed files
with
220 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
34 changes: 34 additions & 0 deletions
34
exporter/f680/application_sections/supporting_documents/forms.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
from core.common.forms import BaseForm | ||
from django import forms | ||
|
||
from core.file_handler import validate_mime_type | ||
from exporter.core.constants import FileUploadFileTypes | ||
from exporter.core.forms import PotentiallyUnsafeClearableFileInput | ||
|
||
|
||
class F680AttachSupportingDocument(BaseForm): | ||
class Layout: | ||
TITLE = "Attach a supporting document" | ||
|
||
file = forms.FileField( | ||
label=FileUploadFileTypes.UPLOAD_GUIDANCE_TEXT, | ||
error_messages={ | ||
"required": "supporting document required", | ||
}, | ||
validators=[ | ||
validate_mime_type, | ||
], | ||
widget=PotentiallyUnsafeClearableFileInput, | ||
) | ||
|
||
description = forms.CharField( | ||
widget=forms.Textarea(attrs={"rows": "5"}), | ||
label="Description (optional)", | ||
required=False, | ||
) | ||
|
||
def get_layout_fields(self): | ||
return ( | ||
"file", | ||
"description", | ||
) |
11 changes: 11 additions & 0 deletions
11
exporter/f680/application_sections/supporting_documents/urls.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
from django.urls import path | ||
|
||
from . import views | ||
|
||
|
||
app_name = "supporting_documents" | ||
|
||
urlpatterns = [ | ||
path("", views.SupportingDocumentsView.as_view(), name="add"), | ||
path("attach-document/", views.SupportingDocumentsAddView.as_view(), name="attach"), | ||
] |
92 changes: 92 additions & 0 deletions
92
exporter/f680/application_sections/supporting_documents/views.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
from http import HTTPStatus | ||
|
||
from django.views.generic import TemplateView | ||
from django.urls import reverse | ||
|
||
from core.decorators import expect_status | ||
|
||
from core.helpers import get_document_data | ||
from exporter.f680.views import F680FeatureRequiredMixin | ||
from exporter.f680.services import get_f680_application, get_f680_documents, post_f680_document | ||
from django.views.generic import FormView | ||
|
||
from .forms import F680AttachSupportingDocument | ||
|
||
|
||
class SupportingDocumentsView(F680FeatureRequiredMixin, TemplateView): | ||
template_name = "f680/supporting_documents/supporting-documents-documents.html" | ||
|
||
@expect_status( | ||
HTTPStatus.OK, | ||
"Error getting F680 documents", | ||
"Unexpected error getting F680 documents", | ||
reraise_404=True, | ||
) | ||
def get_f680_supporting_documents(self, application_id): | ||
# A new F680 Endpoint which retrieved all the documents from | ||
# Application document | ||
# We could then potentially filter based on what's in the supporting-section | ||
# Of the JSON however this isn't nesseasry for first parse since we only have supporting | ||
# documents | ||
return get_f680_documents(self.request, application_id) | ||
|
||
@expect_status( | ||
HTTPStatus.OK, | ||
"Error retrieving F680 application", | ||
"Unexpected error retrieving F680 application", | ||
reraise_404=True, | ||
) | ||
def get_f680_application(self, pk): | ||
return get_f680_application(self.request, pk) | ||
|
||
def setup(self, request, *args, **kwargs): | ||
super().setup(request, *args, **kwargs) | ||
self.application, _ = self.get_f680_application(kwargs["pk"]) | ||
self.supporting_documents, _ = self.get_f680_supporting_documents(self.kwargs["pk"]) | ||
|
||
def get_context_data(self, pk, **kwargs): | ||
return { | ||
"application": self.application, | ||
"additional_documents": self.supporting_documents["documents"], | ||
} | ||
|
||
|
||
class SupportingDocumentsAddView(F680FeatureRequiredMixin, FormView): | ||
form_class = F680AttachSupportingDocument | ||
template_name = "core/form.html" | ||
|
||
@expect_status( | ||
HTTPStatus.CREATED, | ||
"Error creating F680 document", | ||
"Unexpected error creating F680 document", | ||
) | ||
def post_f680_document(self, data): | ||
return post_f680_document(self.request, data) | ||
|
||
def setup(self, request, *args, **kwargs): | ||
super().setup(request, *args, **kwargs) | ||
self.application, _ = self.get_f680_application(kwargs["pk"]) | ||
|
||
def get_success_url(self): | ||
return reverse( | ||
"f680:summary", | ||
kwargs={ | ||
"pk": self.application.id, | ||
}, | ||
) | ||
|
||
def form_valid(self, form): | ||
data = form.cleaned_data | ||
file = data["file"] | ||
description = data["description"] | ||
payload = {**get_document_data(file), "description": description, "application": self.application.id} | ||
# Here we post the document to a new F680 Specific endpoint | ||
# This is stored on ApplicationDocumention | ||
# This is required so we can do virus scans etc etc | ||
self.post_f680_document(payload) | ||
# After we enrich the JSON with | ||
# {:supporting-documents: {documents:{}}} | ||
# This could contain a dummy id for the entry and JSON blurb of the | ||
# Form i.e in this case description and a reference to the id of the | ||
# Physical document on ApplicationDocument | ||
return super().form_valid(form) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
exporter/templates/f680/supporting_documents/supporting-documents-documents.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
{% extends 'layouts/base.html' %} | ||
|
||
{% load additional_documents svg %} | ||
|
||
{% block back_link %} | ||
<a href="">Back</a> | ||
{% endblock %} | ||
|
||
{% block body %} | ||
<div class="lite-app-bar"> | ||
<div class="lite-app-bar__content"> | ||
<h1 class="govuk-heading-l">Supporting Documents</h1> | ||
</div> | ||
</div> | ||
<a class="govuk-button govuk-button--primary" href="{% url "f680:supporting_documents:attach" pk=application.id %}"> | ||
Add a document | ||
</a> | ||
{% if additional_documents %} | ||
<table class="govuk-table"> | ||
<thead class="govuk-table__head"> | ||
<tr class="govuk-table__row"> | ||
<th class="govuk-table__header" scope="col">Name</th> | ||
<th class="govuk-table__header" scope="col">Description</th> | ||
<th class="govuk-table__header" scope="col">Message</th> | ||
<th class="govuk-table__header" scope="col">Action</th> | ||
</tr> | ||
</thead> | ||
<tbody class="govuk-table__body"> | ||
{% for additional_document in additional_documents %} | ||
<tr class="govuk-table__row"> | ||
<td class="govuk-table__cell">{{ additional_document.name }}</td> | ||
<td class="govuk-table__cell"> | ||
{{ additional_document.description|default_na }} | ||
</td> | ||
<td class="govuk-table__cell govuk-table__cell--numeric"> | ||
{% if additional_document.safe == True %} | ||
<a href="{% url 'applications:download_additional_document' application_id additional_document.id %}" id="document_download" class='govuk-link govuk-link--no-visited-state'> | ||
{% lcs 'AdditionalDocuments.Documents.DOWNLOAD_DOCUMENT' %} | ||
</a> | ||
{% elif additional_document.safe == False %} | ||
{% lcs 'AdditionalDocuments.Documents.VIRUS' %} | ||
{% else %} | ||
{% lcs 'AdditionalDocuments.Documents.PROCESSING' %} | ||
{% endif %} | ||
</td> | ||
<td class="govuk-table__cell govuk-table__cell--numeric"> | ||
{% if editable and not additional_document|is_system_document %} | ||
<a href="{% url 'applications:delete_additional_document' application_id additional_document.id %}" id="document_delete" class='govuk-link govuk-link--no-visited-state'> | ||
Delete | ||
</a> | ||
{% endif %} | ||
</td> | ||
</tr> | ||
{% endfor %} | ||
</tbody> | ||
</table> | ||
{% else %} | ||
<div class="lite-information-text"> | ||
<span class="lite-information-text__icon" aria-hidden="true">!</span> | ||
<p class="lite-information-text__text"> | ||
<span class="govuk-visually-hidden">Information</span> | ||
NO Docs | ||
</p> | ||
</div> | ||
<div class="lite-information-text__help"></div> | ||
{% endif %} | ||
|
||
{% endblock %} |