Skip to content

Commit

Permalink
Create AreaSearch pdf exporter
Browse files Browse the repository at this point in the history
  • Loading branch information
vinikvuo committed Sep 15, 2023
1 parent ccd487d commit 47b31d4
Show file tree
Hide file tree
Showing 10 changed files with 300 additions and 34 deletions.
20 changes: 18 additions & 2 deletions locale/fi/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ msgid ""
msgstr ""
"Project-Id-Version: MVJ 0.1\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2023-07-27 16:00+0300\n"
"POT-Creation-Date: 2023-09-14 14:56+0300\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: \n"
"Language: fi\n"
Expand Down Expand Up @@ -3639,10 +3639,26 @@ msgstr "Kohde on poistunut järjestelmästä!"
msgid "The target information has changed!"
msgstr "Kohteen tiedot ovat muuttuneet!"

msgid "Area search information"
msgstr "Aluehaun tiedot"

msgid "Description area"
msgstr "Tarkempi kuvaus alueesta"

msgid "Description intended use"
msgstr "Tarkempi kuvaus käyttötarkoituksesta"

msgid "Received date"
msgstr "Vastaanotettu"

msgid "Time stamp"
msgstr "Aikaleima"

msgid "You have received a link for a direct reservation plot search"
msgstr "Olet vastaanottanut linkin suoravaraushakuun"

#python-brace-format
# python-brace-format
#, python-brace-format
msgid ""
"Hi {receiver}! Here is the link for the direct reservation plot search: "
"{url} \n"
Expand Down
10 changes: 8 additions & 2 deletions mvj/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,12 @@
from leasing.viewsets.vat import VatViewSet
from plotsearch.views.plot_search import (
AreaSearchAttachmentViewset,
AreaSearchGeneratePDF,
AreaSearchViewSet,
DirectReservationLinkViewSet,
DirectReservationToFavourite,
FAQViewSet,
FavouriteViewSet,
GeneratePDF,
InformationCheckViewSet,
)
from plotsearch.views.plot_search import IntendedUseViewSet as IntendedUsePSViewSet
Expand All @@ -124,6 +124,7 @@
PlotSearchTargetViewSet,
PlotSearchTypeViewSet,
PlotSearchViewSet,
TargetStatusGeneratePDF,
)
from users.views import UsersPermissions
from users.viewsets import UserViewSet
Expand Down Expand Up @@ -252,7 +253,12 @@
router.register("job_run_log_entry", JobRunLogEntryViewSet)

additional_api_paths = [
path("target_status_pdf/", GeneratePDF.as_view(), name="target_status-pdf"),
path(
"target_status_pdf/",
TargetStatusGeneratePDF.as_view(),
name="target_status-pdf",
),
path("area_search_pdf/", AreaSearchGeneratePDF.as_view(), name="area-search-pdf"),
path("auditlog/", AuditLogView.as_view(), name="auditlog"),
path("contact_exists/", ContactExistsView.as_view(), name="contact-exists"),
path(
Expand Down
100 changes: 100 additions & 0 deletions plotsearch/templates/area_search/detail.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
{% load static %}
{% load i18n %}
{% load entry_filter %}

<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<title>Title</title>
<link rel="stylesheet" href="{% static 'plotsearch/fonts/fonts.css' %}">
<link rel="stylesheet" href="{% static 'plotsearch/target_status_pdf_style.css' %}">
</head>

<body>
<div class="content">
<div>
<h1>{{ object.identifier }}</h1>
</div>
<div>
<h2>{% trans "Area search information" %}</h2>
<table>
<tr>
<th>{% trans "Lessor" %}</th>
<td>{{ object.lessor.value }}</td>
</tr>
<tr>
<th>{% trans "Description area" %}</th>
<td>{{ object.description_area }}</td>
</tr>
<tr>
<th>{% trans "Address" %}</th>
<td>{{ object.address }}</td>
</tr>
<tr>
<th>{% trans "District" %}</th>
<td>{{ object.district }}</td>
</tr>
<tr>
<th>{% trans "Intended use" %}</th>
<td>{{ object.intended_use }}</td>
</tr>
<tr>
<th>{% trans "Description intended use" %}</th>
<td>{{ object.description_intended_use }}</td>
</tr>
<tr>
<th>{% trans "Start date" %}</th>
<td>{{ object.start_date|date:"G:i j.n.Y" }}</td>
</tr>
<tr>
<th>{% trans "End date" %}</th>
<td>{{ object.end_date|date:"G:i j.n.Y" }}</td>
</tr>
<tr>
<th>{% trans "Received date" %}</th>
<td>{{ object.received_date|date:"G:i j.n.Y" }}</td>
</tr>
</table>
</div>
<div class="divider">&nbsp;</div>
{% for section in object.form.sections.all|filter_only_parent %}
{% if section.applicant_type|slugify == applicant_type|slugify or section.applicant_type|slugify == "Both"|slugify %}
{% include "mixins/section.html" with section=section answer=object.answer %}
{% endif %}
{% endfor %}
{% if show_information_check %}
<div>
<h2>{% trans "Area search information" %}</h2>
<table>
<tr>
<th>{% trans "Lessor" %}</th>
<td>{{ object.area_search_status.decline_reason.value }}</td>
</tr>
<tr>
<th>{% trans "Description area" %}</th>
<td>{{ object.area_search_status.preparer_note }}</td>
</tr>
{% for note in object.area_search_status.status_notes.all %}
<tr>
<th>{% trans "Note" %}</th>
<td>{{ note.note }}</td>
</tr>
<tr>
<th>{% trans "Preparer" %}</th>
<td>{{ note.preparer }}</td>
</tr>
<tr>
<th>{% trans "Time stamp" %}</th>
<td>{{ note.time_stamp|date:"G:i j.n.Y" }}</td>
</tr>
{% endfor %}
</table>
<div class="divider">&nbsp;</div>
</div>
{% endif %}
</div>
</body>

</html>
68 changes: 42 additions & 26 deletions plotsearch/templates/mixins/section.html
Original file line number Diff line number Diff line change
@@ -1,29 +1,45 @@
{% for subsection in section.subsections.all %}
{% include "mixins/section.html" with section=subsection %}
{% endfor %}
{% load entry_filter %}
{% load form_visible %}

{% if section.fields.all and section.visible == True %}
<div>
<h2>{{ section }}</h2>
<table>
{% for field in section.fields.all %}
{% if field.enabled == True %}
<tr>
<th>
{{ field }}
</th>
{% for entry in field.entry_set.all|filter_answer:answer %}
<td>
{% if field.type.identifier == "checkbox" or field.type.identifier == "radiobutton" or field.type.identifier == "radiobuttoninline" %}
{% fetch_choice_value entry.value entry.field.id %}
{% if not entry.value %}
<span> - </span>
{% endif %}

{% else %}
{{ entry.value }}
{% if not entry.value %}
<span> - </span>
{% endif %}
{% endif %}
{% empty %}
<span> - </span>
</td>
{% endfor %}
</tr>
{% endif %}

{% if section.fields.all %}
<div>
<h2>{{ section }}</h2>
<table>
{% for field in section.fields.all %}
<tr>
<th>
{{field}}
</th>
<td>
{% for entry in field.entry_set.all %}
{{ entry.value }}
{% if not entry.value%}
<span> - </span>
{% endif %}
{% empty %}
<span> - </span>
{% endfor %}
</td>
</tr>
{% endfor %}
</table>
{% endfor %}
</table>
</div>
<div class="divider">&nbsp;</div>
</div>
{% endif %}

{% for subsection in section.subsections.all %}
{% if subsection.applicant_type|slugify == applicant_type|slugify or subsection.applicant_type|slugify == "Both"|slugify %}
{% include "mixins/section.html" with section=subsection %}
{% endif %}
{% endfor %}
9 changes: 6 additions & 3 deletions plotsearch/templates/target_status/detail.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
{% load static %}
{% load form_visible %}
{% load entry_filter %}

<!DOCTYPE html>
<html lang="en">

Expand All @@ -15,10 +18,10 @@
<h1>{{ object.application_identifier }}</h1>
</div>
<div class="divider">&nbsp;</div>
{% for section in object.plot_search_target.plot_search.form.sections.all %}
{% include "mixins/section.html" with section=section %}
{% for section in object.plot_search_target.plot_search.form.sections.all|filter_only_parent %}
{% include "mixins/section.html" with section=section answer=object.answer %}
{% endfor %}
</div>
</body>

</html>
</html>
Empty file.
13 changes: 13 additions & 0 deletions plotsearch/templatetags/entry_filter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from django import template

register = template.Library()


@register.filter
def filter_answer(qs, answer):
return qs.filter(entry_section__answer=answer)


@register.filter
def filter_only_parent(qs):
return qs.filter(parent__isnull=True)
32 changes: 32 additions & 0 deletions plotsearch/templatetags/form_visible.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import ast

from django import template

from forms.models import Choice

register = template.Library()


@register.filter
def visible_section(section, value):
return section.filter(visible=value)


@register.filter
def visible_field(field, value):
return field.filter(enabled=value)


@register.simple_tag
def fetch_choice_value(value, field_id):
if value == "" or value == "[]":
return "-"
choice_value = ast.literal_eval(value)
choices = Choice.objects.filter(field=field_id)
if isinstance(choice_value, list):
choices = choices.filter(value__in=choice_value)
else:
choices = choices.filter(value=choice_value)
if not choices.exists():
return "-"
return " ".join([choice.text for choice in choices])
24 changes: 24 additions & 0 deletions plotsearch/utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from django.utils.translation import override
from django.utils.translation import ugettext_lazy as _

from forms.enums import ApplicantType
from forms.models import Choice, Field, Form, Section
from plotsearch.enums import AreaSearchLessor

Expand Down Expand Up @@ -784,3 +785,26 @@ def pop_default(validated_data, index, default_value):
return validated_data.pop(index)
except IndexError:
return default_value


def get_applicant_type(answer):
applicant_sections = answer.entry_sections.filter(
entries__field__identifier="hakija",
entries__field__section__identifier="hakijan-tiedot",
)
applicant_type = (
applicant_sections[0]
.entries.get(
field__identifier="hakija", field__section__identifier="hakijan-tiedot"
)
.value
)

applicant_type_enum = ApplicantType.BOTH

if applicant_type == "0":
applicant_type_enum = ApplicantType.PERSON
if applicant_type == "1":
applicant_type_enum = ApplicantType.COMPANY

return applicant_type_enum
Loading

0 comments on commit 47b31d4

Please sign in to comment.