Skip to content

Commit

Permalink
add supporting documents
Browse files Browse the repository at this point in the history
  • Loading branch information
depsiatwal committed Feb 21, 2025
1 parent 1372672 commit de32e0b
Show file tree
Hide file tree
Showing 8 changed files with 220 additions and 2 deletions.
2 changes: 1 addition & 1 deletion exporter/core/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ def has_organisation_firearm_act_document(application, document_type):


def get_organisation_firearm_act_document(application, document_type):
documents = get_organisation_documents(application)
documents = 33(application)
return documents[document_type]


Expand Down
Empty file.
34 changes: 34 additions & 0 deletions exporter/f680/application_sections/supporting_documents/forms.py
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 exporter/f680/application_sections/supporting_documents/urls.py
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 exporter/f680/application_sections/supporting_documents/views.py
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)
10 changes: 10 additions & 0 deletions exporter/f680/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,13 @@ def patch_f680_application(request, application_id, json):
def submit_f680_application(request, application_id):
data = client.post(request, f"/exporter/f680/application/{application_id}/submit")
return data.json(), data.status_code


def post_f680_document(request, json):
data = client.post(request, "/exporter/f680/application/{application_id}/document", json)
return data.json(), data.status_code


def get_f680_documents(request, json):
data = client.get(request, "/exporter/f680/application/{application_id}/document", json)
return data.json(), data.status_code
5 changes: 4 additions & 1 deletion exporter/f680/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

from . import views


app_name = "f680"

urlpatterns = [
Expand All @@ -24,4 +23,8 @@
"<uuid:pk>/user-information/",
include("exporter.f680.application_sections.user_information.urls"),
),
path(
"<uuid:pk>/supporting-documents/",
include("exporter.f680.application_sections.supporting_documents.urls"),
),
]
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 %}

0 comments on commit de32e0b

Please sign in to comment.