Compare commits
208 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 5550b8aa67 | |||
| a6f7e605e6 | |||
| 8bce8b8e75 | |||
| 4f02e8ee1b | |||
| 117a4437fe | |||
| f9c23a8f29 | |||
| a5f0d7f8c6 | |||
| 982d9f1930 | |||
| 9840c8fa8f | |||
| 890911c2dc | |||
| 3d10e84852 | |||
| 05145673e1 | |||
| fd4c9b0e5e | |||
| 23f0567aef | |||
| 70555ee5a3 | |||
| 1c38acea25 | |||
| cf282c937f | |||
| ee9834c0da | |||
| dacfbd0504 | |||
| 0e7859e538 | |||
| 16107f93f6 | |||
| d669adf54f | |||
| 589a7aec60 | |||
| 3f3ae4e31b | |||
| 1bbede0d12 | |||
| 0801b3f6ab | |||
| 44ad156595 | |||
| 5c95bc7d85 | |||
| 3b045fea8e | |||
| 6e5237ab88 | |||
| f19ad5f639 | |||
| 766e3c8d37 | |||
| f6dcb6c6db | |||
| e90625c8b5 | |||
| 7bacbecdec | |||
| 58ce00a5a6 | |||
| be885306c5 | |||
| 8b67df7617 | |||
| ab9af7ae2f | |||
| f085caac5d | |||
| 7f8d900c10 | |||
| e7031d0bc2 | |||
| 8aa3fbd97a | |||
| eb3b9eb5c1 | |||
| 1e86a1ce5e | |||
| fbab67f897 | |||
| 59c5072619 | |||
| 51525d79f5 | |||
| 4f482595c6 | |||
| 57aa39a670 | |||
| 2f4301d09f | |||
| fec43e1bed | |||
| 9f32c2fdd9 | |||
| b310349c1a | |||
| 946f3af77c | |||
| e73b7633a3 | |||
| d1dc61cbd7 | |||
| 3ba3785ef1 | |||
| 71afdd8b36 | |||
| a334fff54d | |||
| b65dae5b95 | |||
| bb399571b1 | |||
| 90e76bc8f5 | |||
| 5e84dfc4ae | |||
| 92211445e7 | |||
| 73c61e96f5 | |||
| 615eb65534 | |||
| bcde400096 | |||
| aa02dbab96 | |||
| 339f074681 | |||
| 989d256521 | |||
| 623c29f827 | |||
| eb975cd3c5 | |||
| 5a8765f638 | |||
| 9c2bdcdacf | |||
| 48e3e84b4c | |||
| db884baa09 | |||
| 253b509122 | |||
| c60afb0391 | |||
| 49c14a67b6 | |||
| d13c3e8094 | |||
| c6e784e6d4 | |||
| 940aa38154 | |||
| 887a3552b4 | |||
| 3b36193566 | |||
| 090f6faa4e | |||
| d2ec3d9c08 | |||
| 8165540c00 | |||
| 87fae51144 | |||
| bf1c0e2078 | |||
| b85e33dc22 | |||
| 83d70b6d59 | |||
| 60e23d15fc | |||
| 8b7c4a82aa | |||
| fb1dce9d3c | |||
| 6ecbd74b93 | |||
| a6551534dc | |||
| 6060f1c1bd | |||
| 59ff1c79a8 | |||
| 64d0a3bd12 | |||
| a34a0b4d8a | |||
| 1be77e8b22 | |||
| f7b074ab23 | |||
| ac4dacefe0 | |||
| b668c562dd | |||
| fc31ad4ae0 | |||
| 7689e0b80d | |||
| 460011a5e8 | |||
| 17c954e844 | |||
| 06ad0fdc2d | |||
| 76e018e084 | |||
| 98a1a70a69 | |||
| 22a3339157 | |||
| c98f41c9a8 | |||
| e00b050c8b | |||
| f7dbf428ac | |||
| fe409605aa | |||
| a4f6519601 | |||
| 0b9587f17c | |||
| 9794688f20 | |||
| 310f7d124c | |||
| cecceba8b2 | |||
| ab9023aad0 | |||
| ce7d207a6d | |||
| 0dd1ac70d1 | |||
| 25d04006d8 | |||
| fe29035158 | |||
| f6c39304ab | |||
| f05bb6ff5c | |||
| aa675aa046 | |||
| 6dac847d22 | |||
| 02a6b815ea | |||
| 262f1a6298 | |||
| b831a63db6 | |||
| 3e2c5b7e47 | |||
| e8fae7a6f4 | |||
| 7a760332fa | |||
| 7091b3d707 | |||
| a58532322e | |||
| cf43a4351e | |||
| e65b7ec45c | |||
| a1d3fafc61 | |||
| 767285112d | |||
| b62113df8b | |||
| 0658a2f6f1 | |||
| 117f0eaeb6 | |||
| 46ff1d2bc5 | |||
| ec69556b1c | |||
| eb22dcf9b4 | |||
| 30d1e4033d | |||
| b34aa44d44 | |||
| f3a837a8a6 | |||
| f36f219d2e | |||
| 3df605376c | |||
| 2fcc41bf4a | |||
| 23790bca8d | |||
| 925d5f5070 | |||
| 3814c2749a | |||
| d0991ea832 | |||
| 68b8ff07e9 | |||
| f8dedc6df1 | |||
| fe29b7874e | |||
| e3c7a1a274 | |||
| 3f7a6d416d | |||
| cba174b762 | |||
| 8d573e7390 | |||
| 06f81d89c4 | |||
| a16e0af751 | |||
| 0479f54a4d | |||
| aa616db1f0 | |||
| a9bd92c57c | |||
| fce85690b7 | |||
| a385420c57 | |||
| 9915e6a450 | |||
| 59f28fbf12 | |||
| 78b4dce64d | |||
| cb6a2d4d91 | |||
| 591e35a0e2 | |||
| e3fbe60fce | |||
| 83531c5f77 | |||
| 0afb4d34c3 | |||
| a759eb2453 | |||
| fd3fe17953 | |||
| 58e5b47b07 | |||
| a56f202e7f | |||
| 51a1652baa | |||
| 6cdf355063 | |||
| 13fd3e1fcb | |||
| 00c1bb67ca | |||
| 8d47c9576b | |||
| a147626174 | |||
| 34d167a3eb | |||
| 80b78d3e0d | |||
| 6525f24121 | |||
| b4e75fa2cd | |||
| 16505c79e7 | |||
| fd04c314cd | |||
| fb8b338950 | |||
| 6c80480d0d | |||
| e5cd5a2312 | |||
| 1eff3687e8 | |||
| a9215511ac | |||
| f224bbb5bd | |||
| 874b266352 | |||
| 77b59db56f | |||
| d5e23b420e | |||
| 299923ef45 | |||
| 7028672b93 |
@@ -22,6 +22,7 @@ class TimespanReportForm(BaseForm):
|
|||||||
date_from = forms.DateField(
|
date_from = forms.DateField(
|
||||||
label_suffix="",
|
label_suffix="",
|
||||||
label=_("From"),
|
label=_("From"),
|
||||||
|
help_text=_("Entries created from..."),
|
||||||
widget=forms.DateInput(
|
widget=forms.DateInput(
|
||||||
attrs={
|
attrs={
|
||||||
"type": "date",
|
"type": "date",
|
||||||
@@ -34,6 +35,7 @@ class TimespanReportForm(BaseForm):
|
|||||||
date_to = forms.DateField(
|
date_to = forms.DateField(
|
||||||
label_suffix="",
|
label_suffix="",
|
||||||
label=_("To"),
|
label=_("To"),
|
||||||
|
help_text=_("Entries created until..."),
|
||||||
widget=forms.DateInput(
|
widget=forms.DateInput(
|
||||||
attrs={
|
attrs={
|
||||||
"type": "date",
|
"type": "date",
|
||||||
|
|||||||
@@ -3,11 +3,11 @@
|
|||||||
|
|
||||||
{% block body %}
|
{% block body %}
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-sm-12 col-md-12 col-lg-6">
|
<div class="col-sm-12 col-md-12 col-lg-12 col-xl-6">
|
||||||
<h3>{% trans 'Evaluation report' %} {{office.long_name}}</h3>
|
<h3>{% trans 'Evaluation report' %} {{office.long_name}}</h3>
|
||||||
<h5>{% trans 'From' %} {{report.date_from.date}} {% trans 'to' %} {{report.date_to.date}}</h5>
|
<h5>{% trans 'From' %} {{report.date_from.date}} {% trans 'to' %} {{report.date_to.date}}</h5>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-sm-12 col-md-12 col-lg-6">
|
<div class="col-sm-12 col-md-12 col-lg-12 col-xl-6">
|
||||||
<div class="d-flex justify-content-end">
|
<div class="d-flex justify-content-end">
|
||||||
<div class="dropdown">
|
<div class="dropdown">
|
||||||
<div class="btn btn" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">
|
<div class="btn btn" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">
|
||||||
|
|||||||
@@ -15,40 +15,40 @@
|
|||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th scope="col">{% trans 'Area of responsibility' %}</th>
|
<th scope="col">{% trans 'Area of responsibility' %}</th>
|
||||||
|
<th scope="col">{% trans 'Total' %}</th>
|
||||||
|
<th scope="col">{% trans 'Number single areas' %}</th>
|
||||||
<th scope="col">{% fa5_icon 'star' %} {% trans 'Checked' %}</th>
|
<th scope="col">{% fa5_icon 'star' %} {% trans 'Checked' %}</th>
|
||||||
<th scope="col">{% fa5_icon 'bookmark' %} {% trans 'Recorded' %}</th>
|
<th scope="col">{% fa5_icon 'bookmark' %} {% trans 'Recorded' %}</th>
|
||||||
<th scope="col">{% trans 'Number single areas' %}</th>
|
|
||||||
<th scope="col">{% trans 'Total' %}</th>
|
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
<tr>
|
<tr>
|
||||||
<td>{% trans 'Conservation office by law' %}</td>
|
<td>{% trans 'Conservation office by law' %}</td>
|
||||||
|
<td>{{report.compensation_report.queryset_registration_office_unb_count|default_if_zero:"-"}}</td>
|
||||||
|
<td>{{report.compensation_report.num_single_surfaces_total_unb|default_if_zero:"-"}}</td>
|
||||||
<td>{{report.compensation_report.queryset_registration_office_unb_checked_count|default_if_zero:"-"}}</td>
|
<td>{{report.compensation_report.queryset_registration_office_unb_checked_count|default_if_zero:"-"}}</td>
|
||||||
<td>{{report.compensation_report.queryset_registration_office_unb_recorded_count|default_if_zero:"-"}}</td>
|
<td>{{report.compensation_report.queryset_registration_office_unb_recorded_count|default_if_zero:"-"}}</td>
|
||||||
<td>{{report.compensation_report.num_single_surfaces_total_unb|default_if_zero:"-"}}</td>
|
|
||||||
<td>{{report.compensation_report.queryset_registration_office_unb_count|default_if_zero:"-"}}</td>
|
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td>{% trans 'Land-use planning' %}</td>
|
<td>{% trans 'Land-use planning' %}</td>
|
||||||
|
<td>{{report.compensation_report.queryset_registration_office_tbp_count|default_if_zero:"-"}}</td>
|
||||||
|
<td>{{report.compensation_report.num_single_surfaces_total_tbp|default_if_zero:"-"}}</td>
|
||||||
<td>{{report.compensation_report.queryset_registration_office_tbp_checked_count|default_if_zero:"-"}}</td>
|
<td>{{report.compensation_report.queryset_registration_office_tbp_checked_count|default_if_zero:"-"}}</td>
|
||||||
<td>{{report.compensation_report.queryset_registration_office_tbp_recorded_count|default_if_zero:"-"}}</td>
|
<td>{{report.compensation_report.queryset_registration_office_tbp_recorded_count|default_if_zero:"-"}}</td>
|
||||||
<td>{{report.compensation_report.num_single_surfaces_total_tbp|default_if_zero:"-"}}</td>
|
|
||||||
<td>{{report.compensation_report.queryset_registration_office_tbp_count|default_if_zero:"-"}}</td>
|
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td>{% trans 'Other registration office' %}</td>
|
<td>{% trans 'Other registration office' %}</td>
|
||||||
|
<td>{{report.compensation_report.queryset_registration_office_other_count|default_if_zero:"-"}}</td>
|
||||||
|
<td>{{report.compensation_report.num_single_surfaces_total_other|default_if_zero:"-"}}</td>
|
||||||
<td>{{report.compensation_report.queryset_registration_office_other_checked_count|default_if_zero:"-"}}</td>
|
<td>{{report.compensation_report.queryset_registration_office_other_checked_count|default_if_zero:"-"}}</td>
|
||||||
<td>{{report.compensation_report.queryset_registration_office_other_recorded_count|default_if_zero:"-"}}</td>
|
<td>{{report.compensation_report.queryset_registration_office_other_recorded_count|default_if_zero:"-"}}</td>
|
||||||
<td>{{report.compensation_report.num_single_surfaces_total_other|default_if_zero:"-"}}</td>
|
|
||||||
<td>{{report.compensation_report.queryset_registration_office_other_count|default_if_zero:"-"}}</td>
|
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td><strong>{% trans 'Total' %}</strong></td>
|
<td><strong>{% trans 'Total' %}</strong></td>
|
||||||
|
<td><strong>{{report.compensation_report.queryset_count|default_if_zero:"-"}}</strong></td>
|
||||||
|
<td><strong>{{report.compensation_report.num_single_surfaces_total|default_if_zero:"-"}}</strong></td>
|
||||||
<td><strong>{{report.compensation_report.queryset_checked_count|default_if_zero:"-"}}</strong></td>
|
<td><strong>{{report.compensation_report.queryset_checked_count|default_if_zero:"-"}}</strong></td>
|
||||||
<td><strong>{{report.compensation_report.queryset_recorded_count|default_if_zero:"-"}}</strong></td>
|
<td><strong>{{report.compensation_report.queryset_recorded_count|default_if_zero:"-"}}</strong></td>
|
||||||
<td><strong>{{report.compensation_report.num_single_surfaces_total|default_if_zero:"-"}}</strong></td>
|
|
||||||
<td><strong>{{report.compensation_report.queryset_count|default_if_zero:"-"}}</strong></td>
|
|
||||||
</tr>
|
</tr>
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
|||||||
@@ -10,14 +10,14 @@
|
|||||||
<table class="table table-hover">
|
<table class="table table-hover">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th scope="col" class="w-25">{% fa5_icon 'bookmark' %} {% trans 'Recorded' %}</th>
|
|
||||||
<th scope="col">{% trans 'Total' %}</th>
|
<th scope="col">{% trans 'Total' %}</th>
|
||||||
|
<th scope="col" class="w-25">{% fa5_icon 'bookmark' %} {% trans 'Recorded' %}</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
<tr>
|
<tr>
|
||||||
<td>{{report.eco_account_report.queryset_recorded_count|default_if_zero:"-"}}</td>
|
|
||||||
<td>{{report.eco_account_report.queryset_count|default_if_zero:"-"}}</td>
|
<td>{{report.eco_account_report.queryset_count|default_if_zero:"-"}}</td>
|
||||||
|
<td>{{report.eco_account_report.queryset_recorded_count|default_if_zero:"-"}}</td>
|
||||||
</tr>
|
</tr>
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
|||||||
@@ -1,22 +1,37 @@
|
|||||||
{% load i18n fontawesome_5 ksp_filters %}
|
{% load i18n fontawesome_5 ksp_filters %}
|
||||||
|
|
||||||
<h3>{% trans 'Deductions' %}</h3>
|
<h3>{% trans 'Deductions' %}</h3>
|
||||||
|
<strong>
|
||||||
|
{% blocktrans %}
|
||||||
|
Recorded = Counts the deductions whose interventions have been recorded
|
||||||
|
{% endblocktrans %}
|
||||||
|
</strong>
|
||||||
<div class="table-container">
|
<div class="table-container">
|
||||||
<table class="table table-hover">
|
<table class="table table-hover">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th scope="col">{% fa5_icon 'bookmark' %} {% trans 'Recorded' %}</th>
|
|
||||||
<th scope="col">{% fa5_icon 'bookmark' %} {% trans 'Recorded' %} {% trans 'Surface' %}</th>
|
|
||||||
<th scope="col" class="w-25">{% trans 'Total' %}</th>
|
<th scope="col" class="w-25">{% trans 'Total' %}</th>
|
||||||
<th scope="col" class="w-25">{% trans 'Total' %} {% trans 'Surface' %}</th>
|
<th scope="col" class="w-25">{% trans 'Total' %} {% trans 'Surface' %}</th>
|
||||||
|
<th scope="col">{% fa5_icon 'bookmark' %} {% trans 'Recorded' %}</th>
|
||||||
|
<th scope="col">{% fa5_icon 'bookmark' %} {% trans 'Recorded' %} {% trans 'Surface' %}</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
<tr>
|
<tr>
|
||||||
<td>{{report.eco_account_report.queryset_deductions_recorded_count|default_if_zero:"-"}}</td>
|
|
||||||
<td>{{report.eco_account_report.recorded_deductions_sq_m|default_if_zero:"-"}}m²</td>
|
|
||||||
<td>{{report.eco_account_report.queryset_deductions_count|default_if_zero:"-"}}</td>
|
<td>{{report.eco_account_report.queryset_deductions_count|default_if_zero:"-"}}</td>
|
||||||
<td>{{report.eco_account_report.deductions_sq_m|default_if_zero:"-"}}m²</td>
|
<td>
|
||||||
|
{{report.eco_account_report.deductions_sq_m|default_if_zero:"-"}}
|
||||||
|
{% if report.eco_account_report.deductions_sq_m > 0 %}
|
||||||
|
m²
|
||||||
|
{% endif %}
|
||||||
|
</td>
|
||||||
|
<td>{{report.eco_account_report.queryset_deductions_recorded_count|default_if_zero:"-"}}</td>
|
||||||
|
<td>
|
||||||
|
{{report.eco_account_report.recorded_deductions_sq_m|default_if_zero:"-"}}
|
||||||
|
{% if report.eco_account_report.recorded_deductions_sq_m > 0 %}
|
||||||
|
m²
|
||||||
|
{% endif %}
|
||||||
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
|||||||
@@ -14,16 +14,16 @@
|
|||||||
<table class="table table-hover">
|
<table class="table table-hover">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
|
<th scope="col" class="w-25">{% trans 'Total' %}</th>
|
||||||
<th scope="col">{% fa5_icon 'star' %} {% trans 'Checked' %}</th>
|
<th scope="col">{% fa5_icon 'star' %} {% trans 'Checked' %}</th>
|
||||||
<th scope="col">{% fa5_icon 'bookmark' %} {% trans 'Recorded' %}</th>
|
<th scope="col">{% fa5_icon 'bookmark' %} {% trans 'Recorded' %}</th>
|
||||||
<th scope="col" class="w-25">{% trans 'Total' %}</th>
|
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
<tr>
|
<tr>
|
||||||
|
<td>{{report.intervention_report.queryset_count|default_if_zero:"-"}}</td>
|
||||||
<td>{{report.intervention_report.queryset_checked_count|default_if_zero:"-"}}</td>
|
<td>{{report.intervention_report.queryset_checked_count|default_if_zero:"-"}}</td>
|
||||||
<td>{{report.intervention_report.queryset_recorded_count|default_if_zero:"-"}}</td>
|
<td>{{report.intervention_report.queryset_recorded_count|default_if_zero:"-"}}</td>
|
||||||
<td>{{report.intervention_report.queryset_count|default_if_zero:"-"}}</td>
|
|
||||||
</tr>
|
</tr>
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
|||||||
@@ -5,29 +5,29 @@
|
|||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th class="w-25" scope="col">{% trans 'Compensation type' %}</th>
|
<th class="w-25" scope="col">{% trans 'Compensation type' %}</th>
|
||||||
|
<th class="w-25" scope="col">{% trans 'Total' %}</th>
|
||||||
<th class="w-25" scope="col">{% fa5_icon 'star' %} {% trans 'Checked' %}</th>
|
<th class="w-25" scope="col">{% fa5_icon 'star' %} {% trans 'Checked' %}</th>
|
||||||
<th class="w-25" scope="col">{% fa5_icon 'bookmark' %} {% trans 'Recorded' %}</th>
|
<th class="w-25" scope="col">{% fa5_icon 'bookmark' %} {% trans 'Recorded' %}</th>
|
||||||
<th class="w-25" scope="col">{% trans 'Total' %}</th>
|
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
<tr>
|
<tr>
|
||||||
<th>{% trans 'Compensation' %}</th>
|
<th>{% trans 'Compensation' %}</th>
|
||||||
|
<td>{{report.intervention_report.compensation_sum|default_if_zero:"-"}}</td>
|
||||||
<td>{{report.intervention_report.compensation_sum_checked|default_if_zero:"-"}}</td>
|
<td>{{report.intervention_report.compensation_sum_checked|default_if_zero:"-"}}</td>
|
||||||
<td>{{report.intervention_report.compensation_sum_recorded|default_if_zero:"-"}}</td>
|
<td>{{report.intervention_report.compensation_sum_recorded|default_if_zero:"-"}}</td>
|
||||||
<td>{{report.intervention_report.compensation_sum|default_if_zero:"-"}}</td>
|
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<th>{% trans 'Payment' %}</th>
|
<th>{% trans 'Payment' %}</th>
|
||||||
|
<td>{{report.intervention_report.payment_sum|default_if_zero:"-"}}</td>
|
||||||
<td>{{report.intervention_report.payment_sum_checked|default_if_zero:"-"}}</td>
|
<td>{{report.intervention_report.payment_sum_checked|default_if_zero:"-"}}</td>
|
||||||
<td>{{report.intervention_report.payment_sum_recorded|default_if_zero:"-"}}</td>
|
<td>{{report.intervention_report.payment_sum_recorded|default_if_zero:"-"}}</td>
|
||||||
<td>{{report.intervention_report.payment_sum|default_if_zero:"-"}}</td>
|
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<th>{% trans 'Deductions' %}</th>
|
<th>{% trans 'Deductions' %}</th>
|
||||||
|
<td>{{report.intervention_report.deduction_sum|default_if_zero:"-"}}</td>
|
||||||
<td>{{report.intervention_report.deduction_sum_checked|default_if_zero:"-"}}</td>
|
<td>{{report.intervention_report.deduction_sum_checked|default_if_zero:"-"}}</td>
|
||||||
<td>{{report.intervention_report.deduction_sum_recorded|default_if_zero:"-"}}</td>
|
<td>{{report.intervention_report.deduction_sum_recorded|default_if_zero:"-"}}</td>
|
||||||
<td>{{report.intervention_report.deduction_sum|default_if_zero:"-"}}</td>
|
|
||||||
</tr>
|
</tr>
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
|||||||
@@ -13,15 +13,15 @@
|
|||||||
<th class="w-25" scope="col">
|
<th class="w-25" scope="col">
|
||||||
{% trans 'Law' %}
|
{% trans 'Law' %}
|
||||||
</th>
|
</th>
|
||||||
|
<th scope="col">
|
||||||
|
{% trans 'Total' %}
|
||||||
|
</th>
|
||||||
<th scope="col">
|
<th scope="col">
|
||||||
{% fa5_icon 'star' %} {% trans 'Checked' %}
|
{% fa5_icon 'star' %} {% trans 'Checked' %}
|
||||||
</th>
|
</th>
|
||||||
<th scope="col">
|
<th scope="col">
|
||||||
{% fa5_icon 'bookmark' %} {% trans 'Recorded' %}
|
{% fa5_icon 'bookmark' %} {% trans 'Recorded' %}
|
||||||
</th>
|
</th>
|
||||||
<th scope="col">
|
|
||||||
{% trans 'Total' %}
|
|
||||||
</th>
|
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
@@ -34,16 +34,16 @@
|
|||||||
{{law.long_name}}
|
{{law.long_name}}
|
||||||
</small>
|
</small>
|
||||||
</td>
|
</td>
|
||||||
|
<td>{{law.num|default_if_zero:"-"}}</td>
|
||||||
<td>{{law.num_checked|default_if_zero:"-"}}</td>
|
<td>{{law.num_checked|default_if_zero:"-"}}</td>
|
||||||
<td>{{law.num_recorded|default_if_zero:"-"}}</td>
|
<td>{{law.num_recorded|default_if_zero:"-"}}</td>
|
||||||
<td>{{law.num|default_if_zero:"-"}}</td>
|
|
||||||
</tr>
|
</tr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
<tr>
|
<tr>
|
||||||
<td><strong>{% trans 'Total' %}</strong></td>
|
<td><strong>{% trans 'Total' %}</strong></td>
|
||||||
|
<td><strong>{{report.intervention_report.law_sum|default_if_zero:"-"}}</strong></td>
|
||||||
<td><strong>{{report.intervention_report.law_sum_checked|default_if_zero:"-"}}</strong></td>
|
<td><strong>{{report.intervention_report.law_sum_checked|default_if_zero:"-"}}</strong></td>
|
||||||
<td><strong>{{report.intervention_report.law_sum_recorded|default_if_zero:"-"}}</strong></td>
|
<td><strong>{{report.intervention_report.law_sum_recorded|default_if_zero:"-"}}</strong></td>
|
||||||
<td><strong>{{report.intervention_report.law_sum|default_if_zero:"-"}}</strong></td>
|
|
||||||
</tr>
|
</tr>
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
|||||||
@@ -14,26 +14,26 @@
|
|||||||
<table class="table table-hover">
|
<table class="table table-hover">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th scope="col" class="w-25">{% fa5_icon 'star' %} {% trans 'Type' %}</th>
|
<th scope="col" class="w-25">{% trans 'Type' %}</th>
|
||||||
<th scope="col">{% fa5_icon 'bookmark' %} {% trans 'Recorded' %}</th>
|
|
||||||
<th scope="col">{% trans 'Total' %}</th>
|
<th scope="col">{% trans 'Total' %}</th>
|
||||||
|
<th scope="col">{% fa5_icon 'bookmark' %} {% trans 'Recorded' %}</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
<tr>
|
<tr>
|
||||||
<td>{% trans 'Intervention' %}</td>
|
<td>{% trans 'Intervention' %}</td>
|
||||||
<td>{{report.old_data_report.queryset_intervention_recorded_count|default_if_zero:"-"}}</td>
|
|
||||||
<td>{{report.old_data_report.queryset_intervention_count|default_if_zero:"-"}}</td>
|
<td>{{report.old_data_report.queryset_intervention_count|default_if_zero:"-"}}</td>
|
||||||
|
<td>{{report.old_data_report.queryset_intervention_recorded_count|default_if_zero:"-"}}</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td>{% trans 'Compensation' %}</td>
|
<td>{% trans 'Compensation' %}</td>
|
||||||
<td>{{report.old_data_report.queryset_comps_recorded_count|default_if_zero:"-"}}</td>
|
|
||||||
<td>{{report.old_data_report.queryset_comps_count|default_if_zero:"-"}}</td>
|
<td>{{report.old_data_report.queryset_comps_count|default_if_zero:"-"}}</td>
|
||||||
|
<td>{{report.old_data_report.queryset_comps_recorded_count|default_if_zero:"-"}}</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td>{% trans 'Eco-account' %}</td>
|
<td>{% trans 'Eco-account' %}</td>
|
||||||
<td>{{report.old_data_report.queryset_acc_recorded_count|default_if_zero:"-"}}</td>
|
|
||||||
<td>{{report.old_data_report.queryset_acc_count|default_if_zero:"-"}}</td>
|
<td>{{report.old_data_report.queryset_acc_count|default_if_zero:"-"}}</td>
|
||||||
|
<td>{{report.old_data_report.queryset_acc_recorded_count|default_if_zero:"-"}}</td>
|
||||||
</tr>
|
</tr>
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
|||||||
@@ -10,7 +10,7 @@
|
|||||||
{% fa5_icon 'pencil-ruler' %}
|
{% fa5_icon 'pencil-ruler' %}
|
||||||
{% trans 'Old interventions' %}
|
{% trans 'Old interventions' %}
|
||||||
</h5>
|
</h5>
|
||||||
<span>{% trans 'Before' %} 16.06.2018</span>
|
<span>{% trans 'Binding date before' %} 16.06.2018</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -108,7 +108,7 @@ class TempExcelFile:
|
|||||||
for _iter_entry in _iter_obj:
|
for _iter_entry in _iter_obj:
|
||||||
j = 0
|
j = 0
|
||||||
for _iter_attr in _attrs:
|
for _iter_attr in _attrs:
|
||||||
_new_cell = ws.cell(start_cell.row + i, start_cell.column + j, getattr(_iter_entry, _iter_attr))
|
_new_cell = ws.cell(start_cell.row + i, start_cell.column + j, _iter_entry.get(_iter_attr, "MISSING"))
|
||||||
_new_cell.border = border_style
|
_new_cell.border = border_style
|
||||||
j += 1
|
j += 1
|
||||||
i += 1
|
i += 1
|
||||||
|
|||||||
Binary file not shown.
@@ -137,22 +137,36 @@ class TimespanReport:
|
|||||||
).order_by(
|
).order_by(
|
||||||
"long_name"
|
"long_name"
|
||||||
)
|
)
|
||||||
# Fetch all law ids which are used by any .legal object of an intervention object
|
|
||||||
intervention_laws_total = self.queryset.values_list("legal__laws__id")
|
evaluated_laws = []
|
||||||
intervention_laws_checked = self.queryset.filter(checked__isnull=False).values_list("legal__laws__id")
|
sum_num_checked = 0
|
||||||
intervention_laws_recorded = self.queryset.filter(recorded__isnull=False).values_list(
|
sum_num_recorded = 0
|
||||||
"legal__laws__id")
|
sum_num = 0
|
||||||
# Count how often which law id appears in the above list, return only the long_name of the law and the resulting
|
for law in laws:
|
||||||
# count (here 'num'). This is for keeping the db fetch as small as possible
|
num = self.queryset.filter(
|
||||||
# Compute the sum for total, checked and recorded
|
legal__laws__atom_id=law.atom_id
|
||||||
self.evaluated_laws = laws.annotate(
|
).count()
|
||||||
num=Count("id", filter=Q(id__in=intervention_laws_total)),
|
num_checked = self.queryset_checked.filter(
|
||||||
num_checked=Count("id", filter=Q(id__in=intervention_laws_checked)),
|
legal__laws__atom_id=law.atom_id
|
||||||
num_recorded=Count("id", filter=Q(id__in=intervention_laws_recorded)),
|
).count()
|
||||||
).values_list("short_name", "long_name", "num_checked", "num_recorded", "num", named=True)
|
num_recorded = self.queryset_recorded.filter(
|
||||||
self.law_sum = self.evaluated_laws.aggregate(sum_num=Sum("num"))["sum_num"]
|
legal__laws__atom_id=law.atom_id
|
||||||
self.law_sum_checked = self.evaluated_laws.aggregate(sum_num_checked=Sum("num_checked"))["sum_num_checked"]
|
).count()
|
||||||
self.law_sum_recorded = self.evaluated_laws.aggregate(sum_num_recorded=Sum("num_recorded"))["sum_num_recorded"]
|
evaluated_laws.append({
|
||||||
|
"short_name": law.short_name,
|
||||||
|
"long_name": law.long_name,
|
||||||
|
"num": num,
|
||||||
|
"num_checked": num_checked,
|
||||||
|
"num_recorded": num_recorded,
|
||||||
|
})
|
||||||
|
sum_num += num
|
||||||
|
sum_num_checked += num_checked
|
||||||
|
sum_num_recorded += num_recorded
|
||||||
|
|
||||||
|
self.evaluated_laws = evaluated_laws
|
||||||
|
self.law_sum = sum_num
|
||||||
|
self.law_sum_checked = sum_num_checked
|
||||||
|
self.law_sum_recorded = sum_num_recorded
|
||||||
|
|
||||||
def _evaluate_compensations(self):
|
def _evaluate_compensations(self):
|
||||||
""" Analyzes the types of compensation distribution
|
""" Analyzes the types of compensation distribution
|
||||||
|
|||||||
@@ -6,6 +6,7 @@
|
|||||||
"title": "Test_compensation",
|
"title": "Test_compensation",
|
||||||
"is_cef": false,
|
"is_cef": false,
|
||||||
"is_coherence_keeping": false,
|
"is_coherence_keeping": false,
|
||||||
|
"is_pik": false,
|
||||||
"intervention": "MUST_BE_SET_IN_TEST",
|
"intervention": "MUST_BE_SET_IN_TEST",
|
||||||
"before_states": [
|
"before_states": [
|
||||||
],
|
],
|
||||||
|
|||||||
@@ -5,10 +5,14 @@
|
|||||||
"properties": {
|
"properties": {
|
||||||
"title": "Test_ecoaccount",
|
"title": "Test_ecoaccount",
|
||||||
"deductable_surface": 10000.0,
|
"deductable_surface": 10000.0,
|
||||||
|
"is_pik": false,
|
||||||
"responsible": {
|
"responsible": {
|
||||||
"conservation_office": null,
|
"conservation_office": null,
|
||||||
"conservation_file_number": null,
|
"conservation_file_number": null,
|
||||||
"handler": null
|
"handler": {
|
||||||
|
"type": null,
|
||||||
|
"detail": "Someone"
|
||||||
|
}
|
||||||
},
|
},
|
||||||
"legal": {
|
"legal": {
|
||||||
"agreement_date": null
|
"agreement_date": null
|
||||||
|
|||||||
@@ -4,10 +4,14 @@
|
|||||||
],
|
],
|
||||||
"properties": {
|
"properties": {
|
||||||
"title": "Test_ema",
|
"title": "Test_ema",
|
||||||
|
"is_pik": false,
|
||||||
"responsible": {
|
"responsible": {
|
||||||
"conservation_office": null,
|
"conservation_office": null,
|
||||||
"conservation_file_number": null,
|
"conservation_file_number": null,
|
||||||
"handler": null
|
"handler": {
|
||||||
|
"type": null,
|
||||||
|
"detail": "Someone"
|
||||||
|
}
|
||||||
},
|
},
|
||||||
"before_states": [
|
"before_states": [
|
||||||
],
|
],
|
||||||
|
|||||||
@@ -9,7 +9,10 @@
|
|||||||
"registration_file_number": null,
|
"registration_file_number": null,
|
||||||
"conservation_office": null,
|
"conservation_office": null,
|
||||||
"conservation_file_number": null,
|
"conservation_file_number": null,
|
||||||
"handler": null
|
"handler": {
|
||||||
|
"type": null,
|
||||||
|
"detail": "Someone"
|
||||||
|
}
|
||||||
},
|
},
|
||||||
"legal": {
|
"legal": {
|
||||||
"registration_date": null,
|
"registration_date": null,
|
||||||
|
|||||||
@@ -109,8 +109,8 @@ class APIV1CreateTestCase(BaseAPIV1TestCase):
|
|||||||
Returns:
|
Returns:
|
||||||
|
|
||||||
"""
|
"""
|
||||||
self.intervention.share_with(self.superuser)
|
self.intervention.share_with_user(self.superuser)
|
||||||
self.eco_account.share_with(self.superuser)
|
self.eco_account.share_with_user(self.superuser)
|
||||||
|
|
||||||
url = reverse("api:v1:deduction")
|
url = reverse("api:v1:deduction")
|
||||||
json_file_path = "api/tests/v1/create/deduction_create_post_body.json"
|
json_file_path = "api/tests/v1/create/deduction_create_post_body.json"
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ class APIV1DeleteTestCase(BaseAPIV1TestCase):
|
|||||||
|
|
||||||
"""
|
"""
|
||||||
test_intervention = self.create_dummy_intervention()
|
test_intervention = self.create_dummy_intervention()
|
||||||
test_intervention.share_with(self.superuser)
|
test_intervention.share_with_user(self.superuser)
|
||||||
url = reverse("api:v1:intervention", args=(str(test_intervention.id),))
|
url = reverse("api:v1:intervention", args=(str(test_intervention.id),))
|
||||||
self._test_delete_object(test_intervention, url)
|
self._test_delete_object(test_intervention, url)
|
||||||
|
|
||||||
@@ -68,7 +68,7 @@ class APIV1DeleteTestCase(BaseAPIV1TestCase):
|
|||||||
|
|
||||||
"""
|
"""
|
||||||
test_comp = self.create_dummy_compensation()
|
test_comp = self.create_dummy_compensation()
|
||||||
test_comp.share_with(self.superuser)
|
test_comp.share_with_user(self.superuser)
|
||||||
url = reverse("api:v1:compensation", args=(str(test_comp.id),))
|
url = reverse("api:v1:compensation", args=(str(test_comp.id),))
|
||||||
self._test_delete_object(test_comp, url)
|
self._test_delete_object(test_comp, url)
|
||||||
|
|
||||||
@@ -79,7 +79,7 @@ class APIV1DeleteTestCase(BaseAPIV1TestCase):
|
|||||||
|
|
||||||
"""
|
"""
|
||||||
test_acc = self.create_dummy_eco_account()
|
test_acc = self.create_dummy_eco_account()
|
||||||
test_acc.share_with(self.superuser)
|
test_acc.share_with_user(self.superuser)
|
||||||
url = reverse("api:v1:ecoaccount", args=(str(test_acc.id),))
|
url = reverse("api:v1:ecoaccount", args=(str(test_acc.id),))
|
||||||
self._test_delete_object(test_acc, url)
|
self._test_delete_object(test_acc, url)
|
||||||
|
|
||||||
@@ -90,7 +90,7 @@ class APIV1DeleteTestCase(BaseAPIV1TestCase):
|
|||||||
|
|
||||||
"""
|
"""
|
||||||
test_ema = self.create_dummy_ema()
|
test_ema = self.create_dummy_ema()
|
||||||
test_ema.share_with(self.superuser)
|
test_ema.share_with_user(self.superuser)
|
||||||
url = reverse("api:v1:ema", args=(str(test_ema.id),))
|
url = reverse("api:v1:ema", args=(str(test_ema.id),))
|
||||||
self._test_delete_object(test_ema, url)
|
self._test_delete_object(test_ema, url)
|
||||||
|
|
||||||
@@ -101,7 +101,7 @@ class APIV1DeleteTestCase(BaseAPIV1TestCase):
|
|||||||
|
|
||||||
"""
|
"""
|
||||||
test_deduction = self.create_dummy_deduction()
|
test_deduction = self.create_dummy_deduction()
|
||||||
test_deduction.intervention.share_with(self.superuser)
|
test_deduction.intervention.share_with_user(self.superuser)
|
||||||
url = reverse("api:v1:deduction", args=(str(test_deduction.id),))
|
url = reverse("api:v1:deduction", args=(str(test_deduction.id),))
|
||||||
|
|
||||||
response = self._run_delete_request(url)
|
response = self._run_delete_request(url)
|
||||||
|
|||||||
@@ -36,7 +36,12 @@ class APIV1GetTestCase(BaseAPIV1TestCase):
|
|||||||
"""
|
"""
|
||||||
response = self._run_get_request(url)
|
response = self._run_get_request(url)
|
||||||
content = json.loads(response.content)
|
content = json.loads(response.content)
|
||||||
geojson = content[str(obj.id)]
|
self.assertIn("rpp", content)
|
||||||
|
self.assertIn("p", content)
|
||||||
|
self.assertIn("next", content)
|
||||||
|
self.assertIn("results", content)
|
||||||
|
paginated_content = content["results"]
|
||||||
|
geojson = paginated_content[str(obj.id)]
|
||||||
self.assertEqual(response.status_code, 200, msg=response.content)
|
self.assertEqual(response.status_code, 200, msg=response.content)
|
||||||
return geojson
|
return geojson
|
||||||
|
|
||||||
@@ -59,7 +64,7 @@ class APIV1GetTestCase(BaseAPIV1TestCase):
|
|||||||
Returns:
|
Returns:
|
||||||
|
|
||||||
"""
|
"""
|
||||||
self.intervention.share_with(self.superuser)
|
self.intervention.share_with_user(self.superuser)
|
||||||
url = reverse("api:v1:intervention", args=(str(self.intervention.id),))
|
url = reverse("api:v1:intervention", args=(str(self.intervention.id),))
|
||||||
geojson = self._test_get_object(self.intervention, url)
|
geojson = self._test_get_object(self.intervention, url)
|
||||||
self._assert_geojson_format(geojson)
|
self._assert_geojson_format(geojson)
|
||||||
@@ -80,13 +85,33 @@ class APIV1GetTestCase(BaseAPIV1TestCase):
|
|||||||
except KeyError as e:
|
except KeyError as e:
|
||||||
self.fail(e)
|
self.fail(e)
|
||||||
|
|
||||||
|
def test_get_shared(self):
|
||||||
|
""" Tests api GET on shared info of the intervention
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
|
||||||
|
"""
|
||||||
|
self.intervention.share_with_user(self.superuser)
|
||||||
|
self.intervention.share_with_team(self.team)
|
||||||
|
url = reverse("api:v1:intervention-share", args=(str(self.intervention.id),))
|
||||||
|
response = self._run_get_request(url)
|
||||||
|
content = json.loads(response.content)
|
||||||
|
self.assertIn("users", content)
|
||||||
|
self.assertIn(self.superuser.username, content["users"])
|
||||||
|
self.assertEqual(1, len(content["users"]))
|
||||||
|
self.assertIn("teams", content)
|
||||||
|
self.assertEqual(1, len(content["teams"]))
|
||||||
|
for team in content["teams"]:
|
||||||
|
self.assertEqual(team["id"], str(self.team.id))
|
||||||
|
self.assertEqual(team["name"], self.team.name)
|
||||||
|
|
||||||
def test_get_compensation(self):
|
def test_get_compensation(self):
|
||||||
""" Tests api GET
|
""" Tests api GET
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
|
|
||||||
"""
|
"""
|
||||||
self.intervention.share_with(self.superuser)
|
self.intervention.share_with_user(self.superuser)
|
||||||
self.compensation.intervention = self.intervention
|
self.compensation.intervention = self.intervention
|
||||||
self.compensation.save()
|
self.compensation.save()
|
||||||
|
|
||||||
@@ -97,6 +122,7 @@ class APIV1GetTestCase(BaseAPIV1TestCase):
|
|||||||
props = geojson["properties"]
|
props = geojson["properties"]
|
||||||
props["is_cef"]
|
props["is_cef"]
|
||||||
props["is_coherence_keeping"]
|
props["is_coherence_keeping"]
|
||||||
|
props["is_pik"]
|
||||||
props["intervention"]
|
props["intervention"]
|
||||||
props["intervention"]["id"]
|
props["intervention"]["id"]
|
||||||
props["intervention"]["identifier"]
|
props["intervention"]["identifier"]
|
||||||
@@ -114,7 +140,7 @@ class APIV1GetTestCase(BaseAPIV1TestCase):
|
|||||||
Returns:
|
Returns:
|
||||||
|
|
||||||
"""
|
"""
|
||||||
self.eco_account.share_with(self.superuser)
|
self.eco_account.share_with_user(self.superuser)
|
||||||
|
|
||||||
url = reverse("api:v1:ecoaccount", args=(str(self.eco_account.id),))
|
url = reverse("api:v1:ecoaccount", args=(str(self.eco_account.id),))
|
||||||
geojson = self._test_get_object(self.eco_account, url)
|
geojson = self._test_get_object(self.eco_account, url)
|
||||||
@@ -143,7 +169,7 @@ class APIV1GetTestCase(BaseAPIV1TestCase):
|
|||||||
Returns:
|
Returns:
|
||||||
|
|
||||||
"""
|
"""
|
||||||
self.ema.share_with(self.superuser)
|
self.ema.share_with_user(self.superuser)
|
||||||
|
|
||||||
url = reverse("api:v1:ema", args=(str(self.ema.id),))
|
url = reverse("api:v1:ema", args=(str(self.ema.id),))
|
||||||
geojson = self._test_get_object(self.ema, url)
|
geojson = self._test_get_object(self.ema, url)
|
||||||
@@ -167,7 +193,7 @@ class APIV1GetTestCase(BaseAPIV1TestCase):
|
|||||||
Returns:
|
Returns:
|
||||||
|
|
||||||
"""
|
"""
|
||||||
self.deduction.intervention.share_with(self.superuser)
|
self.deduction.intervention.share_with_user(self.superuser)
|
||||||
|
|
||||||
url = reverse("api:v1:deduction", args=(str(self.deduction.id),))
|
url = reverse("api:v1:deduction", args=(str(self.deduction.id),))
|
||||||
_json = self._test_get_object(self.deduction, url)
|
_json = self._test_get_object(self.deduction, url)
|
||||||
|
|||||||
@@ -12,15 +12,17 @@ class BaseAPIV1TestCase(BaseTestCase):
|
|||||||
def setUpTestData(cls):
|
def setUpTestData(cls):
|
||||||
super().setUpTestData()
|
super().setUpTestData()
|
||||||
|
|
||||||
cls.superuser.get_API_token()
|
def setUp(self) -> None:
|
||||||
cls.superuser.api_token.is_active = True
|
super().setUp()
|
||||||
cls.superuser.api_token.save()
|
self.superuser.get_API_token()
|
||||||
default_group = cls.groups.get(name=DEFAULT_GROUP)
|
self.superuser.api_token.is_active = True
|
||||||
cls.superuser.groups.add(default_group)
|
self.superuser.api_token.save()
|
||||||
|
default_group = self.groups.get(name=DEFAULT_GROUP)
|
||||||
|
self.superuser.groups.add(default_group)
|
||||||
|
|
||||||
cls.header_data = {
|
self.header_data = {
|
||||||
"HTTP_ksptoken": cls.superuser.api_token.token,
|
"HTTP_ksptoken": self.superuser.api_token.token,
|
||||||
"HTTP_kspuser": cls.superuser.username,
|
"HTTP_kspuser": self.superuser.username,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -46,6 +46,7 @@
|
|||||||
"title": "TEST_compensation_CHANGED",
|
"title": "TEST_compensation_CHANGED",
|
||||||
"is_cef": true,
|
"is_cef": true,
|
||||||
"is_coherence_keeping": true,
|
"is_coherence_keeping": true,
|
||||||
|
"is_pik": true,
|
||||||
"intervention": "CHANGE_BEFORE_RUN!!!",
|
"intervention": "CHANGE_BEFORE_RUN!!!",
|
||||||
"before_states": [],
|
"before_states": [],
|
||||||
"after_states": [],
|
"after_states": [],
|
||||||
|
|||||||
@@ -45,10 +45,14 @@
|
|||||||
"properties": {
|
"properties": {
|
||||||
"title": "TEST_account_CHANGED",
|
"title": "TEST_account_CHANGED",
|
||||||
"deductable_surface": "100000.0",
|
"deductable_surface": "100000.0",
|
||||||
|
"is_pik": true,
|
||||||
"responsible": {
|
"responsible": {
|
||||||
"conservation_office": null,
|
"conservation_office": null,
|
||||||
"conservation_file_number": "123-TEST",
|
"conservation_file_number": "123-TEST",
|
||||||
"handler": "TEST_HANDLER_CHANGED"
|
"handler": {
|
||||||
|
"type": null,
|
||||||
|
"detail": "TEST HANDLER CHANGED"
|
||||||
|
}
|
||||||
},
|
},
|
||||||
"legal": {
|
"legal": {
|
||||||
"agreement_date": "2022-01-11"
|
"agreement_date": "2022-01-11"
|
||||||
|
|||||||
@@ -47,8 +47,12 @@
|
|||||||
"responsible": {
|
"responsible": {
|
||||||
"conservation_office": null,
|
"conservation_office": null,
|
||||||
"conservation_file_number": "TEST_CHANGED",
|
"conservation_file_number": "TEST_CHANGED",
|
||||||
"handler": "TEST_HANDLER_CHANGED"
|
"handler": {
|
||||||
|
"type": null,
|
||||||
|
"detail": "TEST_HANDLER_CHANGED"
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
"is_pik": true,
|
||||||
"before_states": [],
|
"before_states": [],
|
||||||
"after_states": [],
|
"after_states": [],
|
||||||
"actions": [],
|
"actions": [],
|
||||||
|
|||||||
@@ -0,0 +1,8 @@
|
|||||||
|
{
|
||||||
|
"users": [
|
||||||
|
"CHANGE_ME"
|
||||||
|
],
|
||||||
|
"teams": [
|
||||||
|
"CHANGE_ME"
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -49,7 +49,10 @@
|
|||||||
"registration_file_number": "CHANGED",
|
"registration_file_number": "CHANGED",
|
||||||
"conservation_office": null,
|
"conservation_office": null,
|
||||||
"conservation_file_number": "CHANGED",
|
"conservation_file_number": "CHANGED",
|
||||||
"handler": null
|
"handler": {
|
||||||
|
"type": null,
|
||||||
|
"detail": "TEST_HANDLER_CHANGED"
|
||||||
|
}
|
||||||
},
|
},
|
||||||
"legal": {
|
"legal": {
|
||||||
"registration_date": "2022-02-01",
|
"registration_date": "2022-02-01",
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ from django.contrib.gis import geos
|
|||||||
from django.urls import reverse
|
from django.urls import reverse
|
||||||
|
|
||||||
from api.tests.v1.share.test_api_sharing import BaseAPIV1TestCase
|
from api.tests.v1.share.test_api_sharing import BaseAPIV1TestCase
|
||||||
|
from konova.sub_settings.lanis_settings import DEFAULT_SRID_RLP
|
||||||
|
|
||||||
|
|
||||||
class APIV1UpdateTestCase(BaseAPIV1TestCase):
|
class APIV1UpdateTestCase(BaseAPIV1TestCase):
|
||||||
@@ -52,7 +53,7 @@ class APIV1UpdateTestCase(BaseAPIV1TestCase):
|
|||||||
Returns:
|
Returns:
|
||||||
|
|
||||||
"""
|
"""
|
||||||
self.intervention.share_with(self.superuser)
|
self.intervention.share_with_user(self.superuser)
|
||||||
modified_on = self.intervention.modified
|
modified_on = self.intervention.modified
|
||||||
url = reverse("api:v1:intervention", args=(str(self.intervention.id),))
|
url = reverse("api:v1:intervention", args=(str(self.intervention.id),))
|
||||||
json_file_path = "api/tests/v1/update/intervention_update_put_body.json"
|
json_file_path = "api/tests/v1/update/intervention_update_put_body.json"
|
||||||
@@ -63,6 +64,7 @@ class APIV1UpdateTestCase(BaseAPIV1TestCase):
|
|||||||
|
|
||||||
put_props = put_body["properties"]
|
put_props = put_body["properties"]
|
||||||
put_geom = geos.fromstr(json.dumps(put_body))
|
put_geom = geos.fromstr(json.dumps(put_body))
|
||||||
|
put_geom.transform(DEFAULT_SRID_RLP)
|
||||||
self.assertEqual(put_geom, self.intervention.geometry.geom)
|
self.assertEqual(put_geom, self.intervention.geometry.geom)
|
||||||
self.assertEqual(put_props["title"], self.intervention.title)
|
self.assertEqual(put_props["title"], self.intervention.title)
|
||||||
self.assertNotEqual(modified_on, self.intervention.modified)
|
self.assertNotEqual(modified_on, self.intervention.modified)
|
||||||
@@ -79,7 +81,7 @@ class APIV1UpdateTestCase(BaseAPIV1TestCase):
|
|||||||
"""
|
"""
|
||||||
self.compensation.intervention = self.intervention
|
self.compensation.intervention = self.intervention
|
||||||
self.compensation.save()
|
self.compensation.save()
|
||||||
self.intervention.share_with(self.superuser)
|
self.intervention.share_with_user(self.superuser)
|
||||||
|
|
||||||
modified_on = self.compensation.modified
|
modified_on = self.compensation.modified
|
||||||
url = reverse("api:v1:compensation", args=(str(self.compensation.id),))
|
url = reverse("api:v1:compensation", args=(str(self.compensation.id),))
|
||||||
@@ -92,11 +94,13 @@ class APIV1UpdateTestCase(BaseAPIV1TestCase):
|
|||||||
|
|
||||||
put_props = put_body["properties"]
|
put_props = put_body["properties"]
|
||||||
put_geom = geos.fromstr(json.dumps(put_body))
|
put_geom = geos.fromstr(json.dumps(put_body))
|
||||||
|
put_geom.transform(DEFAULT_SRID_RLP)
|
||||||
self.assertEqual(put_geom, self.compensation.geometry.geom)
|
self.assertEqual(put_geom, self.compensation.geometry.geom)
|
||||||
self.assertEqual(put_props["title"], self.compensation.title)
|
self.assertEqual(put_props["title"], self.compensation.title)
|
||||||
self.assertNotEqual(modified_on, self.compensation.modified)
|
self.assertNotEqual(modified_on, self.compensation.modified)
|
||||||
self.assertEqual(put_props["is_cef"], self.compensation.is_cef)
|
self.assertEqual(put_props["is_cef"], self.compensation.is_cef)
|
||||||
self.assertEqual(put_props["is_coherence_keeping"], self.compensation.is_coherence_keeping)
|
self.assertEqual(put_props["is_coherence_keeping"], self.compensation.is_coherence_keeping)
|
||||||
|
self.assertEqual(put_props["is_pik"], self.compensation.is_pik)
|
||||||
self.assertEqual(len(put_props["actions"]), self.compensation.actions.count())
|
self.assertEqual(len(put_props["actions"]), self.compensation.actions.count())
|
||||||
self.assertEqual(len(put_props["before_states"]), self.compensation.before_states.count())
|
self.assertEqual(len(put_props["before_states"]), self.compensation.before_states.count())
|
||||||
self.assertEqual(len(put_props["after_states"]), self.compensation.after_states.count())
|
self.assertEqual(len(put_props["after_states"]), self.compensation.after_states.count())
|
||||||
@@ -108,7 +112,7 @@ class APIV1UpdateTestCase(BaseAPIV1TestCase):
|
|||||||
Returns:
|
Returns:
|
||||||
|
|
||||||
"""
|
"""
|
||||||
self.eco_account.share_with(self.superuser)
|
self.eco_account.share_with_user(self.superuser)
|
||||||
|
|
||||||
modified_on = self.eco_account.modified
|
modified_on = self.eco_account.modified
|
||||||
url = reverse("api:v1:ecoaccount", args=(str(self.eco_account.id),))
|
url = reverse("api:v1:ecoaccount", args=(str(self.eco_account.id),))
|
||||||
@@ -120,13 +124,14 @@ class APIV1UpdateTestCase(BaseAPIV1TestCase):
|
|||||||
|
|
||||||
put_props = put_body["properties"]
|
put_props = put_body["properties"]
|
||||||
put_geom = geos.fromstr(json.dumps(put_body))
|
put_geom = geos.fromstr(json.dumps(put_body))
|
||||||
|
put_geom.transform(DEFAULT_SRID_RLP)
|
||||||
self.assertEqual(put_geom, self.eco_account.geometry.geom)
|
self.assertEqual(put_geom, self.eco_account.geometry.geom)
|
||||||
self.assertEqual(put_props["title"], self.eco_account.title)
|
self.assertEqual(put_props["title"], self.eco_account.title)
|
||||||
self.assertNotEqual(modified_on, self.eco_account.modified)
|
self.assertNotEqual(modified_on, self.eco_account.modified)
|
||||||
self.assertEqual(put_props["deductable_surface"], str(self.eco_account.deductable_surface))
|
self.assertEqual(put_props["deductable_surface"], str(self.eco_account.deductable_surface))
|
||||||
self.assertEqual(put_props["responsible"]["conservation_office"], self.eco_account.responsible.conservation_office)
|
self.assertEqual(put_props["responsible"]["conservation_office"], self.eco_account.responsible.conservation_office)
|
||||||
self.assertEqual(put_props["responsible"]["conservation_file_number"], self.eco_account.responsible.conservation_file_number)
|
self.assertEqual(put_props["responsible"]["conservation_file_number"], self.eco_account.responsible.conservation_file_number)
|
||||||
self.assertEqual(put_props["responsible"]["handler"], self.eco_account.responsible.handler)
|
self.assertEqual(put_props["responsible"]["handler"]["detail"], self.eco_account.responsible.handler.detail)
|
||||||
self.assertEqual(put_props["legal"]["agreement_date"], str(self.eco_account.legal.registration_date))
|
self.assertEqual(put_props["legal"]["agreement_date"], str(self.eco_account.legal.registration_date))
|
||||||
self.assertEqual(len(put_props["actions"]), self.eco_account.actions.count())
|
self.assertEqual(len(put_props["actions"]), self.eco_account.actions.count())
|
||||||
self.assertEqual(len(put_props["before_states"]), self.eco_account.before_states.count())
|
self.assertEqual(len(put_props["before_states"]), self.eco_account.before_states.count())
|
||||||
@@ -139,7 +144,7 @@ class APIV1UpdateTestCase(BaseAPIV1TestCase):
|
|||||||
Returns:
|
Returns:
|
||||||
|
|
||||||
"""
|
"""
|
||||||
self.ema.share_with(self.superuser)
|
self.ema.share_with_user(self.superuser)
|
||||||
|
|
||||||
modified_on = self.ema.modified
|
modified_on = self.ema.modified
|
||||||
url = reverse("api:v1:ema", args=(str(self.ema.id),))
|
url = reverse("api:v1:ema", args=(str(self.ema.id),))
|
||||||
@@ -151,12 +156,13 @@ class APIV1UpdateTestCase(BaseAPIV1TestCase):
|
|||||||
|
|
||||||
put_props = put_body["properties"]
|
put_props = put_body["properties"]
|
||||||
put_geom = geos.fromstr(json.dumps(put_body))
|
put_geom = geos.fromstr(json.dumps(put_body))
|
||||||
|
put_geom.transform(DEFAULT_SRID_RLP)
|
||||||
self.assertEqual(put_geom, self.ema.geometry.geom)
|
self.assertEqual(put_geom, self.ema.geometry.geom)
|
||||||
self.assertEqual(put_props["title"], self.ema.title)
|
self.assertEqual(put_props["title"], self.ema.title)
|
||||||
self.assertNotEqual(modified_on, self.ema.modified)
|
self.assertNotEqual(modified_on, self.ema.modified)
|
||||||
self.assertEqual(put_props["responsible"]["conservation_office"], self.ema.responsible.conservation_office)
|
self.assertEqual(put_props["responsible"]["conservation_office"], self.ema.responsible.conservation_office)
|
||||||
self.assertEqual(put_props["responsible"]["conservation_file_number"], self.ema.responsible.conservation_file_number)
|
self.assertEqual(put_props["responsible"]["conservation_file_number"], self.ema.responsible.conservation_file_number)
|
||||||
self.assertEqual(put_props["responsible"]["handler"], self.ema.responsible.handler)
|
self.assertEqual(put_props["responsible"]["handler"]["detail"], self.ema.responsible.handler.detail)
|
||||||
self.assertEqual(len(put_props["actions"]), self.ema.actions.count())
|
self.assertEqual(len(put_props["actions"]), self.ema.actions.count())
|
||||||
self.assertEqual(len(put_props["before_states"]), self.ema.before_states.count())
|
self.assertEqual(len(put_props["before_states"]), self.ema.before_states.count())
|
||||||
self.assertEqual(len(put_props["after_states"]), self.ema.after_states.count())
|
self.assertEqual(len(put_props["after_states"]), self.ema.after_states.count())
|
||||||
@@ -168,8 +174,8 @@ class APIV1UpdateTestCase(BaseAPIV1TestCase):
|
|||||||
Returns:
|
Returns:
|
||||||
|
|
||||||
"""
|
"""
|
||||||
self.deduction.intervention.share_with(self.superuser)
|
self.deduction.intervention.share_with_user(self.superuser)
|
||||||
self.deduction.account.share_with(self.superuser)
|
self.deduction.account.share_with_user(self.superuser)
|
||||||
|
|
||||||
url = reverse("api:v1:deduction", args=(str(self.deduction.id),))
|
url = reverse("api:v1:deduction", args=(str(self.deduction.id),))
|
||||||
json_file_path = "api/tests/v1/update/deduction_update_put_body.json"
|
json_file_path = "api/tests/v1/update/deduction_update_put_body.json"
|
||||||
@@ -184,3 +190,24 @@ class APIV1UpdateTestCase(BaseAPIV1TestCase):
|
|||||||
self.assertEqual(put_body["intervention"], str(self.deduction.intervention.id))
|
self.assertEqual(put_body["intervention"], str(self.deduction.intervention.id))
|
||||||
self.assertEqual(put_body["eco_account"], str(self.deduction.account.id))
|
self.assertEqual(put_body["eco_account"], str(self.deduction.account.id))
|
||||||
self.assertEqual(put_body["surface"], self.deduction.surface)
|
self.assertEqual(put_body["surface"], self.deduction.surface)
|
||||||
|
|
||||||
|
def test_update_share_intervention(self):
|
||||||
|
self.intervention.share_with_user(self.superuser)
|
||||||
|
url = reverse("api:v1:intervention-share", args=(str(self.intervention.id),))
|
||||||
|
json_file_path = "api/tests/v1/update/intervention_share_update_put_body.json"
|
||||||
|
with open(json_file_path) as json_file:
|
||||||
|
put_body = json.load(fp=json_file)
|
||||||
|
put_body["users"] = [self.user.username]
|
||||||
|
put_body["teams"] = [self.team.name]
|
||||||
|
|
||||||
|
self.assertFalse(self.intervention.is_shared_with(self.user))
|
||||||
|
self.assertEqual(0, self.intervention.shared_teams.count())
|
||||||
|
|
||||||
|
response = self._run_update_request(url, put_body)
|
||||||
|
self.assertEqual(response.status_code, 200, msg=response.content)
|
||||||
|
self.intervention.refresh_from_db()
|
||||||
|
|
||||||
|
self.assertEqual(1, self.intervention.shared_teams.count())
|
||||||
|
self.assertEqual(2, self.intervention.shared_users.count())
|
||||||
|
self.assertEqual(self.team.name, self.intervention.shared_teams.first().name)
|
||||||
|
self.assertTrue(self.intervention.is_shared_with(self.user))
|
||||||
|
|||||||
@@ -10,7 +10,9 @@ from abc import abstractmethod
|
|||||||
|
|
||||||
from django.contrib.gis import geos
|
from django.contrib.gis import geos
|
||||||
from django.contrib.gis.geos import GEOSGeometry
|
from django.contrib.gis.geos import GEOSGeometry
|
||||||
|
from django.core.paginator import Paginator
|
||||||
|
|
||||||
|
from konova.sub_settings.lanis_settings import DEFAULT_SRID_RLP
|
||||||
from konova.utils.message_templates import DATA_UNSHARED
|
from konova.utils.message_templates import DATA_UNSHARED
|
||||||
|
|
||||||
|
|
||||||
@@ -19,6 +21,10 @@ class AbstractModelAPISerializer:
|
|||||||
lookup = None
|
lookup = None
|
||||||
properties_data = None
|
properties_data = None
|
||||||
|
|
||||||
|
rpp = None
|
||||||
|
page_number = None
|
||||||
|
paginator = None
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
abstract = True
|
abstract = True
|
||||||
|
|
||||||
@@ -80,9 +86,12 @@ class AbstractModelAPISerializer:
|
|||||||
Returns:
|
Returns:
|
||||||
serialized_data (dict)
|
serialized_data (dict)
|
||||||
"""
|
"""
|
||||||
entries = self.model.objects.filter(**self.lookup)
|
entries = self.model.objects.filter(**self.lookup).order_by("id")
|
||||||
|
self.paginator = Paginator(entries, self.rpp)
|
||||||
|
requested_entries = self.paginator.page(self.page_number)
|
||||||
|
|
||||||
serialized_data = {}
|
serialized_data = {}
|
||||||
for entry in entries:
|
for entry in requested_entries.object_list:
|
||||||
serialized_data[str(entry.id)] = self._model_to_geo_json(entry)
|
serialized_data[str(entry.id)] = self._model_to_geo_json(entry)
|
||||||
return serialized_data
|
return serialized_data
|
||||||
|
|
||||||
@@ -125,6 +134,8 @@ class AbstractModelAPISerializer:
|
|||||||
if isinstance(geojson, dict):
|
if isinstance(geojson, dict):
|
||||||
geojson = json.dumps(geojson)
|
geojson = json.dumps(geojson)
|
||||||
geometry = geos.fromstr(geojson)
|
geometry = geos.fromstr(geojson)
|
||||||
|
if geometry.srid != DEFAULT_SRID_RLP:
|
||||||
|
geometry.transform(DEFAULT_SRID_RLP)
|
||||||
if geometry.empty:
|
if geometry.empty:
|
||||||
geometry = None
|
geometry = None
|
||||||
return geometry
|
return geometry
|
||||||
|
|||||||
@@ -34,6 +34,7 @@ class CompensationAPISerializerV1(AbstractModelAPISerializerV1, AbstractCompensa
|
|||||||
def _extend_properties_data(self, entry):
|
def _extend_properties_data(self, entry):
|
||||||
self.properties_data["is_cef"] = entry.is_cef
|
self.properties_data["is_cef"] = entry.is_cef
|
||||||
self.properties_data["is_coherence_keeping"] = entry.is_coherence_keeping
|
self.properties_data["is_coherence_keeping"] = entry.is_coherence_keeping
|
||||||
|
self.properties_data["is_pik"] = entry.is_pik
|
||||||
self.properties_data["intervention"] = self.intervention_to_json(entry.intervention)
|
self.properties_data["intervention"] = self.intervention_to_json(entry.intervention)
|
||||||
self.properties_data["before_states"] = self._compensation_state_to_json(entry.before_states.all())
|
self.properties_data["before_states"] = self._compensation_state_to_json(entry.before_states.all())
|
||||||
self.properties_data["after_states"] = self._compensation_state_to_json(entry.after_states.all())
|
self.properties_data["after_states"] = self._compensation_state_to_json(entry.after_states.all())
|
||||||
@@ -113,6 +114,7 @@ class CompensationAPISerializerV1(AbstractModelAPISerializerV1, AbstractCompensa
|
|||||||
obj.title = properties["title"]
|
obj.title = properties["title"]
|
||||||
obj.is_cef = properties["is_cef"]
|
obj.is_cef = properties["is_cef"]
|
||||||
obj.is_coherence_keeping = properties["is_coherence_keeping"]
|
obj.is_coherence_keeping = properties["is_coherence_keeping"]
|
||||||
|
obj.is_pik = properties.get("is_pik", False)
|
||||||
obj = self.set_intervention(obj, properties["intervention"], user)
|
obj = self.set_intervention(obj, properties["intervention"], user)
|
||||||
|
|
||||||
obj.geometry.save()
|
obj.geometry.save()
|
||||||
@@ -149,6 +151,7 @@ class CompensationAPISerializerV1(AbstractModelAPISerializerV1, AbstractCompensa
|
|||||||
obj.title = properties["title"]
|
obj.title = properties["title"]
|
||||||
obj.is_cef = properties["is_cef"]
|
obj.is_cef = properties["is_cef"]
|
||||||
obj.is_coherence_keeping = properties["is_coherence_keeping"]
|
obj.is_coherence_keeping = properties["is_coherence_keeping"]
|
||||||
|
obj.is_pik = properties.get("is_pik", False)
|
||||||
obj.modified = update_action
|
obj.modified = update_action
|
||||||
obj.geometry.geom = self._create_geometry_from_json(json_model)
|
obj.geometry.geom = self._create_geometry_from_json(json_model)
|
||||||
obj.geometry.modified = update_action
|
obj.geometry.modified = update_action
|
||||||
|
|||||||
@@ -9,9 +9,9 @@ from django.db import transaction
|
|||||||
|
|
||||||
from api.utils.serializer.v1.serializer import AbstractModelAPISerializerV1, AbstractCompensationAPISerializerV1Mixin, \
|
from api.utils.serializer.v1.serializer import AbstractModelAPISerializerV1, AbstractCompensationAPISerializerV1Mixin, \
|
||||||
LegalAPISerializerV1Mixin, ResponsibilityAPISerializerV1Mixin, DeductableAPISerializerV1Mixin
|
LegalAPISerializerV1Mixin, ResponsibilityAPISerializerV1Mixin, DeductableAPISerializerV1Mixin
|
||||||
from codelist.settings import CODELIST_CONSERVATION_OFFICE_ID
|
from codelist.settings import CODELIST_CONSERVATION_OFFICE_ID, CODELIST_HANDLER_ID
|
||||||
from compensation.models import EcoAccount
|
from compensation.models import EcoAccount
|
||||||
from intervention.models import Legal, Responsibility
|
from intervention.models import Legal, Responsibility, Handler
|
||||||
from konova.models import Geometry
|
from konova.models import Geometry
|
||||||
from konova.tasks import celery_update_parcels
|
from konova.tasks import celery_update_parcels
|
||||||
from user.models import UserActionLogEntry
|
from user.models import UserActionLogEntry
|
||||||
@@ -25,6 +25,7 @@ class EcoAccountAPISerializerV1(AbstractModelAPISerializerV1,
|
|||||||
model = EcoAccount
|
model = EcoAccount
|
||||||
|
|
||||||
def _extend_properties_data(self, entry):
|
def _extend_properties_data(self, entry):
|
||||||
|
self.properties_data["is_pik"] = entry.is_pik
|
||||||
self.properties_data["deductable_surface"] = entry.deductable_surface
|
self.properties_data["deductable_surface"] = entry.deductable_surface
|
||||||
self.properties_data["deductable_surface_available"] = entry.deductable_surface - entry.get_deductions_surface()
|
self.properties_data["deductable_surface_available"] = entry.deductable_surface - entry.get_deductions_surface()
|
||||||
self.properties_data["responsible"] = self._responsible_to_json(entry.responsible)
|
self.properties_data["responsible"] = self._responsible_to_json(entry.responsible)
|
||||||
@@ -44,7 +45,7 @@ class EcoAccountAPISerializerV1(AbstractModelAPISerializerV1,
|
|||||||
return {
|
return {
|
||||||
"conservation_office": self._konova_code_to_json(responsible.conservation_office),
|
"conservation_office": self._konova_code_to_json(responsible.conservation_office),
|
||||||
"conservation_file_number": responsible.conservation_file_number,
|
"conservation_file_number": responsible.conservation_file_number,
|
||||||
"handler": responsible.handler,
|
"handler": self._handler_to_json(responsible.handler),
|
||||||
}
|
}
|
||||||
|
|
||||||
def _set_responsibility(self, obj, responsibility_data: dict):
|
def _set_responsibility(self, obj, responsibility_data: dict):
|
||||||
@@ -64,7 +65,11 @@ class EcoAccountAPISerializerV1(AbstractModelAPISerializerV1,
|
|||||||
CODELIST_CONSERVATION_OFFICE_ID,
|
CODELIST_CONSERVATION_OFFICE_ID,
|
||||||
)
|
)
|
||||||
obj.responsible.conservation_file_number = responsibility_data["conservation_file_number"]
|
obj.responsible.conservation_file_number = responsibility_data["conservation_file_number"]
|
||||||
obj.responsible.handler = responsibility_data["handler"]
|
obj.responsible.handler.type = self._konova_code_from_json(
|
||||||
|
responsibility_data["handler"]["type"],
|
||||||
|
CODELIST_HANDLER_ID,
|
||||||
|
)
|
||||||
|
obj.responsible.handler.detail = responsibility_data["handler"]["detail"]
|
||||||
return obj
|
return obj
|
||||||
|
|
||||||
def _set_legal(self, obj, legal_data):
|
def _set_legal(self, obj, legal_data):
|
||||||
@@ -92,7 +97,9 @@ class EcoAccountAPISerializerV1(AbstractModelAPISerializerV1,
|
|||||||
|
|
||||||
# Create linked objects
|
# Create linked objects
|
||||||
obj = EcoAccount()
|
obj = EcoAccount()
|
||||||
obj.responsible = Responsibility()
|
obj.responsible = Responsibility(
|
||||||
|
handler=Handler()
|
||||||
|
)
|
||||||
obj.legal = Legal()
|
obj.legal = Legal()
|
||||||
created = create_action
|
created = create_action
|
||||||
obj.created = created
|
obj.created = created
|
||||||
@@ -116,6 +123,7 @@ class EcoAccountAPISerializerV1(AbstractModelAPISerializerV1,
|
|||||||
properties = json_model["properties"]
|
properties = json_model["properties"]
|
||||||
obj.identifier = obj.generate_new_identifier()
|
obj.identifier = obj.generate_new_identifier()
|
||||||
obj.title = properties["title"]
|
obj.title = properties["title"]
|
||||||
|
obj.is_pik = properties.get("is_pik", False)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
obj.deductable_surface = float(properties["deductable_surface"])
|
obj.deductable_surface = float(properties["deductable_surface"])
|
||||||
@@ -128,6 +136,7 @@ class EcoAccountAPISerializerV1(AbstractModelAPISerializerV1,
|
|||||||
obj = self._set_legal(obj, properties["legal"])
|
obj = self._set_legal(obj, properties["legal"])
|
||||||
|
|
||||||
obj.geometry.save()
|
obj.geometry.save()
|
||||||
|
obj.responsible.handler.save()
|
||||||
obj.responsible.save()
|
obj.responsible.save()
|
||||||
obj.legal.save()
|
obj.legal.save()
|
||||||
obj.save()
|
obj.save()
|
||||||
@@ -162,6 +171,7 @@ class EcoAccountAPISerializerV1(AbstractModelAPISerializerV1,
|
|||||||
# Fill in data to objects
|
# Fill in data to objects
|
||||||
properties = json_model["properties"]
|
properties = json_model["properties"]
|
||||||
obj.title = properties["title"]
|
obj.title = properties["title"]
|
||||||
|
obj.is_pik = properties.get("is_pik", False)
|
||||||
obj.deductable_surface = float(properties["deductable_surface"])
|
obj.deductable_surface = float(properties["deductable_surface"])
|
||||||
obj.modified = update_action
|
obj.modified = update_action
|
||||||
obj.geometry.geom = self._create_geometry_from_json(json_model)
|
obj.geometry.geom = self._create_geometry_from_json(json_model)
|
||||||
@@ -170,6 +180,7 @@ class EcoAccountAPISerializerV1(AbstractModelAPISerializerV1,
|
|||||||
obj = self._set_legal(obj, properties["legal"])
|
obj = self._set_legal(obj, properties["legal"])
|
||||||
|
|
||||||
obj.geometry.save()
|
obj.geometry.save()
|
||||||
|
obj.responsible.handler.save()
|
||||||
obj.responsible.save()
|
obj.responsible.save()
|
||||||
obj.legal.save()
|
obj.legal.save()
|
||||||
obj.save()
|
obj.save()
|
||||||
|
|||||||
@@ -9,9 +9,9 @@ from django.db import transaction
|
|||||||
|
|
||||||
from api.utils.serializer.v1.serializer import AbstractModelAPISerializerV1, AbstractCompensationAPISerializerV1Mixin, \
|
from api.utils.serializer.v1.serializer import AbstractModelAPISerializerV1, AbstractCompensationAPISerializerV1Mixin, \
|
||||||
ResponsibilityAPISerializerV1Mixin
|
ResponsibilityAPISerializerV1Mixin
|
||||||
from codelist.settings import CODELIST_CONSERVATION_OFFICE_ID
|
from codelist.settings import CODELIST_CONSERVATION_OFFICE_ID, CODELIST_HANDLER_ID
|
||||||
from ema.models import Ema
|
from ema.models import Ema
|
||||||
from intervention.models import Responsibility
|
from intervention.models import Responsibility, Handler
|
||||||
from konova.models import Geometry
|
from konova.models import Geometry
|
||||||
from konova.tasks import celery_update_parcels
|
from konova.tasks import celery_update_parcels
|
||||||
from user.models import UserActionLogEntry
|
from user.models import UserActionLogEntry
|
||||||
@@ -21,6 +21,7 @@ class EmaAPISerializerV1(AbstractModelAPISerializerV1, AbstractCompensationAPISe
|
|||||||
model = Ema
|
model = Ema
|
||||||
|
|
||||||
def _extend_properties_data(self, entry):
|
def _extend_properties_data(self, entry):
|
||||||
|
self.properties_data["is_pik"] = entry.is_pik
|
||||||
self.properties_data["responsible"] = self._responsible_to_json(entry.responsible)
|
self.properties_data["responsible"] = self._responsible_to_json(entry.responsible)
|
||||||
self.properties_data["before_states"] = self._compensation_state_to_json(entry.before_states.all())
|
self.properties_data["before_states"] = self._compensation_state_to_json(entry.before_states.all())
|
||||||
self.properties_data["after_states"] = self._compensation_state_to_json(entry.after_states.all())
|
self.properties_data["after_states"] = self._compensation_state_to_json(entry.after_states.all())
|
||||||
@@ -31,7 +32,7 @@ class EmaAPISerializerV1(AbstractModelAPISerializerV1, AbstractCompensationAPISe
|
|||||||
return {
|
return {
|
||||||
"conservation_office": self._konova_code_to_json(responsible.conservation_office),
|
"conservation_office": self._konova_code_to_json(responsible.conservation_office),
|
||||||
"conservation_file_number": responsible.conservation_file_number,
|
"conservation_file_number": responsible.conservation_file_number,
|
||||||
"handler": responsible.handler,
|
"handler": self._handler_to_json(responsible.handler),
|
||||||
}
|
}
|
||||||
|
|
||||||
def _set_responsibility(self, obj, responsibility_data: dict):
|
def _set_responsibility(self, obj, responsibility_data: dict):
|
||||||
@@ -51,7 +52,11 @@ class EmaAPISerializerV1(AbstractModelAPISerializerV1, AbstractCompensationAPISe
|
|||||||
CODELIST_CONSERVATION_OFFICE_ID,
|
CODELIST_CONSERVATION_OFFICE_ID,
|
||||||
)
|
)
|
||||||
obj.responsible.conservation_file_number = responsibility_data["conservation_file_number"]
|
obj.responsible.conservation_file_number = responsibility_data["conservation_file_number"]
|
||||||
obj.responsible.handler = responsibility_data["handler"]
|
obj.responsible.handler.type = self._konova_code_from_json(
|
||||||
|
responsibility_data["handler"]["type"],
|
||||||
|
CODELIST_HANDLER_ID,
|
||||||
|
)
|
||||||
|
obj.responsible.handler.detail = responsibility_data["handler"]["detail"]
|
||||||
return obj
|
return obj
|
||||||
|
|
||||||
def _initialize_objects(self, json_model, user):
|
def _initialize_objects(self, json_model, user):
|
||||||
@@ -75,7 +80,9 @@ class EmaAPISerializerV1(AbstractModelAPISerializerV1, AbstractCompensationAPISe
|
|||||||
|
|
||||||
# Create linked objects
|
# Create linked objects
|
||||||
obj = Ema()
|
obj = Ema()
|
||||||
obj.responsible = Responsibility()
|
obj.responsible = Responsibility(
|
||||||
|
handler=Handler()
|
||||||
|
)
|
||||||
created = create_action
|
created = create_action
|
||||||
obj.created = created
|
obj.created = created
|
||||||
obj.geometry = geometry
|
obj.geometry = geometry
|
||||||
@@ -98,9 +105,11 @@ class EmaAPISerializerV1(AbstractModelAPISerializerV1, AbstractCompensationAPISe
|
|||||||
properties = json_model["properties"]
|
properties = json_model["properties"]
|
||||||
obj.identifier = obj.generate_new_identifier()
|
obj.identifier = obj.generate_new_identifier()
|
||||||
obj.title = properties["title"]
|
obj.title = properties["title"]
|
||||||
|
obj.is_pik = properties.get("is_pik", False)
|
||||||
obj = self._set_responsibility(obj, properties["responsible"])
|
obj = self._set_responsibility(obj, properties["responsible"])
|
||||||
|
|
||||||
obj.geometry.save()
|
obj.geometry.save()
|
||||||
|
obj.responsible.handler.save()
|
||||||
obj.responsible.save()
|
obj.responsible.save()
|
||||||
obj.save()
|
obj.save()
|
||||||
|
|
||||||
@@ -134,12 +143,14 @@ class EmaAPISerializerV1(AbstractModelAPISerializerV1, AbstractCompensationAPISe
|
|||||||
# Fill in data to objects
|
# Fill in data to objects
|
||||||
properties = json_model["properties"]
|
properties = json_model["properties"]
|
||||||
obj.title = properties["title"]
|
obj.title = properties["title"]
|
||||||
|
obj.is_pik = properties.get("is_pik", False)
|
||||||
obj.modified = update_action
|
obj.modified = update_action
|
||||||
obj.geometry.geom = self._create_geometry_from_json(json_model)
|
obj.geometry.geom = self._create_geometry_from_json(json_model)
|
||||||
obj.geometry.modified = update_action
|
obj.geometry.modified = update_action
|
||||||
obj = self._set_responsibility(obj, properties["responsible"])
|
obj = self._set_responsibility(obj, properties["responsible"])
|
||||||
|
|
||||||
obj.geometry.save()
|
obj.geometry.save()
|
||||||
|
obj.responsible.handler.save()
|
||||||
obj.responsible.save()
|
obj.responsible.save()
|
||||||
obj.save()
|
obj.save()
|
||||||
|
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ from django.db.models import QuerySet
|
|||||||
from api.utils.serializer.v1.serializer import AbstractModelAPISerializerV1, \
|
from api.utils.serializer.v1.serializer import AbstractModelAPISerializerV1, \
|
||||||
ResponsibilityAPISerializerV1Mixin, LegalAPISerializerV1Mixin, DeductableAPISerializerV1Mixin
|
ResponsibilityAPISerializerV1Mixin, LegalAPISerializerV1Mixin, DeductableAPISerializerV1Mixin
|
||||||
from compensation.models import Payment
|
from compensation.models import Payment
|
||||||
from intervention.models import Intervention, Responsibility, Legal
|
from intervention.models import Intervention, Responsibility, Legal, Handler
|
||||||
from konova.models import Geometry
|
from konova.models import Geometry
|
||||||
from konova.tasks import celery_update_parcels
|
from konova.tasks import celery_update_parcels
|
||||||
from user.models import UserActionLogEntry
|
from user.models import UserActionLogEntry
|
||||||
@@ -69,7 +69,9 @@ class InterventionAPISerializerV1(AbstractModelAPISerializerV1,
|
|||||||
|
|
||||||
# Create linked objects
|
# Create linked objects
|
||||||
obj = Intervention()
|
obj = Intervention()
|
||||||
resp = Responsibility()
|
resp = Responsibility(
|
||||||
|
handler=Handler()
|
||||||
|
)
|
||||||
legal = Legal()
|
legal = Legal()
|
||||||
created = create_action
|
created = create_action
|
||||||
obj.legal = legal
|
obj.legal = legal
|
||||||
@@ -130,6 +132,7 @@ class InterventionAPISerializerV1(AbstractModelAPISerializerV1,
|
|||||||
id__in=payments
|
id__in=payments
|
||||||
)
|
)
|
||||||
obj.payments.set(payments)
|
obj.payments.set(payments)
|
||||||
|
obj.send_data_to_egon()
|
||||||
return obj
|
return obj
|
||||||
|
|
||||||
def create_model_from_json(self, json_model, user):
|
def create_model_from_json(self, json_model, user):
|
||||||
@@ -152,6 +155,7 @@ class InterventionAPISerializerV1(AbstractModelAPISerializerV1,
|
|||||||
self._set_responsibility(obj, properties["responsible"])
|
self._set_responsibility(obj, properties["responsible"])
|
||||||
self._set_legal(obj, properties["legal"])
|
self._set_legal(obj, properties["legal"])
|
||||||
|
|
||||||
|
obj.responsible.handler.save()
|
||||||
obj.responsible.save()
|
obj.responsible.save()
|
||||||
obj.geometry.save()
|
obj.geometry.save()
|
||||||
obj.legal.save()
|
obj.legal.save()
|
||||||
@@ -188,12 +192,13 @@ class InterventionAPISerializerV1(AbstractModelAPISerializerV1,
|
|||||||
obj.geometry.geom = self._create_geometry_from_json(json_model)
|
obj.geometry.geom = self._create_geometry_from_json(json_model)
|
||||||
obj.geometry.modified = update_action
|
obj.geometry.modified = update_action
|
||||||
|
|
||||||
|
obj.responsible.handler.save()
|
||||||
obj.responsible.save()
|
obj.responsible.save()
|
||||||
obj.geometry.save()
|
obj.geometry.save()
|
||||||
obj.legal.save()
|
obj.legal.save()
|
||||||
obj.save()
|
obj.save()
|
||||||
|
|
||||||
obj.mark_as_edited(user)
|
obj.mark_as_edited(user, edit_comment="API update")
|
||||||
|
|
||||||
celery_update_parcels.delay(obj.geometry.id)
|
celery_update_parcels.delay(obj.geometry.id)
|
||||||
|
|
||||||
|
|||||||
@@ -15,9 +15,9 @@ from api.utils.serializer.serializer import AbstractModelAPISerializer
|
|||||||
from codelist.models import KonovaCode
|
from codelist.models import KonovaCode
|
||||||
from codelist.settings import CODELIST_COMPENSATION_ACTION_ID, CODELIST_BIOTOPES_ID, CODELIST_PROCESS_TYPE_ID, \
|
from codelist.settings import CODELIST_COMPENSATION_ACTION_ID, CODELIST_BIOTOPES_ID, CODELIST_PROCESS_TYPE_ID, \
|
||||||
CODELIST_LAW_ID, CODELIST_REGISTRATION_OFFICE_ID, CODELIST_CONSERVATION_OFFICE_ID, \
|
CODELIST_LAW_ID, CODELIST_REGISTRATION_OFFICE_ID, CODELIST_CONSERVATION_OFFICE_ID, \
|
||||||
CODELIST_COMPENSATION_ACTION_DETAIL_ID, CODELIST_BIOTOPES_EXTRA_CODES_ID
|
CODELIST_COMPENSATION_ACTION_DETAIL_ID, CODELIST_BIOTOPES_EXTRA_CODES_ID, CODELIST_HANDLER_ID
|
||||||
from compensation.models import CompensationAction, UnitChoices, CompensationState
|
from compensation.models import CompensationAction, UnitChoices, CompensationState
|
||||||
from intervention.models import Responsibility, Legal
|
from intervention.models import Responsibility, Legal, Handler
|
||||||
from konova.models import Deadline, DeadlineType
|
from konova.models import Deadline, DeadlineType
|
||||||
from konova.utils.message_templates import DATA_UNSHARED
|
from konova.utils.message_templates import DATA_UNSHARED
|
||||||
|
|
||||||
@@ -75,7 +75,10 @@ class AbstractModelAPISerializerV1(AbstractModelAPISerializer):
|
|||||||
Returns:
|
Returns:
|
||||||
|
|
||||||
"""
|
"""
|
||||||
if json_str is None or len(json_str) == 0:
|
if json_str is None:
|
||||||
|
return None
|
||||||
|
json_str = str(json_str)
|
||||||
|
if len(json_str) == 0:
|
||||||
return None
|
return None
|
||||||
code = KonovaCode.objects.get(
|
code = KonovaCode.objects.get(
|
||||||
atom_id=json_str,
|
atom_id=json_str,
|
||||||
@@ -176,6 +179,12 @@ class ResponsibilityAPISerializerV1Mixin:
|
|||||||
class Meta:
|
class Meta:
|
||||||
abstract = True
|
abstract = True
|
||||||
|
|
||||||
|
def _handler_to_json(self, handler: Handler):
|
||||||
|
return {
|
||||||
|
"type": self._konova_code_to_json(handler.type),
|
||||||
|
"detail": handler.detail
|
||||||
|
}
|
||||||
|
|
||||||
def _responsible_to_json(self, responsible: Responsibility):
|
def _responsible_to_json(self, responsible: Responsibility):
|
||||||
""" Serializes Responsibility model into json
|
""" Serializes Responsibility model into json
|
||||||
|
|
||||||
@@ -190,7 +199,7 @@ class ResponsibilityAPISerializerV1Mixin:
|
|||||||
"registration_file_number": responsible.registration_file_number,
|
"registration_file_number": responsible.registration_file_number,
|
||||||
"conservation_office": self._konova_code_to_json(responsible.conservation_office),
|
"conservation_office": self._konova_code_to_json(responsible.conservation_office),
|
||||||
"conservation_file_number": responsible.conservation_file_number,
|
"conservation_file_number": responsible.conservation_file_number,
|
||||||
"handler": responsible.handler,
|
"handler": self._handler_to_json(responsible.handler),
|
||||||
}
|
}
|
||||||
|
|
||||||
def _set_responsibility(self, obj, responsibility_data: dict):
|
def _set_responsibility(self, obj, responsibility_data: dict):
|
||||||
@@ -215,7 +224,11 @@ class ResponsibilityAPISerializerV1Mixin:
|
|||||||
CODELIST_CONSERVATION_OFFICE_ID,
|
CODELIST_CONSERVATION_OFFICE_ID,
|
||||||
)
|
)
|
||||||
obj.responsible.conservation_file_number = responsibility_data["conservation_file_number"]
|
obj.responsible.conservation_file_number = responsibility_data["conservation_file_number"]
|
||||||
obj.responsible.handler = responsibility_data["handler"]
|
obj.responsible.handler.type = self._konova_code_from_json(
|
||||||
|
responsibility_data["handler"]["type"],
|
||||||
|
CODELIST_HANDLER_ID,
|
||||||
|
)
|
||||||
|
obj.responsible.handler.detail = responsibility_data["handler"]["detail"]
|
||||||
return obj
|
return obj
|
||||||
|
|
||||||
|
|
||||||
@@ -367,7 +380,9 @@ class AbstractCompensationAPISerializerV1Mixin:
|
|||||||
"""
|
"""
|
||||||
actions = []
|
actions = []
|
||||||
for entry in actions_data:
|
for entry in actions_data:
|
||||||
action = entry["action"]
|
action_types = [
|
||||||
|
self._konova_code_from_json(e, CODELIST_COMPENSATION_ACTION_ID) for e in entry["action_types"]
|
||||||
|
]
|
||||||
action_details = [
|
action_details = [
|
||||||
self._konova_code_from_json(e, CODELIST_COMPENSATION_ACTION_DETAIL_ID) for e in entry["action_details"]
|
self._konova_code_from_json(e, CODELIST_COMPENSATION_ACTION_DETAIL_ID) for e in entry["action_details"]
|
||||||
]
|
]
|
||||||
@@ -384,7 +399,7 @@ class AbstractCompensationAPISerializerV1Mixin:
|
|||||||
# If this exact data is already existing, we do not create it new. Instead put it's id in the list of
|
# If this exact data is already existing, we do not create it new. Instead put it's id in the list of
|
||||||
# entries, we will use to set the new actions
|
# entries, we will use to set the new actions
|
||||||
action_entry = obj.actions.filter(
|
action_entry = obj.actions.filter(
|
||||||
action_type__atom_id=action,
|
action_type__in=action_types,
|
||||||
amount=amount,
|
amount=amount,
|
||||||
unit=unit,
|
unit=unit,
|
||||||
comment=comment,
|
comment=comment,
|
||||||
@@ -396,13 +411,13 @@ class AbstractCompensationAPISerializerV1Mixin:
|
|||||||
else:
|
else:
|
||||||
# Create and add id to list
|
# Create and add id to list
|
||||||
action_entry = CompensationAction.objects.create(
|
action_entry = CompensationAction.objects.create(
|
||||||
action_type=self._konova_code_from_json(action, CODELIST_COMPENSATION_ACTION_ID),
|
|
||||||
amount=amount,
|
amount=amount,
|
||||||
unit=unit,
|
unit=unit,
|
||||||
comment=comment,
|
comment=comment,
|
||||||
)
|
)
|
||||||
actions.append(action_entry.id)
|
actions.append(action_entry.id)
|
||||||
|
|
||||||
|
action_entry.action_type.set(action_types)
|
||||||
action_entry.action_type_details.set(action_details)
|
action_entry.action_type_details.set(action_details)
|
||||||
obj.actions.set(actions)
|
obj.actions.set(actions)
|
||||||
return obj
|
return obj
|
||||||
@@ -438,7 +453,9 @@ class AbstractCompensationAPISerializerV1Mixin:
|
|||||||
"""
|
"""
|
||||||
return [
|
return [
|
||||||
{
|
{
|
||||||
"action": self._konova_code_to_json(entry.action_type),
|
"action_types": [
|
||||||
|
self._konova_code_to_json(action) for action in entry.action_type.all()
|
||||||
|
],
|
||||||
"action_details": [
|
"action_details": [
|
||||||
self._konova_code_to_json(detail) for detail in entry.action_type_details.all()
|
self._konova_code_to_json(detail) for detail in entry.action_type_details.all()
|
||||||
],
|
],
|
||||||
|
|||||||
@@ -21,7 +21,6 @@ class AbstractAPIViewV1(AbstractAPIView):
|
|||||||
""" Holds general serialization functions for API v1
|
""" Holds general serialization functions for API v1
|
||||||
|
|
||||||
"""
|
"""
|
||||||
serializer = None
|
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
self.lookup = {
|
self.lookup = {
|
||||||
@@ -45,11 +44,17 @@ class AbstractAPIViewV1(AbstractAPIView):
|
|||||||
response (JsonResponse)
|
response (JsonResponse)
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
|
self.rpp = int(request.GET.get("rpp", self.rpp))
|
||||||
|
self.page_number = int(request.GET.get("p", self.page_number))
|
||||||
|
|
||||||
|
self.serializer.rpp = self.rpp
|
||||||
|
self.serializer.page_number = self.page_number
|
||||||
|
|
||||||
self.serializer.prepare_lookup(id, self.user)
|
self.serializer.prepare_lookup(id, self.user)
|
||||||
data = self.serializer.fetch_and_serialize()
|
data = self.serializer.fetch_and_serialize()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
return self.return_error_response(e, 500)
|
return self._return_error_response(e, 500)
|
||||||
return JsonResponse(data)
|
return self._return_response(request, data)
|
||||||
|
|
||||||
def post(self, request: HttpRequest):
|
def post(self, request: HttpRequest):
|
||||||
""" Handles the POST request
|
""" Handles the POST request
|
||||||
@@ -67,7 +72,7 @@ class AbstractAPIViewV1(AbstractAPIView):
|
|||||||
body = json.loads(body)
|
body = json.loads(body)
|
||||||
created_id = self.serializer.create_model_from_json(body, self.user)
|
created_id = self.serializer.create_model_from_json(body, self.user)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
return self.return_error_response(e, 500)
|
return self._return_error_response(e, 500)
|
||||||
return JsonResponse({"id": created_id})
|
return JsonResponse({"id": created_id})
|
||||||
|
|
||||||
def put(self, request: HttpRequest, id=None):
|
def put(self, request: HttpRequest, id=None):
|
||||||
@@ -87,7 +92,7 @@ class AbstractAPIViewV1(AbstractAPIView):
|
|||||||
body = json.loads(body)
|
body = json.loads(body)
|
||||||
updated_id = self.serializer.update_model_from_json(id, body, self.user)
|
updated_id = self.serializer.update_model_from_json(id, body, self.user)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
return self.return_error_response(e, 500)
|
return self._return_error_response(e, 500)
|
||||||
return JsonResponse({"id": updated_id})
|
return JsonResponse({"id": updated_id})
|
||||||
|
|
||||||
def delete(self, request: HttpRequest, id=None):
|
def delete(self, request: HttpRequest, id=None):
|
||||||
@@ -104,7 +109,7 @@ class AbstractAPIViewV1(AbstractAPIView):
|
|||||||
try:
|
try:
|
||||||
success = self.serializer.delete_entry(id, self.user)
|
success = self.serializer.delete_entry(id, self.user)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
return self.return_error_response(e, 500)
|
return self._return_error_response(e, 500)
|
||||||
return JsonResponse(
|
return JsonResponse(
|
||||||
{
|
{
|
||||||
"success": success,
|
"success": success,
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ from ema.models import Ema
|
|||||||
from intervention.models import Intervention
|
from intervention.models import Intervention
|
||||||
from konova.utils.message_templates import DATA_UNSHARED
|
from konova.utils.message_templates import DATA_UNSHARED
|
||||||
from konova.utils.user_checks import is_default_group_only
|
from konova.utils.user_checks import is_default_group_only
|
||||||
from user.models import User
|
from user.models import User, Team
|
||||||
|
|
||||||
|
|
||||||
class AbstractAPIView(View):
|
class AbstractAPIView(View):
|
||||||
@@ -31,10 +31,22 @@ class AbstractAPIView(View):
|
|||||||
|
|
||||||
"""
|
"""
|
||||||
user = None
|
user = None
|
||||||
|
serializer = None
|
||||||
|
rpp = 5 # Results per page default
|
||||||
|
page_number = 1 # Page number default
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
abstract = True
|
abstract = True
|
||||||
|
|
||||||
|
def __init__(self, *args, **kwargs):
|
||||||
|
super().__init__(*args, **kwargs)
|
||||||
|
self.response_body_base = {
|
||||||
|
"rpp": None,
|
||||||
|
"p": None,
|
||||||
|
"next": None,
|
||||||
|
"results": None
|
||||||
|
}
|
||||||
|
|
||||||
@csrf_exempt
|
@csrf_exempt
|
||||||
def dispatch(self, request, *args, **kwargs):
|
def dispatch(self, request, *args, **kwargs):
|
||||||
try:
|
try:
|
||||||
@@ -42,13 +54,14 @@ class AbstractAPIView(View):
|
|||||||
ksp_token = request.headers.get(KSP_TOKEN_HEADER_IDENTIFIER, None)
|
ksp_token = request.headers.get(KSP_TOKEN_HEADER_IDENTIFIER, None)
|
||||||
ksp_user = request.headers.get(KSP_USER_HEADER_IDENTIFIER, None)
|
ksp_user = request.headers.get(KSP_USER_HEADER_IDENTIFIER, None)
|
||||||
self.user = APIUserToken.get_user_from_token(ksp_token, ksp_user)
|
self.user = APIUserToken.get_user_from_token(ksp_token, ksp_user)
|
||||||
|
request.user = self.user
|
||||||
if not self.user.is_default_user():
|
if not self.user.is_default_user():
|
||||||
raise PermissionError("Default permissions required")
|
raise PermissionError("Default permissions required")
|
||||||
except PermissionError as e:
|
except PermissionError as e:
|
||||||
return self.return_error_response(e, 403)
|
return self._return_error_response(e, 403)
|
||||||
return super().dispatch(request, *args, **kwargs)
|
return super().dispatch(request, *args, **kwargs)
|
||||||
|
|
||||||
def return_error_response(self, error, status_code=500):
|
def _return_error_response(self, error, status_code=500):
|
||||||
""" Returns an error as JsonReponse
|
""" Returns an error as JsonReponse
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
@@ -68,6 +81,31 @@ class AbstractAPIView(View):
|
|||||||
status=status_code
|
status=status_code
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def _return_response(self, request: HttpRequest, data):
|
||||||
|
""" Returns all important data into a response object
|
||||||
|
|
||||||
|
Args:
|
||||||
|
request (HttpRequest): The incoming request
|
||||||
|
data (dict): The serialized data
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
response (JsonResponse): The response to be returned
|
||||||
|
"""
|
||||||
|
response = self.response_body_base
|
||||||
|
next_page = self.page_number + 1
|
||||||
|
next_page = next_page if next_page in self.serializer.paginator.page_range else None
|
||||||
|
if next_page is not None:
|
||||||
|
next_url = request.build_absolute_uri(
|
||||||
|
request.path + f"?rpp={self.rpp}&p={next_page}"
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
next_url = None
|
||||||
|
response["rpp"] = self.rpp
|
||||||
|
response["p"] = self.page_number
|
||||||
|
response["next"] = next_url
|
||||||
|
response["results"] = data
|
||||||
|
return JsonResponse(response)
|
||||||
|
|
||||||
|
|
||||||
class InterventionCheckAPIView(AbstractAPIView):
|
class InterventionCheckAPIView(AbstractAPIView):
|
||||||
|
|
||||||
@@ -82,14 +120,14 @@ class InterventionCheckAPIView(AbstractAPIView):
|
|||||||
response (JsonResponse)
|
response (JsonResponse)
|
||||||
"""
|
"""
|
||||||
if not self.user.is_zb_user():
|
if not self.user.is_zb_user():
|
||||||
return self.return_error_response("Permission not granted", 403)
|
return self._return_error_response("Permission not granted", 403)
|
||||||
try:
|
try:
|
||||||
obj = Intervention.objects.get(
|
obj = Intervention.objects.get(
|
||||||
id=id,
|
id=id,
|
||||||
users__in=[self.user]
|
users__in=[self.user]
|
||||||
)
|
)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
return self.return_error_response(e)
|
return self._return_error_response(e)
|
||||||
|
|
||||||
all_valid, check_details = self.run_quality_checks(obj)
|
all_valid, check_details = self.run_quality_checks(obj)
|
||||||
|
|
||||||
@@ -160,13 +198,21 @@ class AbstractModelShareAPIView(AbstractAPIView):
|
|||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
users = self._get_shared_users_of_object(id)
|
users = self._get_shared_users_of_object(id)
|
||||||
|
teams = self._get_shared_teams_of_object(id)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
return self.return_error_response(e)
|
return self._return_error_response(e)
|
||||||
|
|
||||||
data = {
|
data = {
|
||||||
"users": [
|
"users": [
|
||||||
user.username for user in users
|
user.username for user in users
|
||||||
]
|
],
|
||||||
|
"teams": [
|
||||||
|
{
|
||||||
|
"id": team.id,
|
||||||
|
"name": team.name,
|
||||||
|
}
|
||||||
|
for team in teams
|
||||||
|
],
|
||||||
}
|
}
|
||||||
|
|
||||||
return JsonResponse(data)
|
return JsonResponse(data)
|
||||||
@@ -185,7 +231,7 @@ class AbstractModelShareAPIView(AbstractAPIView):
|
|||||||
try:
|
try:
|
||||||
success = self._process_put_body(request.body, id)
|
success = self._process_put_body(request.body, id)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
return self.return_error_response(e)
|
return self._return_error_response(e)
|
||||||
data = {
|
data = {
|
||||||
"success": success,
|
"success": success,
|
||||||
}
|
}
|
||||||
@@ -220,6 +266,22 @@ class AbstractModelShareAPIView(AbstractAPIView):
|
|||||||
users = obj.shared_users
|
users = obj.shared_users
|
||||||
return users
|
return users
|
||||||
|
|
||||||
|
def _get_shared_teams_of_object(self, id) -> QuerySet:
|
||||||
|
""" Check permissions and get the teams
|
||||||
|
|
||||||
|
Args:
|
||||||
|
id (str): The object's id
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
users (QuerySet)
|
||||||
|
"""
|
||||||
|
obj = self.model.objects.get(
|
||||||
|
id=id
|
||||||
|
)
|
||||||
|
self._check_user_has_shared_access(obj)
|
||||||
|
teams = obj.shared_teams
|
||||||
|
return teams
|
||||||
|
|
||||||
def _process_put_body(self, body: bytes, id: str):
|
def _process_put_body(self, body: bytes, id: str):
|
||||||
""" Reads the body data, performs validity checks and sets the new users
|
""" Reads the body data, performs validity checks and sets the new users
|
||||||
|
|
||||||
@@ -233,19 +295,26 @@ class AbstractModelShareAPIView(AbstractAPIView):
|
|||||||
obj = self.model.objects.get(id=id)
|
obj = self.model.objects.get(id=id)
|
||||||
self._check_user_has_shared_access(obj)
|
self._check_user_has_shared_access(obj)
|
||||||
|
|
||||||
new_users = json.loads(body.decode("utf-8"))
|
content = json.loads(body.decode("utf-8"))
|
||||||
new_users = new_users.get("users", [])
|
new_users = content.get("users", [])
|
||||||
if len(new_users) == 0:
|
if len(new_users) == 0:
|
||||||
raise ValueError("Shared user list must not be empty!")
|
raise ValueError("Shared user list must not be empty!")
|
||||||
|
new_teams = content.get("teams", [])
|
||||||
|
|
||||||
# Eliminate duplicates
|
# Eliminate duplicates
|
||||||
new_users = list(dict.fromkeys(new_users))
|
new_users = list(dict.fromkeys(new_users))
|
||||||
|
new_teams = list(dict.fromkeys(new_teams))
|
||||||
|
|
||||||
# Make sure each of these names exist as a user
|
# Make sure each of these names exist as a user
|
||||||
new_users_objs = []
|
new_users_objs = []
|
||||||
for user in new_users:
|
for user in new_users:
|
||||||
new_users_objs.append(User.objects.get(username=user))
|
new_users_objs.append(User.objects.get(username=user))
|
||||||
|
|
||||||
|
# Make sure each of these names exist as a user
|
||||||
|
new_teams_objs = []
|
||||||
|
for team_name in new_teams:
|
||||||
|
new_teams_objs.append(Team.objects.get(name=team_name))
|
||||||
|
|
||||||
if is_default_group_only(self.user):
|
if is_default_group_only(self.user):
|
||||||
# Default only users are not allowed to remove other users from having access. They can only add new ones!
|
# Default only users are not allowed to remove other users from having access. They can only add new ones!
|
||||||
new_users_to_be_added = User.objects.filter(
|
new_users_to_be_added = User.objects.filter(
|
||||||
@@ -254,7 +323,16 @@ class AbstractModelShareAPIView(AbstractAPIView):
|
|||||||
id__in=obj.shared_users
|
id__in=obj.shared_users
|
||||||
)
|
)
|
||||||
new_users_objs = obj.shared_users.union(new_users_to_be_added)
|
new_users_objs = obj.shared_users.union(new_users_to_be_added)
|
||||||
obj.share_with_list(new_users_objs)
|
|
||||||
|
new_teams_to_be_added = Team.objects.filter(
|
||||||
|
name__in=new_teams
|
||||||
|
).exclude(
|
||||||
|
id__in=obj.shared_teams
|
||||||
|
)
|
||||||
|
new_teams_objs = obj.shared_teams.union(new_teams_to_be_added)
|
||||||
|
|
||||||
|
obj.share_with_user_list(new_users_objs)
|
||||||
|
obj.share_with_team_list(new_teams_objs)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -33,6 +33,7 @@ class KonovaCodeAdmin(admin.ModelAdmin):
|
|||||||
"is_selectable",
|
"is_selectable",
|
||||||
"is_leaf",
|
"is_leaf",
|
||||||
"parent",
|
"parent",
|
||||||
|
"found_in_codelists",
|
||||||
]
|
]
|
||||||
|
|
||||||
search_fields = [
|
search_fields = [
|
||||||
@@ -42,6 +43,12 @@ class KonovaCodeAdmin(admin.ModelAdmin):
|
|||||||
"short_name",
|
"short_name",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
def found_in_codelists(self, obj):
|
||||||
|
codelists = KonovaCodeList.objects.filter(
|
||||||
|
codes__in=[obj]
|
||||||
|
).values_list("id", flat=True)
|
||||||
|
codelists = "\n".join(str(x) for x in codelists)
|
||||||
|
return codelists
|
||||||
|
|
||||||
#admin.site.register(KonovaCodeList, KonovaCodeListAdmin)
|
#admin.site.register(KonovaCodeList, KonovaCodeListAdmin)
|
||||||
admin.site.register(KonovaCode, KonovaCodeAdmin)
|
admin.site.register(KonovaCode, KonovaCodeAdmin)
|
||||||
|
|||||||
165
codelist/management/commands/sync_codelist.py
Normal file
165
codelist/management/commands/sync_codelist.py
Normal file
@@ -0,0 +1,165 @@
|
|||||||
|
"""
|
||||||
|
Author: Michel Peltriaux
|
||||||
|
Organization: Struktur- und Genehmigungsdirektion Nord, Rhineland-Palatinate, Germany
|
||||||
|
Contact: michel.peltriaux@sgdnord.rlp.de
|
||||||
|
Created on: 31.05.22
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
from django.db import transaction
|
||||||
|
|
||||||
|
from codelist.models import KonovaCode
|
||||||
|
from compensation.models import CompensationAction, CompensationState
|
||||||
|
from intervention.models import Legal, Handler, Responsibility
|
||||||
|
from konova.management.commands.setup import BaseKonovaCommand
|
||||||
|
|
||||||
|
|
||||||
|
class Command(BaseKonovaCommand):
|
||||||
|
help = "Updates internal codelist by external API"
|
||||||
|
|
||||||
|
def handle(self, *args, **options):
|
||||||
|
try:
|
||||||
|
with transaction.atomic():
|
||||||
|
self.sync_codelist()
|
||||||
|
except KeyboardInterrupt:
|
||||||
|
self._break_line()
|
||||||
|
exit(-1)
|
||||||
|
|
||||||
|
def __get_newest_code(self, code):
|
||||||
|
code = KonovaCode.objects.filter(
|
||||||
|
atom_id=code.atom_id,
|
||||||
|
parent=code.parent,
|
||||||
|
code_lists__in=code.code_lists.all(),
|
||||||
|
).order_by(
|
||||||
|
"-id"
|
||||||
|
).first()
|
||||||
|
return code
|
||||||
|
|
||||||
|
def __migrate_compensation_action_codes(self):
|
||||||
|
all_actions = CompensationAction.objects.all()
|
||||||
|
used_codes = []
|
||||||
|
for action in all_actions:
|
||||||
|
stored_codes = action.action_type.all()
|
||||||
|
codes = []
|
||||||
|
for code in stored_codes:
|
||||||
|
codes.append(self.__get_newest_code(code))
|
||||||
|
action.action_type.set(codes)
|
||||||
|
used_codes += codes
|
||||||
|
|
||||||
|
stored_codes = action.action_type_details.all()
|
||||||
|
codes = []
|
||||||
|
for code in stored_codes:
|
||||||
|
codes.append(self.__get_newest_code(code))
|
||||||
|
action.action_type_details.set(codes)
|
||||||
|
used_codes += codes
|
||||||
|
|
||||||
|
action.save()
|
||||||
|
return used_codes
|
||||||
|
|
||||||
|
def __migrate_compensation_state_codes(self):
|
||||||
|
all_states = CompensationState.objects.all()
|
||||||
|
used_codes = []
|
||||||
|
for state in all_states:
|
||||||
|
code = state.biotope_type
|
||||||
|
if code is not None:
|
||||||
|
new_code = self.__get_newest_code(code)
|
||||||
|
state.biotope_type = new_code
|
||||||
|
used_codes.append(new_code)
|
||||||
|
|
||||||
|
stored_codes = state.biotope_type_details.all()
|
||||||
|
codes = []
|
||||||
|
for code in stored_codes:
|
||||||
|
codes.append(self.__get_newest_code(code))
|
||||||
|
state.biotope_type_details.set(codes)
|
||||||
|
|
||||||
|
used_codes += codes
|
||||||
|
state.save()
|
||||||
|
return used_codes
|
||||||
|
|
||||||
|
def __migrate_legal_codes(self):
|
||||||
|
all_legal = Legal.objects.all()
|
||||||
|
used_codes = []
|
||||||
|
for legal in all_legal:
|
||||||
|
code = legal.process_type
|
||||||
|
if code is not None:
|
||||||
|
new_code = self.__get_newest_code(code)
|
||||||
|
legal.process_type = new_code
|
||||||
|
used_codes.append(new_code)
|
||||||
|
|
||||||
|
stored_codes = legal.laws.all()
|
||||||
|
codes = []
|
||||||
|
for code in stored_codes:
|
||||||
|
codes.append(self.__get_newest_code(code))
|
||||||
|
legal.laws.set(codes)
|
||||||
|
|
||||||
|
used_codes += codes
|
||||||
|
legal.save()
|
||||||
|
return used_codes
|
||||||
|
|
||||||
|
def __migrate_handler_codes(apps):
|
||||||
|
all_handlers = Handler.objects.all()
|
||||||
|
used_codes = []
|
||||||
|
for handler in all_handlers:
|
||||||
|
code = handler.type
|
||||||
|
if code is None:
|
||||||
|
continue
|
||||||
|
new_code = apps.__get_newest_code(code)
|
||||||
|
handler.type = new_code
|
||||||
|
used_codes.append(new_code)
|
||||||
|
handler.save()
|
||||||
|
return used_codes
|
||||||
|
|
||||||
|
def __migrate_responsibility_codes(apps):
|
||||||
|
all_resps = Responsibility.objects.all()
|
||||||
|
used_codes = []
|
||||||
|
for responsibility in all_resps:
|
||||||
|
code = responsibility.registration_office
|
||||||
|
if code is not None:
|
||||||
|
new_code = apps.__get_newest_code(code)
|
||||||
|
responsibility.registration_office = new_code
|
||||||
|
used_codes.append(new_code)
|
||||||
|
|
||||||
|
code = responsibility.conservation_office
|
||||||
|
if code is not None:
|
||||||
|
new_code = apps.__get_newest_code(code)
|
||||||
|
responsibility.conservation_office = new_code
|
||||||
|
used_codes.append(new_code)
|
||||||
|
|
||||||
|
responsibility.save()
|
||||||
|
return used_codes
|
||||||
|
|
||||||
|
def sync_codelist(self):
|
||||||
|
""" Due to issues on the external codelist app there can be multiple entries of the same code
|
||||||
|
(atom_id, parent, list) but with different identifiers.
|
||||||
|
|
||||||
|
These issues have been resolved but already
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
|
||||||
|
"""
|
||||||
|
self._write_warning("Sync codes in usage and replace by newest entries...")
|
||||||
|
used_codes = []
|
||||||
|
used_codes += self.__migrate_compensation_action_codes()
|
||||||
|
used_codes += self.__migrate_compensation_state_codes()
|
||||||
|
used_codes += self.__migrate_legal_codes()
|
||||||
|
used_codes += self.__migrate_handler_codes()
|
||||||
|
used_codes += self.__migrate_responsibility_codes()
|
||||||
|
self._write_success(f"Synced {len(used_codes)} code usages!")
|
||||||
|
|
||||||
|
all_codes = KonovaCode.objects.all()
|
||||||
|
newest_code_ids = []
|
||||||
|
for code in all_codes:
|
||||||
|
newest_code = self.__get_newest_code(code)
|
||||||
|
newest_code_ids.append(newest_code.id)
|
||||||
|
|
||||||
|
code_ids_to_keep = set(newest_code_ids)
|
||||||
|
self._write_warning(f"Of {all_codes.count()} KonovaCodes there are {len(code_ids_to_keep)} to keep as newest versions...")
|
||||||
|
|
||||||
|
deletable_codes = KonovaCode.objects.all().exclude(
|
||||||
|
id__in=code_ids_to_keep
|
||||||
|
)
|
||||||
|
deletable_codes_count = deletable_codes.count()
|
||||||
|
self._write_warning(f"{deletable_codes_count} found which are obsolet...")
|
||||||
|
if deletable_codes_count > 0:
|
||||||
|
deletable_codes.delete()
|
||||||
|
self._write_success("Obsolete codes deleted!")
|
||||||
@@ -6,12 +6,11 @@ Created on: 23.08.21
|
|||||||
|
|
||||||
"""
|
"""
|
||||||
import requests
|
import requests
|
||||||
from django.core.management import BaseCommand
|
|
||||||
from xml.etree import ElementTree as etree
|
from xml.etree import ElementTree as etree
|
||||||
|
|
||||||
from codelist.models import KonovaCode, KonovaCodeList
|
from codelist.models import KonovaCode, KonovaCodeList
|
||||||
from codelist.settings import CODELIST_INTERVENTION_HANDLER_ID, CODELIST_CONSERVATION_OFFICE_ID, \
|
from codelist.settings import CODELIST_INTERVENTION_HANDLER_ID, CODELIST_CONSERVATION_OFFICE_ID, \
|
||||||
CODELIST_REGISTRATION_OFFICE_ID, CODELIST_BIOTOPES_ID, CODELIST_LAW_ID, CODELIST_COMPENSATION_HANDLER_ID, \
|
CODELIST_REGISTRATION_OFFICE_ID, CODELIST_BIOTOPES_ID, CODELIST_LAW_ID, CODELIST_HANDLER_ID, \
|
||||||
CODELIST_COMPENSATION_ACTION_ID, CODELIST_COMPENSATION_ACTION_CLASS_ID, CODELIST_COMPENSATION_ADDITIONAL_TYPE_ID, \
|
CODELIST_COMPENSATION_ACTION_ID, CODELIST_COMPENSATION_ACTION_CLASS_ID, CODELIST_COMPENSATION_ADDITIONAL_TYPE_ID, \
|
||||||
CODELIST_BASE_URL, CODELIST_PROCESS_TYPE_ID, CODELIST_BIOTOPES_EXTRA_CODES_ID, \
|
CODELIST_BASE_URL, CODELIST_PROCESS_TYPE_ID, CODELIST_BIOTOPES_EXTRA_CODES_ID, \
|
||||||
CODELIST_COMPENSATION_ACTION_DETAIL_ID
|
CODELIST_COMPENSATION_ACTION_DETAIL_ID
|
||||||
@@ -36,7 +35,7 @@ class Command(BaseKonovaCommand):
|
|||||||
CODELIST_BIOTOPES_ID,
|
CODELIST_BIOTOPES_ID,
|
||||||
CODELIST_BIOTOPES_EXTRA_CODES_ID,
|
CODELIST_BIOTOPES_EXTRA_CODES_ID,
|
||||||
CODELIST_LAW_ID,
|
CODELIST_LAW_ID,
|
||||||
CODELIST_COMPENSATION_HANDLER_ID,
|
CODELIST_HANDLER_ID,
|
||||||
CODELIST_COMPENSATION_ACTION_ID,
|
CODELIST_COMPENSATION_ACTION_ID,
|
||||||
CODELIST_COMPENSATION_ACTION_CLASS_ID,
|
CODELIST_COMPENSATION_ACTION_CLASS_ID,
|
||||||
CODELIST_COMPENSATION_ACTION_DETAIL_ID,
|
CODELIST_COMPENSATION_ACTION_DETAIL_ID,
|
||||||
|
|||||||
@@ -1,9 +1,13 @@
|
|||||||
# Generated by Django 3.1.3 on 2022-01-14 08:36
|
# Generated by Django 3.1.3 on 2022-01-14 08:36
|
||||||
|
from django.core.management import call_command
|
||||||
from django.db import migrations, models
|
from django.db import migrations, models
|
||||||
import django.db.models.deletion
|
import django.db.models.deletion
|
||||||
|
|
||||||
|
|
||||||
|
def load_initial_codes(apps, schema_editor):
|
||||||
|
call_command('update_codelist')
|
||||||
|
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
initial = True
|
initial = True
|
||||||
@@ -32,4 +36,5 @@ class Migration(migrations.Migration):
|
|||||||
('codes', models.ManyToManyField(blank=True, help_text='Codes for this list', related_name='code_lists', to='codelist.KonovaCode')),
|
('codes', models.ManyToManyField(blank=True, help_text='Codes for this list', related_name='code_lists', to='codelist.KonovaCode')),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
migrations.RunPython(load_initial_codes),
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -65,6 +65,25 @@ class KonovaCode(models.Model):
|
|||||||
ret_val += ", " + self.parent.long_name
|
ret_val += ", " + self.parent.long_name
|
||||||
return ret_val
|
return ret_val
|
||||||
|
|
||||||
|
def add_children(self, order_by: str = "long_name"):
|
||||||
|
""" Adds all children (resurcively until leaf) as .children to the KonovaCode
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
code (KonovaCode): The manipulated KonovaCode instance
|
||||||
|
"""
|
||||||
|
if self.is_leaf:
|
||||||
|
return self
|
||||||
|
|
||||||
|
children = KonovaCode.objects.filter(
|
||||||
|
parent=self
|
||||||
|
).order_by(
|
||||||
|
order_by
|
||||||
|
)
|
||||||
|
self.children = children
|
||||||
|
for child in children:
|
||||||
|
child.add_children(order_by)
|
||||||
|
return self
|
||||||
|
|
||||||
|
|
||||||
class KonovaCodeList(models.Model):
|
class KonovaCodeList(models.Model):
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -13,12 +13,13 @@ CODELIST_BASE_URL = "https://codelisten.naturschutz.rlp.de/repository/referenzli
|
|||||||
CODELIST_INTERVENTION_HANDLER_ID = 903 # CLMassnahmeträger
|
CODELIST_INTERVENTION_HANDLER_ID = 903 # CLMassnahmeträger
|
||||||
CODELIST_CONSERVATION_OFFICE_ID = 907 # CLNaturschutzbehörden
|
CODELIST_CONSERVATION_OFFICE_ID = 907 # CLNaturschutzbehörden
|
||||||
CODELIST_REGISTRATION_OFFICE_ID = 1053 # CLZulassungsbehörden
|
CODELIST_REGISTRATION_OFFICE_ID = 1053 # CLZulassungsbehörden
|
||||||
CODELIST_BIOTOPES_ID = 974 # CL_EIV_Biotoptypen
|
CODELIST_BIOTOPES_ID = 654 # CL_Biotoptypen
|
||||||
|
CODELIST_AFTER_STATE_BIOTOPES_ID = 974 # CL-KSP_ZielBiotoptypen - USAGE HAS BEEN DROPPED IN 2022 IN FAVOR OF 654
|
||||||
CODELIST_BIOTOPES_EXTRA_CODES_ID = 975 # CLZusatzbezeichnung
|
CODELIST_BIOTOPES_EXTRA_CODES_ID = 975 # CLZusatzbezeichnung
|
||||||
CODELIST_LAW_ID = 1048 # CLVerfahrensrecht
|
CODELIST_LAW_ID = 1048 # CLVerfahrensrecht
|
||||||
CODELIST_PROCESS_TYPE_ID = 44382 # CLVerfahrenstyp
|
CODELIST_PROCESS_TYPE_ID = 44382 # CLVerfahrenstyp
|
||||||
|
|
||||||
CODELIST_COMPENSATION_HANDLER_ID = 1052 # CLEingreifer
|
CODELIST_HANDLER_ID = 1052 # CLEingreifer
|
||||||
CODELIST_COMPENSATION_ACTION_ID = 1026 # CLMassnahmedetail
|
CODELIST_COMPENSATION_ACTION_ID = 1026 # CLMassnahmedetail
|
||||||
CODELIST_COMPENSATION_ACTION_DETAIL_ID = 1035 # CLZusatzmerkmal
|
CODELIST_COMPENSATION_ACTION_DETAIL_ID = 1035 # CLZusatzmerkmal
|
||||||
CODELIST_COMPENSATION_ACTION_CLASS_ID = 1034 # CLMassnahmeklasse
|
CODELIST_COMPENSATION_ACTION_CLASS_ID = 1034 # CLMassnahmeklasse
|
||||||
|
|||||||
@@ -3,6 +3,8 @@ from django.contrib import admin
|
|||||||
from compensation.models import Compensation, CompensationAction, CompensationState, Payment, \
|
from compensation.models import Compensation, CompensationAction, CompensationState, Payment, \
|
||||||
EcoAccountDeduction, EcoAccount
|
EcoAccountDeduction, EcoAccount
|
||||||
from konova.admin import BaseObjectAdmin, BaseResourceAdmin
|
from konova.admin import BaseObjectAdmin, BaseResourceAdmin
|
||||||
|
from konova.utils.message_templates import COMPENSATION_REMOVED_TEMPLATE
|
||||||
|
from user.models import UserAction
|
||||||
|
|
||||||
|
|
||||||
class AbstractCompensationAdmin(BaseObjectAdmin):
|
class AbstractCompensationAdmin(BaseObjectAdmin):
|
||||||
@@ -19,16 +21,30 @@ class AbstractCompensationAdmin(BaseObjectAdmin):
|
|||||||
"identifier",
|
"identifier",
|
||||||
"title",
|
"title",
|
||||||
"comment",
|
"comment",
|
||||||
"after_states",
|
"list_after_states",
|
||||||
"before_states",
|
"list_before_states",
|
||||||
|
"geometry",
|
||||||
]
|
]
|
||||||
|
|
||||||
def get_readonly_fields(self, request, obj=None):
|
def get_readonly_fields(self, request, obj=None):
|
||||||
return super().get_readonly_fields(request, obj) + [
|
return super().get_readonly_fields(request, obj) + [
|
||||||
"after_states",
|
"list_after_states",
|
||||||
"before_states",
|
"list_before_states",
|
||||||
|
"geometry",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
def list_after_states(self, obj):
|
||||||
|
states = obj.after_states.all()
|
||||||
|
states = [str(state) for state in states]
|
||||||
|
states = "\n".join(states)
|
||||||
|
return states
|
||||||
|
|
||||||
|
def list_before_states(self, obj):
|
||||||
|
states = obj.before_states.all()
|
||||||
|
states = [str(state) for state in states]
|
||||||
|
states = "\n".join(states)
|
||||||
|
return states
|
||||||
|
|
||||||
|
|
||||||
class CompensationAdmin(AbstractCompensationAdmin):
|
class CompensationAdmin(AbstractCompensationAdmin):
|
||||||
autocomplete_fields = [
|
autocomplete_fields = [
|
||||||
@@ -39,9 +55,21 @@ class CompensationAdmin(AbstractCompensationAdmin):
|
|||||||
return super().get_fields(request, obj) + [
|
return super().get_fields(request, obj) + [
|
||||||
"is_cef",
|
"is_cef",
|
||||||
"is_coherence_keeping",
|
"is_coherence_keeping",
|
||||||
|
"is_pik",
|
||||||
"intervention",
|
"intervention",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
def restore_deleted_data(self, request, queryset):
|
||||||
|
super().restore_deleted_data(request, queryset)
|
||||||
|
|
||||||
|
for entry in queryset:
|
||||||
|
# Remove delete log entry from related intervention log history
|
||||||
|
logs = entry.intervention.log.filter(
|
||||||
|
action=UserAction.EDITED,
|
||||||
|
comment=COMPENSATION_REMOVED_TEMPLATE.format(entry.identifier)
|
||||||
|
)
|
||||||
|
logs.delete()
|
||||||
|
|
||||||
|
|
||||||
class EcoAccountAdmin(AbstractCompensationAdmin):
|
class EcoAccountAdmin(AbstractCompensationAdmin):
|
||||||
list_display = [
|
list_display = [
|
||||||
|
|||||||
@@ -59,8 +59,9 @@ class CheckboxCompensationTableFilter(CheckboxTableFilter):
|
|||||||
"""
|
"""
|
||||||
if not value:
|
if not value:
|
||||||
return queryset.filter(
|
return queryset.filter(
|
||||||
intervention__users__in=[self.user], # requesting user has access
|
Q(intervention__users__in=[self.user]) | # requesting user has access
|
||||||
)
|
Q(intervention__teams__in=self.user.shared_teams)
|
||||||
|
).distinct()
|
||||||
else:
|
else:
|
||||||
return queryset
|
return queryset
|
||||||
|
|
||||||
@@ -127,24 +128,6 @@ class CheckboxEcoAccountTableFilter(CheckboxTableFilter):
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
def filter_show_all(self, queryset, name, value) -> QuerySet:
|
|
||||||
""" Filters queryset depending on value of 'show_all' setting
|
|
||||||
|
|
||||||
Args:
|
|
||||||
queryset ():
|
|
||||||
name ():
|
|
||||||
value ():
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
|
|
||||||
"""
|
|
||||||
if not value:
|
|
||||||
return queryset.filter(
|
|
||||||
users__in=[self.user], # requesting user has access
|
|
||||||
)
|
|
||||||
else:
|
|
||||||
return queryset
|
|
||||||
|
|
||||||
def filter_only_show_unrecorded(self, queryset, name, value) -> QuerySet:
|
def filter_only_show_unrecorded(self, queryset, name, value) -> QuerySet:
|
||||||
""" Filters queryset depending on value of 'show_recorded' setting
|
""" Filters queryset depending on value of 'show_recorded' setting
|
||||||
|
|
||||||
|
|||||||
@@ -13,12 +13,12 @@ from django.utils.translation import gettext_lazy as _
|
|||||||
from django import forms
|
from django import forms
|
||||||
|
|
||||||
from codelist.models import KonovaCode
|
from codelist.models import KonovaCode
|
||||||
from codelist.settings import CODELIST_CONSERVATION_OFFICE_ID
|
from codelist.settings import CODELIST_CONSERVATION_OFFICE_ID, CODELIST_HANDLER_ID
|
||||||
from compensation.models import Compensation, EcoAccount
|
from compensation.models import Compensation, EcoAccount
|
||||||
from intervention.inputs import GenerateInput
|
from intervention.inputs import GenerateInput
|
||||||
from intervention.models import Intervention, Responsibility, Legal
|
from intervention.models import Intervention, Responsibility, Legal, Handler
|
||||||
from konova.forms import BaseForm, SimpleGeomForm
|
from konova.forms import BaseForm, SimpleGeomForm
|
||||||
from konova.utils.message_templates import EDITED_GENERAL_DATA
|
from konova.utils.message_templates import EDITED_GENERAL_DATA, COMPENSATION_ADDED_TEMPLATE
|
||||||
from user.models import UserActionLogEntry
|
from user.models import UserActionLogEntry
|
||||||
|
|
||||||
|
|
||||||
@@ -101,12 +101,30 @@ class CompensationResponsibleFormMixin(forms.Form):
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
handler = forms.CharField(
|
|
||||||
label=_("Eco-account handler"),
|
handler_type = forms.ModelChoiceField(
|
||||||
|
label=_("Eco-Account handler type"),
|
||||||
|
label_suffix="",
|
||||||
|
help_text=_("What type of handler is responsible for the ecoaccount?"),
|
||||||
|
required=False,
|
||||||
|
queryset=KonovaCode.objects.filter(
|
||||||
|
is_archived=False,
|
||||||
|
is_leaf=True,
|
||||||
|
code_lists__in=[CODELIST_HANDLER_ID],
|
||||||
|
),
|
||||||
|
widget=autocomplete.ModelSelect2(
|
||||||
|
url="codes-handler-autocomplete",
|
||||||
|
attrs={
|
||||||
|
"data-placeholder": _("Click for selection"),
|
||||||
|
}
|
||||||
|
),
|
||||||
|
)
|
||||||
|
handler_detail = forms.CharField(
|
||||||
|
label=_("Eco-Account handler detail"),
|
||||||
label_suffix="",
|
label_suffix="",
|
||||||
max_length=255,
|
max_length=255,
|
||||||
required=False,
|
required=False,
|
||||||
help_text=_("Who handles the eco-account"),
|
help_text=_("Detail input on the handler"),
|
||||||
widget=forms.TextInput(
|
widget=forms.TextInput(
|
||||||
attrs={
|
attrs={
|
||||||
"placeholder": _("Company Mustermann"),
|
"placeholder": _("Company Mustermann"),
|
||||||
@@ -142,7 +160,23 @@ class CoherenceCompensationFormMixin(forms.Form):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class NewCompensationForm(AbstractCompensationForm, CEFCompensationFormMixin, CoherenceCompensationFormMixin):
|
class PikCompensationFormMixin(forms.Form):
|
||||||
|
""" A form mixin, providing PIK compensation field
|
||||||
|
|
||||||
|
"""
|
||||||
|
is_pik = forms.BooleanField(
|
||||||
|
label_suffix="",
|
||||||
|
label=_("Is PIK"),
|
||||||
|
help_text=_("Optionally: Whether this compensation is a compensation integrated in production?"),
|
||||||
|
required=False,
|
||||||
|
widget=forms.CheckboxInput()
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class NewCompensationForm(AbstractCompensationForm,
|
||||||
|
CEFCompensationFormMixin,
|
||||||
|
CoherenceCompensationFormMixin,
|
||||||
|
PikCompensationFormMixin):
|
||||||
""" Form for creating new compensations.
|
""" Form for creating new compensations.
|
||||||
|
|
||||||
Can be initialized with an intervention id for preselecting the related intervention.
|
Can be initialized with an intervention id for preselecting the related intervention.
|
||||||
@@ -173,6 +207,7 @@ class NewCompensationForm(AbstractCompensationForm, CEFCompensationFormMixin, Co
|
|||||||
"identifier",
|
"identifier",
|
||||||
"title",
|
"title",
|
||||||
"intervention",
|
"intervention",
|
||||||
|
"is_pik",
|
||||||
"is_cef",
|
"is_cef",
|
||||||
"is_coherence_keeping",
|
"is_coherence_keeping",
|
||||||
"comment",
|
"comment",
|
||||||
@@ -200,35 +235,51 @@ class NewCompensationForm(AbstractCompensationForm, CEFCompensationFormMixin, Co
|
|||||||
self.initialize_form_field("identifier", identifier)
|
self.initialize_form_field("identifier", identifier)
|
||||||
self.fields["identifier"].widget.attrs["url"] = reverse_lazy("compensation:new-id")
|
self.fields["identifier"].widget.attrs["url"] = reverse_lazy("compensation:new-id")
|
||||||
|
|
||||||
|
def __create_comp(self, user, geom_form) -> Compensation:
|
||||||
|
""" Creates the compensation from form data
|
||||||
|
|
||||||
|
Args:
|
||||||
|
user (User): The performing user
|
||||||
|
geom_form (SimpleGeomForm): The geometry form
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
comp (Compensation): The compensation object
|
||||||
|
"""
|
||||||
|
# Fetch data from cleaned POST values
|
||||||
|
identifier = self.cleaned_data.get("identifier", None)
|
||||||
|
title = self.cleaned_data.get("title", None)
|
||||||
|
intervention = self.cleaned_data.get("intervention", None)
|
||||||
|
is_cef = self.cleaned_data.get("is_cef", None)
|
||||||
|
is_coherence_keeping = self.cleaned_data.get("is_coherence_keeping", None)
|
||||||
|
is_pik = self.cleaned_data.get("is_pik", None)
|
||||||
|
comment = self.cleaned_data.get("comment", None)
|
||||||
|
|
||||||
|
# Create log entry
|
||||||
|
action = UserActionLogEntry.get_created_action(user)
|
||||||
|
# Process the geometry form
|
||||||
|
geometry = geom_form.save(action)
|
||||||
|
|
||||||
|
# Finally create main object
|
||||||
|
comp = Compensation.objects.create(
|
||||||
|
identifier=identifier,
|
||||||
|
title=title,
|
||||||
|
intervention=intervention,
|
||||||
|
created=action,
|
||||||
|
is_cef=is_cef,
|
||||||
|
is_coherence_keeping=is_coherence_keeping,
|
||||||
|
is_pik=is_pik,
|
||||||
|
geometry=geometry,
|
||||||
|
comment=comment,
|
||||||
|
)
|
||||||
|
|
||||||
|
# Add the log entry to the main objects log list
|
||||||
|
comp.log.add(action)
|
||||||
|
return comp
|
||||||
|
|
||||||
def save(self, user: User, geom_form: SimpleGeomForm):
|
def save(self, user: User, geom_form: SimpleGeomForm):
|
||||||
with transaction.atomic():
|
with transaction.atomic():
|
||||||
# Fetch data from cleaned POST values
|
comp = self.__create_comp(user, geom_form)
|
||||||
identifier = self.cleaned_data.get("identifier", None)
|
comp.intervention.mark_as_edited(user, edit_comment=COMPENSATION_ADDED_TEMPLATE.format(comp.identifier))
|
||||||
title = self.cleaned_data.get("title", None)
|
|
||||||
intervention = self.cleaned_data.get("intervention", None)
|
|
||||||
is_cef = self.cleaned_data.get("is_cef", None)
|
|
||||||
is_coherence_keeping = self.cleaned_data.get("is_coherence_keeping", None)
|
|
||||||
comment = self.cleaned_data.get("comment", None)
|
|
||||||
|
|
||||||
# Create log entry
|
|
||||||
action = UserActionLogEntry.get_created_action(user)
|
|
||||||
# Process the geometry form
|
|
||||||
geometry = geom_form.save(action)
|
|
||||||
|
|
||||||
# Finally create main object
|
|
||||||
comp = Compensation.objects.create(
|
|
||||||
identifier=identifier,
|
|
||||||
title=title,
|
|
||||||
intervention=intervention,
|
|
||||||
created=action,
|
|
||||||
is_cef=is_cef,
|
|
||||||
is_coherence_keeping=is_coherence_keeping,
|
|
||||||
geometry=geometry,
|
|
||||||
comment=comment,
|
|
||||||
)
|
|
||||||
|
|
||||||
# Add the log entry to the main objects log list
|
|
||||||
comp.log.add(action)
|
|
||||||
return comp
|
return comp
|
||||||
|
|
||||||
|
|
||||||
@@ -249,6 +300,7 @@ class EditCompensationForm(NewCompensationForm):
|
|||||||
"intervention": self.instance.intervention,
|
"intervention": self.instance.intervention,
|
||||||
"is_cef": self.instance.is_cef,
|
"is_cef": self.instance.is_cef,
|
||||||
"is_coherence_keeping": self.instance.is_coherence_keeping,
|
"is_coherence_keeping": self.instance.is_coherence_keeping,
|
||||||
|
"is_pik": self.instance.is_pik,
|
||||||
"comment": self.instance.comment,
|
"comment": self.instance.comment,
|
||||||
}
|
}
|
||||||
disabled_fields = []
|
disabled_fields = []
|
||||||
@@ -265,6 +317,7 @@ class EditCompensationForm(NewCompensationForm):
|
|||||||
intervention = self.cleaned_data.get("intervention", None)
|
intervention = self.cleaned_data.get("intervention", None)
|
||||||
is_cef = self.cleaned_data.get("is_cef", None)
|
is_cef = self.cleaned_data.get("is_cef", None)
|
||||||
is_coherence_keeping = self.cleaned_data.get("is_coherence_keeping", None)
|
is_coherence_keeping = self.cleaned_data.get("is_coherence_keeping", None)
|
||||||
|
is_pik = self.cleaned_data.get("is_pik", None)
|
||||||
comment = self.cleaned_data.get("comment", None)
|
comment = self.cleaned_data.get("comment", None)
|
||||||
|
|
||||||
# Create log entry
|
# Create log entry
|
||||||
@@ -281,6 +334,7 @@ class EditCompensationForm(NewCompensationForm):
|
|||||||
self.instance.is_cef = is_cef
|
self.instance.is_cef = is_cef
|
||||||
self.instance.is_coherence_keeping = is_coherence_keeping
|
self.instance.is_coherence_keeping = is_coherence_keeping
|
||||||
self.instance.comment = comment
|
self.instance.comment = comment
|
||||||
|
self.instance.is_pik = is_pik
|
||||||
self.instance.modified = action
|
self.instance.modified = action
|
||||||
self.instance.save()
|
self.instance.save()
|
||||||
|
|
||||||
@@ -290,7 +344,7 @@ class EditCompensationForm(NewCompensationForm):
|
|||||||
return self.instance
|
return self.instance
|
||||||
|
|
||||||
|
|
||||||
class NewEcoAccountForm(AbstractCompensationForm, CompensationResponsibleFormMixin):
|
class NewEcoAccountForm(AbstractCompensationForm, CompensationResponsibleFormMixin, PikCompensationFormMixin):
|
||||||
""" Form for creating eco accounts
|
""" Form for creating eco accounts
|
||||||
|
|
||||||
Inherits from basic AbstractCompensationForm and further form fields from CompensationResponsibleFormMixin
|
Inherits from basic AbstractCompensationForm and further form fields from CompensationResponsibleFormMixin
|
||||||
@@ -331,7 +385,9 @@ class NewEcoAccountForm(AbstractCompensationForm, CompensationResponsibleFormMix
|
|||||||
"registration_date",
|
"registration_date",
|
||||||
"surface",
|
"surface",
|
||||||
"conservation_file_number",
|
"conservation_file_number",
|
||||||
"handler",
|
"is_pik",
|
||||||
|
"handler_type",
|
||||||
|
"handler_detail",
|
||||||
"comment",
|
"comment",
|
||||||
]
|
]
|
||||||
|
|
||||||
@@ -339,13 +395,13 @@ class NewEcoAccountForm(AbstractCompensationForm, CompensationResponsibleFormMix
|
|||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
self.form_title = _("New Eco-Account")
|
self.form_title = _("New Eco-Account")
|
||||||
|
|
||||||
self.action_url = reverse("compensation:acc-new")
|
self.action_url = reverse("compensation:acc:new")
|
||||||
self.cancel_redirect = reverse("compensation:acc-index")
|
self.cancel_redirect = reverse("compensation:acc:index")
|
||||||
|
|
||||||
tmp = EcoAccount()
|
tmp = EcoAccount()
|
||||||
identifier = tmp.generate_new_identifier()
|
identifier = tmp.generate_new_identifier()
|
||||||
self.initialize_form_field("identifier", identifier)
|
self.initialize_form_field("identifier", identifier)
|
||||||
self.fields["identifier"].widget.attrs["url"] = reverse_lazy("compensation:acc-new-id")
|
self.fields["identifier"].widget.attrs["url"] = reverse_lazy("compensation:acc:new-id")
|
||||||
self.fields["title"].widget.attrs["placeholder"] = _("Eco-Account XY; Location ABC")
|
self.fields["title"].widget.attrs["placeholder"] = _("Eco-Account XY; Location ABC")
|
||||||
|
|
||||||
def save(self, user: User, geom_form: SimpleGeomForm):
|
def save(self, user: User, geom_form: SimpleGeomForm):
|
||||||
@@ -354,10 +410,12 @@ class NewEcoAccountForm(AbstractCompensationForm, CompensationResponsibleFormMix
|
|||||||
identifier = self.cleaned_data.get("identifier", None)
|
identifier = self.cleaned_data.get("identifier", None)
|
||||||
title = self.cleaned_data.get("title", None)
|
title = self.cleaned_data.get("title", None)
|
||||||
registration_date = self.cleaned_data.get("registration_date", None)
|
registration_date = self.cleaned_data.get("registration_date", None)
|
||||||
handler = self.cleaned_data.get("handler", None)
|
handler_type = self.cleaned_data.get("handler_type", None)
|
||||||
|
handler_detail = self.cleaned_data.get("handler_detail", None)
|
||||||
surface = self.cleaned_data.get("surface", None)
|
surface = self.cleaned_data.get("surface", None)
|
||||||
conservation_office = self.cleaned_data.get("conservation_office", None)
|
conservation_office = self.cleaned_data.get("conservation_office", None)
|
||||||
conservation_file_number = self.cleaned_data.get("conservation_file_number", None)
|
conservation_file_number = self.cleaned_data.get("conservation_file_number", None)
|
||||||
|
is_pik = self.cleaned_data.get("is_pik", None)
|
||||||
comment = self.cleaned_data.get("comment", None)
|
comment = self.cleaned_data.get("comment", None)
|
||||||
|
|
||||||
# Create log entry
|
# Create log entry
|
||||||
@@ -365,6 +423,11 @@ class NewEcoAccountForm(AbstractCompensationForm, CompensationResponsibleFormMix
|
|||||||
# Process the geometry form
|
# Process the geometry form
|
||||||
geometry = geom_form.save(action)
|
geometry = geom_form.save(action)
|
||||||
|
|
||||||
|
handler = Handler.objects.create(
|
||||||
|
type=handler_type,
|
||||||
|
detail=handler_detail,
|
||||||
|
)
|
||||||
|
|
||||||
responsible = Responsibility.objects.create(
|
responsible = Responsibility.objects.create(
|
||||||
handler=handler,
|
handler=handler,
|
||||||
conservation_file_number=conservation_file_number,
|
conservation_file_number=conservation_file_number,
|
||||||
@@ -384,9 +447,10 @@ class NewEcoAccountForm(AbstractCompensationForm, CompensationResponsibleFormMix
|
|||||||
created=action,
|
created=action,
|
||||||
geometry=geometry,
|
geometry=geometry,
|
||||||
comment=comment,
|
comment=comment,
|
||||||
|
is_pik=is_pik,
|
||||||
legal=legal
|
legal=legal
|
||||||
)
|
)
|
||||||
acc.share_with(user)
|
acc.share_with_user(user)
|
||||||
|
|
||||||
# Add the log entry to the main objects log list
|
# Add the log entry to the main objects log list
|
||||||
acc.log.add(action)
|
acc.log.add(action)
|
||||||
@@ -402,21 +466,24 @@ class EditEcoAccountForm(NewEcoAccountForm):
|
|||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
self.form_title = _("Edit Eco-Account")
|
self.form_title = _("Edit Eco-Account")
|
||||||
|
|
||||||
self.action_url = reverse("compensation:acc-edit", args=(self.instance.id,))
|
self.action_url = reverse("compensation:acc:edit", args=(self.instance.id,))
|
||||||
self.cancel_redirect = reverse("compensation:acc-detail", args=(self.instance.id,))
|
self.cancel_redirect = reverse("compensation:acc:detail", args=(self.instance.id,))
|
||||||
|
|
||||||
# Initialize form data
|
# Initialize form data
|
||||||
reg_date = self.instance.legal.registration_date
|
reg_date = self.instance.legal.registration_date
|
||||||
if reg_date is not None:
|
if reg_date is not None:
|
||||||
reg_date = reg_date.isoformat()
|
reg_date = reg_date.isoformat()
|
||||||
|
|
||||||
form_data = {
|
form_data = {
|
||||||
"identifier": self.instance.identifier,
|
"identifier": self.instance.identifier,
|
||||||
"title": self.instance.title,
|
"title": self.instance.title,
|
||||||
"surface": self.instance.deductable_surface,
|
"surface": self.instance.deductable_surface,
|
||||||
"handler": self.instance.responsible.handler,
|
"handler_type": self.instance.responsible.handler.type,
|
||||||
|
"handler_detail": self.instance.responsible.handler.detail,
|
||||||
"registration_date": reg_date,
|
"registration_date": reg_date,
|
||||||
"conservation_office": self.instance.responsible.conservation_office,
|
"conservation_office": self.instance.responsible.conservation_office,
|
||||||
"conservation_file_number": self.instance.responsible.conservation_file_number,
|
"conservation_file_number": self.instance.responsible.conservation_file_number,
|
||||||
|
"is_pik": self.instance.is_pik,
|
||||||
"comment": self.instance.comment,
|
"comment": self.instance.comment,
|
||||||
}
|
}
|
||||||
disabled_fields = []
|
disabled_fields = []
|
||||||
@@ -431,11 +498,13 @@ class EditEcoAccountForm(NewEcoAccountForm):
|
|||||||
identifier = self.cleaned_data.get("identifier", None)
|
identifier = self.cleaned_data.get("identifier", None)
|
||||||
title = self.cleaned_data.get("title", None)
|
title = self.cleaned_data.get("title", None)
|
||||||
registration_date = self.cleaned_data.get("registration_date", None)
|
registration_date = self.cleaned_data.get("registration_date", None)
|
||||||
handler = self.cleaned_data.get("handler", None)
|
handler_type = self.cleaned_data.get("handler_type", None)
|
||||||
|
handler_detail = self.cleaned_data.get("handler_detail", None)
|
||||||
surface = self.cleaned_data.get("surface", None)
|
surface = self.cleaned_data.get("surface", None)
|
||||||
conservation_office = self.cleaned_data.get("conservation_office", None)
|
conservation_office = self.cleaned_data.get("conservation_office", None)
|
||||||
conservation_file_number = self.cleaned_data.get("conservation_file_number", None)
|
conservation_file_number = self.cleaned_data.get("conservation_file_number", None)
|
||||||
comment = self.cleaned_data.get("comment", None)
|
comment = self.cleaned_data.get("comment", None)
|
||||||
|
is_pik = self.cleaned_data.get("is_pik", None)
|
||||||
|
|
||||||
# Create log entry
|
# Create log entry
|
||||||
action = UserActionLogEntry.get_edited_action(user)
|
action = UserActionLogEntry.get_edited_action(user)
|
||||||
@@ -444,7 +513,9 @@ class EditEcoAccountForm(NewEcoAccountForm):
|
|||||||
geometry = geom_form.save(action)
|
geometry = geom_form.save(action)
|
||||||
|
|
||||||
# Update responsible data
|
# Update responsible data
|
||||||
self.instance.responsible.handler = handler
|
self.instance.responsible.handler.type = handler_type
|
||||||
|
self.instance.responsible.handler.detail = handler_detail
|
||||||
|
self.instance.responsible.handler.save()
|
||||||
self.instance.responsible.conservation_office = conservation_office
|
self.instance.responsible.conservation_office = conservation_office
|
||||||
self.instance.responsible.conservation_file_number = conservation_file_number
|
self.instance.responsible.conservation_file_number = conservation_file_number
|
||||||
self.instance.responsible.save()
|
self.instance.responsible.save()
|
||||||
@@ -459,6 +530,7 @@ class EditEcoAccountForm(NewEcoAccountForm):
|
|||||||
self.instance.deductable_surface = surface
|
self.instance.deductable_surface = surface
|
||||||
self.instance.geometry = geometry
|
self.instance.geometry = geometry
|
||||||
self.instance.comment = comment
|
self.instance.comment = comment
|
||||||
|
self.instance.is_pik = is_pik
|
||||||
self.instance.modified = action
|
self.instance.modified = action
|
||||||
self.instance.save()
|
self.instance.save()
|
||||||
|
|
||||||
|
|||||||
@@ -17,11 +17,13 @@ from codelist.models import KonovaCode
|
|||||||
from codelist.settings import CODELIST_BIOTOPES_ID, CODELIST_COMPENSATION_ACTION_ID, CODELIST_BIOTOPES_EXTRA_CODES_ID, \
|
from codelist.settings import CODELIST_BIOTOPES_ID, CODELIST_COMPENSATION_ACTION_ID, CODELIST_BIOTOPES_EXTRA_CODES_ID, \
|
||||||
CODELIST_COMPENSATION_ACTION_DETAIL_ID
|
CODELIST_COMPENSATION_ACTION_DETAIL_ID
|
||||||
from compensation.models import CompensationDocument, EcoAccountDocument
|
from compensation.models import CompensationDocument, EcoAccountDocument
|
||||||
|
from intervention.inputs import CompensationActionTreeCheckboxSelectMultiple, \
|
||||||
|
CompensationStateTreeRadioSelect
|
||||||
from konova.contexts import BaseContext
|
from konova.contexts import BaseContext
|
||||||
from konova.forms import BaseModalForm, NewDocumentForm
|
from konova.forms.modals import BaseModalForm, NewDocumentModalForm, RemoveModalForm
|
||||||
from konova.models import DeadlineType
|
from konova.models import DeadlineType
|
||||||
from konova.utils.message_templates import FORM_INVALID, ADDED_COMPENSATION_STATE, ADDED_DEADLINE, \
|
from konova.utils.message_templates import FORM_INVALID, ADDED_COMPENSATION_STATE, \
|
||||||
ADDED_COMPENSATION_ACTION
|
ADDED_COMPENSATION_ACTION, PAYMENT_EDITED, COMPENSATION_STATE_EDITED, COMPENSATION_ACTION_EDITED, DEADLINE_EDITED
|
||||||
|
|
||||||
|
|
||||||
class NewPaymentForm(BaseModalForm):
|
class NewPaymentForm(BaseModalForm):
|
||||||
@@ -100,10 +102,54 @@ class NewPaymentForm(BaseModalForm):
|
|||||||
|
|
||||||
def save(self):
|
def save(self):
|
||||||
pay = self.instance.add_payment(self)
|
pay = self.instance.add_payment(self)
|
||||||
self.instance.mark_as_edited(self.user, self.request)
|
|
||||||
return pay
|
return pay
|
||||||
|
|
||||||
|
|
||||||
|
class EditPaymentModalForm(NewPaymentForm):
|
||||||
|
""" Form handling edit for Payment
|
||||||
|
|
||||||
|
"""
|
||||||
|
payment = None
|
||||||
|
|
||||||
|
def __init__(self, *args, **kwargs):
|
||||||
|
self.payment = kwargs.pop("payment", None)
|
||||||
|
super().__init__(*args, **kwargs)
|
||||||
|
self.form_title = _("Edit payment")
|
||||||
|
form_date = {
|
||||||
|
"amount": self.payment.amount,
|
||||||
|
"due": str(self.payment.due_on),
|
||||||
|
"comment": self.payment.comment,
|
||||||
|
}
|
||||||
|
self.load_initial_data(form_date, disabled_fields=[])
|
||||||
|
|
||||||
|
def save(self):
|
||||||
|
payment = self.payment
|
||||||
|
payment.amount = self.cleaned_data.get("amount", None)
|
||||||
|
payment.due_on = self.cleaned_data.get("due", None)
|
||||||
|
payment.comment = self.cleaned_data.get("comment", None)
|
||||||
|
payment.save()
|
||||||
|
self.instance.mark_as_edited(self.user, self.request, edit_comment=PAYMENT_EDITED)
|
||||||
|
self.instance.send_data_to_egon()
|
||||||
|
return payment
|
||||||
|
|
||||||
|
|
||||||
|
class RemovePaymentModalForm(RemoveModalForm):
|
||||||
|
""" Removing modal form for Payment
|
||||||
|
|
||||||
|
Can be used for anything, where removing shall be confirmed by the user a second time.
|
||||||
|
|
||||||
|
"""
|
||||||
|
payment = None
|
||||||
|
|
||||||
|
def __init__(self, *args, **kwargs):
|
||||||
|
payment = kwargs.pop("payment", None)
|
||||||
|
self.payment = payment
|
||||||
|
super().__init__(*args, **kwargs)
|
||||||
|
|
||||||
|
def save(self):
|
||||||
|
self.instance.remove_payment(self)
|
||||||
|
|
||||||
|
|
||||||
class NewStateModalForm(BaseModalForm):
|
class NewStateModalForm(BaseModalForm):
|
||||||
""" Form handling state related input
|
""" Form handling state related input
|
||||||
|
|
||||||
@@ -111,22 +157,12 @@ class NewStateModalForm(BaseModalForm):
|
|||||||
What has been on this area before changes/compensations have been applied and what will be the result ('after')?
|
What has been on this area before changes/compensations have been applied and what will be the result ('after')?
|
||||||
|
|
||||||
"""
|
"""
|
||||||
biotope_type = forms.ModelChoiceField(
|
biotope_type = forms.ChoiceField(
|
||||||
label=_("Biotope Type"),
|
label=_("Biotope Type"),
|
||||||
label_suffix="",
|
label_suffix="",
|
||||||
required=True,
|
required=True,
|
||||||
help_text=_("Select the biotope type"),
|
help_text=_("Select the biotope type"),
|
||||||
queryset=KonovaCode.objects.filter(
|
widget=CompensationStateTreeRadioSelect(),
|
||||||
is_archived=False,
|
|
||||||
is_leaf=True,
|
|
||||||
code_lists__in=[CODELIST_BIOTOPES_ID],
|
|
||||||
),
|
|
||||||
widget=autocomplete.ModelSelect2(
|
|
||||||
url="codes-biotope-autocomplete",
|
|
||||||
attrs={
|
|
||||||
"data-placeholder": _("Biotope Type"),
|
|
||||||
}
|
|
||||||
),
|
|
||||||
)
|
)
|
||||||
biotope_extra = forms.ModelMultipleChoiceField(
|
biotope_extra = forms.ModelMultipleChoiceField(
|
||||||
label=_("Biotope additional type"),
|
label=_("Biotope additional type"),
|
||||||
@@ -164,6 +200,16 @@ class NewStateModalForm(BaseModalForm):
|
|||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
self.form_title = _("New state")
|
self.form_title = _("New state")
|
||||||
self.form_caption = _("Insert data for the new state")
|
self.form_caption = _("Insert data for the new state")
|
||||||
|
choices = KonovaCode.objects.filter(
|
||||||
|
code_lists__in=[CODELIST_BIOTOPES_ID],
|
||||||
|
is_archived=False,
|
||||||
|
is_leaf=True,
|
||||||
|
).values_list("id", flat=True)
|
||||||
|
choices = [
|
||||||
|
(choice, choice)
|
||||||
|
for choice in choices
|
||||||
|
]
|
||||||
|
self.fields["biotope_type"].choices = choices
|
||||||
|
|
||||||
def save(self, is_before_state: bool = False):
|
def save(self, is_before_state: bool = False):
|
||||||
state = self.instance.add_state(self, is_before_state)
|
state = self.instance.add_state(self, is_before_state)
|
||||||
@@ -219,6 +265,66 @@ class NewStateModalForm(BaseModalForm):
|
|||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
|
|
||||||
|
class EditCompensationStateModalForm(NewStateModalForm):
|
||||||
|
state = None
|
||||||
|
|
||||||
|
def __init__(self, *args, **kwargs):
|
||||||
|
self.state = kwargs.pop("state", None)
|
||||||
|
super().__init__(*args, **kwargs)
|
||||||
|
self.form_title = _("Edit state")
|
||||||
|
biotope_type_id = self.state.biotope_type.id if self.state.biotope_type else None
|
||||||
|
form_data = {
|
||||||
|
"biotope_type": biotope_type_id,
|
||||||
|
"biotope_extra": self.state.biotope_type_details.all(),
|
||||||
|
"surface": self.state.surface,
|
||||||
|
}
|
||||||
|
self.load_initial_data(form_data)
|
||||||
|
|
||||||
|
def save(self, is_before_state: bool = False):
|
||||||
|
state = self.state
|
||||||
|
biotope_type_id = self.cleaned_data.get("biotope_type", None)
|
||||||
|
state.biotope_type = KonovaCode.objects.get(id=biotope_type_id)
|
||||||
|
state.biotope_type_details.set(self.cleaned_data.get("biotope_extra", []))
|
||||||
|
state.surface = self.cleaned_data.get("surface", None)
|
||||||
|
state.save()
|
||||||
|
self.instance.mark_as_edited(self.user, self.request, edit_comment=COMPENSATION_STATE_EDITED)
|
||||||
|
return state
|
||||||
|
|
||||||
|
|
||||||
|
class RemoveCompensationStateModalForm(RemoveModalForm):
|
||||||
|
""" Removing modal form for CompensationState
|
||||||
|
|
||||||
|
Can be used for anything, where removing shall be confirmed by the user a second time.
|
||||||
|
|
||||||
|
"""
|
||||||
|
state = None
|
||||||
|
|
||||||
|
def __init__(self, *args, **kwargs):
|
||||||
|
state = kwargs.pop("state", None)
|
||||||
|
self.state = state
|
||||||
|
super().__init__(*args, **kwargs)
|
||||||
|
|
||||||
|
def save(self):
|
||||||
|
self.instance.remove_state(self)
|
||||||
|
|
||||||
|
|
||||||
|
class RemoveCompensationActionModalForm(RemoveModalForm):
|
||||||
|
""" Removing modal form for CompensationAction
|
||||||
|
|
||||||
|
Can be used for anything, where removing shall be confirmed by the user a second time.
|
||||||
|
|
||||||
|
"""
|
||||||
|
action = None
|
||||||
|
|
||||||
|
def __init__(self, *args, **kwargs):
|
||||||
|
action = kwargs.pop("action", None)
|
||||||
|
self.action = action
|
||||||
|
super().__init__(*args, **kwargs)
|
||||||
|
|
||||||
|
def save(self):
|
||||||
|
self.instance.remove_action(self)
|
||||||
|
|
||||||
|
|
||||||
class NewDeadlineModalForm(BaseModalForm):
|
class NewDeadlineModalForm(BaseModalForm):
|
||||||
""" Form handling deadline related input
|
""" Form handling deadline related input
|
||||||
|
|
||||||
@@ -271,7 +377,30 @@ class NewDeadlineModalForm(BaseModalForm):
|
|||||||
|
|
||||||
def save(self):
|
def save(self):
|
||||||
deadline = self.instance.add_deadline(self)
|
deadline = self.instance.add_deadline(self)
|
||||||
self.instance.mark_as_edited(self.user, self.request, ADDED_DEADLINE)
|
return deadline
|
||||||
|
|
||||||
|
|
||||||
|
class EditDeadlineModalForm(NewDeadlineModalForm):
|
||||||
|
deadline = None
|
||||||
|
|
||||||
|
def __init__(self, *args, **kwargs):
|
||||||
|
self.deadline = kwargs.pop("deadline", None)
|
||||||
|
super().__init__(*args, **kwargs)
|
||||||
|
self.form_title = _("Edit deadline")
|
||||||
|
form_data = {
|
||||||
|
"type": self.deadline.type,
|
||||||
|
"date": str(self.deadline.date),
|
||||||
|
"comment": self.deadline.comment,
|
||||||
|
}
|
||||||
|
self.load_initial_data(form_data)
|
||||||
|
|
||||||
|
def save(self):
|
||||||
|
deadline = self.deadline
|
||||||
|
deadline.type = self.cleaned_data.get("type", None)
|
||||||
|
deadline.date = self.cleaned_data.get("date", None)
|
||||||
|
deadline.comment = self.cleaned_data.get("comment", None)
|
||||||
|
deadline.save()
|
||||||
|
self.instance.mark_as_edited(self.user, self.request, edit_comment=DEADLINE_EDITED)
|
||||||
return deadline
|
return deadline
|
||||||
|
|
||||||
|
|
||||||
@@ -284,22 +413,13 @@ class NewActionModalForm(BaseModalForm):
|
|||||||
|
|
||||||
"""
|
"""
|
||||||
from compensation.models import UnitChoices
|
from compensation.models import UnitChoices
|
||||||
action_type = forms.ModelChoiceField(
|
action_type = forms.MultipleChoiceField(
|
||||||
label=_("Action Type"),
|
label=_("Action Type"),
|
||||||
label_suffix="",
|
label_suffix="",
|
||||||
required=True,
|
required=True,
|
||||||
help_text=_("Select the action type"),
|
help_text=_("An action can consist of multiple different action types. All the selected action types are expected to be performed according to the amount and unit below on this form."),
|
||||||
queryset=KonovaCode.objects.filter(
|
choices=[],
|
||||||
is_archived=False,
|
widget=CompensationActionTreeCheckboxSelectMultiple(),
|
||||||
is_leaf=True,
|
|
||||||
code_lists__in=[CODELIST_COMPENSATION_ACTION_ID],
|
|
||||||
),
|
|
||||||
widget=autocomplete.ModelSelect2(
|
|
||||||
url="codes-compensation-action-autocomplete",
|
|
||||||
attrs={
|
|
||||||
"data-placeholder": _("Action"),
|
|
||||||
}
|
|
||||||
),
|
|
||||||
)
|
)
|
||||||
action_type_details = forms.ModelMultipleChoiceField(
|
action_type_details = forms.ModelMultipleChoiceField(
|
||||||
label=_("Action Type detail"),
|
label=_("Action Type detail"),
|
||||||
@@ -346,10 +466,9 @@ class NewActionModalForm(BaseModalForm):
|
|||||||
)
|
)
|
||||||
comment = forms.CharField(
|
comment = forms.CharField(
|
||||||
required=False,
|
required=False,
|
||||||
max_length=200,
|
|
||||||
label=_("Comment"),
|
label=_("Comment"),
|
||||||
label_suffix=_(""),
|
label_suffix=_(""),
|
||||||
help_text=_("Additional comment, maximum {} letters").format(200),
|
help_text=_("Additional comment"),
|
||||||
widget=forms.Textarea(
|
widget=forms.Textarea(
|
||||||
attrs={
|
attrs={
|
||||||
"rows": 5,
|
"rows": 5,
|
||||||
@@ -362,6 +481,16 @@ class NewActionModalForm(BaseModalForm):
|
|||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
self.form_title = _("New action")
|
self.form_title = _("New action")
|
||||||
self.form_caption = _("Insert data for the new action")
|
self.form_caption = _("Insert data for the new action")
|
||||||
|
choices =KonovaCode.objects.filter(
|
||||||
|
code_lists__in=[CODELIST_COMPENSATION_ACTION_ID],
|
||||||
|
is_archived=False,
|
||||||
|
is_leaf=True,
|
||||||
|
).values_list("id", flat=True)
|
||||||
|
choices = [
|
||||||
|
(choice, choice)
|
||||||
|
for choice in choices
|
||||||
|
]
|
||||||
|
self.fields["action_type"].choices = choices
|
||||||
|
|
||||||
def save(self):
|
def save(self):
|
||||||
action = self.instance.add_action(self)
|
action = self.instance.add_action(self)
|
||||||
@@ -369,9 +498,37 @@ class NewActionModalForm(BaseModalForm):
|
|||||||
return action
|
return action
|
||||||
|
|
||||||
|
|
||||||
class NewCompensationDocumentForm(NewDocumentForm):
|
class EditCompensationActionModalForm(NewActionModalForm):
|
||||||
|
action = None
|
||||||
|
|
||||||
|
def __init__(self, *args, **kwargs):
|
||||||
|
self.action = kwargs.pop("action", None)
|
||||||
|
super().__init__(*args, **kwargs)
|
||||||
|
self.form_title = _("Edit action")
|
||||||
|
form_data = {
|
||||||
|
"action_type": list(self.action.action_type.values_list("id", flat=True)),
|
||||||
|
"action_type_details": self.action.action_type_details.all(),
|
||||||
|
"amount": self.action.amount,
|
||||||
|
"unit": self.action.unit,
|
||||||
|
"comment": self.action.comment,
|
||||||
|
}
|
||||||
|
self.load_initial_data(form_data)
|
||||||
|
|
||||||
|
def save(self):
|
||||||
|
action = self.action
|
||||||
|
action.action_type.set(self.cleaned_data.get("action_type", []))
|
||||||
|
action.action_type_details.set(self.cleaned_data.get("action_type_details", []))
|
||||||
|
action.amount = self.cleaned_data.get("amount", None)
|
||||||
|
action.unit = self.cleaned_data.get("unit", None)
|
||||||
|
action.comment = self.cleaned_data.get("comment", None)
|
||||||
|
action.save()
|
||||||
|
self.instance.mark_as_edited(self.user, self.request, edit_comment=COMPENSATION_ACTION_EDITED)
|
||||||
|
return action
|
||||||
|
|
||||||
|
|
||||||
|
class NewCompensationDocumentModalForm(NewDocumentModalForm):
|
||||||
document_model = CompensationDocument
|
document_model = CompensationDocument
|
||||||
|
|
||||||
|
|
||||||
class NewEcoAccountDocumentForm(NewDocumentForm):
|
class NewEcoAccountDocumentModalForm(NewDocumentModalForm):
|
||||||
document_model = EcoAccountDocument
|
document_model = EcoAccountDocument
|
||||||
@@ -8,17 +8,6 @@ Created on: 14.10.21
|
|||||||
from django.db import models
|
from django.db import models
|
||||||
|
|
||||||
|
|
||||||
class CompensationActionManager(models.Manager):
|
|
||||||
""" Holds default db fetch setting for this model type
|
|
||||||
|
|
||||||
"""
|
|
||||||
def get_queryset(self):
|
|
||||||
return super().get_queryset().select_related(
|
|
||||||
"action_type",
|
|
||||||
"action_type__parent"
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
class CompensationStateManager(models.Manager):
|
class CompensationStateManager(models.Manager):
|
||||||
""" Holds default db fetch setting for this model type
|
""" Holds default db fetch setting for this model type
|
||||||
|
|
||||||
|
|||||||
42
compensation/migrations/0004_auto_20220210_1402.py
Normal file
42
compensation/migrations/0004_auto_20220210_1402.py
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
# Generated by Django 3.1.3 on 2022-02-10 13:02
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
def migrate_actions(apps, schema_editor):
|
||||||
|
CompensationAction = apps.get_model('compensation', 'CompensationAction')
|
||||||
|
actions = CompensationAction.objects.all()
|
||||||
|
|
||||||
|
for action in actions:
|
||||||
|
action_type = action.action_type or []
|
||||||
|
action.action_type_tmp.set([action_type])
|
||||||
|
action.save()
|
||||||
|
|
||||||
|
if not action.action_type_tmp.count() > 0:
|
||||||
|
raise ValueError("Migration of actions did not work! Stoped before data loss!")
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('codelist', '0001_initial'),
|
||||||
|
('compensation', '0003_auto_20220202_0846'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='compensationaction',
|
||||||
|
name='action_type_tmp',
|
||||||
|
field=models.ManyToManyField(blank=True, limit_choices_to={'code_lists__in': [1026], 'is_archived': False, 'is_selectable': True}, related_name='_compensationaction_action_type_+', to='codelist.KonovaCode'),
|
||||||
|
),
|
||||||
|
migrations.RunPython(migrate_actions),
|
||||||
|
migrations.RemoveField(
|
||||||
|
model_name='compensationaction',
|
||||||
|
name='action_type',
|
||||||
|
),
|
||||||
|
migrations.RenameField(
|
||||||
|
model_name='compensationaction',
|
||||||
|
old_name='action_type_tmp',
|
||||||
|
new_name='action_type',
|
||||||
|
)
|
||||||
|
]
|
||||||
46
compensation/migrations/0005_auto_20220218_0917.py
Normal file
46
compensation/migrations/0005_auto_20220218_0917.py
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
# Generated by Django 3.1.3 on 2022-02-18 08:17
|
||||||
|
|
||||||
|
from django.db import migrations, models, transaction
|
||||||
|
import django.db.models.deletion
|
||||||
|
|
||||||
|
from codelist.settings import CODELIST_BIOTOPES_ID, CODELIST_AFTER_STATE_BIOTOPES_ID
|
||||||
|
|
||||||
|
|
||||||
|
def migrate_entries_974_to_654(apps, schema_editor):
|
||||||
|
CompensationState = apps.get_model("compensation", "CompensationState")
|
||||||
|
KonovaCode = apps.get_model("codelist", "KonovaCode")
|
||||||
|
all_states = CompensationState.objects.all()
|
||||||
|
|
||||||
|
with transaction.atomic():
|
||||||
|
for state in all_states:
|
||||||
|
code_from_654 = KonovaCode.objects.get(
|
||||||
|
short_name=state.biotope_type.short_name,
|
||||||
|
code_lists__in=[CODELIST_BIOTOPES_ID],
|
||||||
|
is_archived=False,
|
||||||
|
is_leaf=True,
|
||||||
|
)
|
||||||
|
state.biotope_type = code_from_654
|
||||||
|
state.save()
|
||||||
|
|
||||||
|
old_list_states = CompensationState.objects.filter(
|
||||||
|
biotope_type__code_lists__in=[CODELIST_AFTER_STATE_BIOTOPES_ID]
|
||||||
|
)
|
||||||
|
if old_list_states.count() > 0:
|
||||||
|
raise Exception("Still unmigrated values!")
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('codelist', '0001_initial'),
|
||||||
|
('compensation', '0004_auto_20220210_1402'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.RunPython(migrate_entries_974_to_654),
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='compensationstate',
|
||||||
|
name='biotope_type',
|
||||||
|
field=models.ForeignKey(blank=True, limit_choices_to={'code_lists__in': [654], 'is_archived': False, 'is_selectable': True}, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='+', to='codelist.konovacode'),
|
||||||
|
),
|
||||||
|
]
|
||||||
19
compensation/migrations/0006_ecoaccount_teams.py
Normal file
19
compensation/migrations/0006_ecoaccount_teams.py
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
# Generated by Django 3.1.3 on 2022-02-18 09:13
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('user', '0003_team'),
|
||||||
|
('compensation', '0005_auto_20220218_0917'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='ecoaccount',
|
||||||
|
name='teams',
|
||||||
|
field=models.ManyToManyField(help_text='Teams having access (data shared with)', to='user.Team'),
|
||||||
|
),
|
||||||
|
]
|
||||||
23
compensation/migrations/0007_auto_20220531_1245.py
Normal file
23
compensation/migrations/0007_auto_20220531_1245.py
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
# Generated by Django 3.1.3 on 2022-05-31 10:45
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('compensation', '0006_ecoaccount_teams'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='compensation',
|
||||||
|
name='is_pik',
|
||||||
|
field=models.BooleanField(blank=True, default=False, help_text="Flag if compensation is a 'Produktonsintegrierte Kompensation'", null=True),
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='ecoaccount',
|
||||||
|
name='is_pik',
|
||||||
|
field=models.BooleanField(blank=True, default=False, help_text="Flag if compensation is a 'Produktonsintegrierte Kompensation'", null=True),
|
||||||
|
),
|
||||||
|
]
|
||||||
24
compensation/migrations/0008_auto_20220815_0803.py
Normal file
24
compensation/migrations/0008_auto_20220815_0803.py
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
# Generated by Django 3.1.3 on 2022-08-15 06:03
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('konova', '0014_resubmission'),
|
||||||
|
('compensation', '0007_auto_20220531_1245'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='compensation',
|
||||||
|
name='resubmission',
|
||||||
|
field=models.ManyToManyField(blank=True, null=True, related_name='_compensation_resubmission_+', to='konova.Resubmission'),
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='ecoaccount',
|
||||||
|
name='resubmission',
|
||||||
|
field=models.ManyToManyField(blank=True, null=True, related_name='_ecoaccount_resubmission_+', to='konova.Resubmission'),
|
||||||
|
),
|
||||||
|
]
|
||||||
32
compensation/migrations/0009_auto_20220815_0803.py
Normal file
32
compensation/migrations/0009_auto_20220815_0803.py
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
# Generated by Django 3.1.3 on 2022-08-15 06:03
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('konova', '0014_resubmission'),
|
||||||
|
('compensation', '0008_auto_20220815_0803'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.RemoveField(
|
||||||
|
model_name='compensation',
|
||||||
|
name='resubmission',
|
||||||
|
),
|
||||||
|
migrations.RemoveField(
|
||||||
|
model_name='ecoaccount',
|
||||||
|
name='resubmission',
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='compensation',
|
||||||
|
name='resubmissions',
|
||||||
|
field=models.ManyToManyField(blank=True, null=True, related_name='_compensation_resubmissions_+', to='konova.Resubmission'),
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='ecoaccount',
|
||||||
|
name='resubmissions',
|
||||||
|
field=models.ManyToManyField(blank=True, null=True, related_name='_ecoaccount_resubmissions_+', to='konova.Resubmission'),
|
||||||
|
),
|
||||||
|
]
|
||||||
24
compensation/migrations/0010_auto_20220815_1030.py
Normal file
24
compensation/migrations/0010_auto_20220815_1030.py
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
# Generated by Django 3.1.3 on 2022-08-15 08:30
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('konova', '0014_resubmission'),
|
||||||
|
('compensation', '0009_auto_20220815_0803'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='compensation',
|
||||||
|
name='resubmissions',
|
||||||
|
field=models.ManyToManyField(blank=True, related_name='_compensation_resubmissions_+', to='konova.Resubmission'),
|
||||||
|
),
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='ecoaccount',
|
||||||
|
name='resubmissions',
|
||||||
|
field=models.ManyToManyField(blank=True, related_name='_ecoaccount_resubmissions_+', to='konova.Resubmission'),
|
||||||
|
),
|
||||||
|
]
|
||||||
@@ -10,7 +10,6 @@ from django.utils.translation import gettext_lazy as _
|
|||||||
|
|
||||||
from codelist.models import KonovaCode
|
from codelist.models import KonovaCode
|
||||||
from codelist.settings import CODELIST_COMPENSATION_ACTION_ID, CODELIST_COMPENSATION_ACTION_DETAIL_ID
|
from codelist.settings import CODELIST_COMPENSATION_ACTION_ID, CODELIST_COMPENSATION_ACTION_DETAIL_ID
|
||||||
from compensation.managers import CompensationActionManager
|
|
||||||
from konova.models import BaseResource
|
from konova.models import BaseResource
|
||||||
|
|
||||||
|
|
||||||
@@ -30,10 +29,8 @@ class CompensationAction(BaseResource):
|
|||||||
"""
|
"""
|
||||||
Compensations include actions like planting trees, refreshing rivers and so on.
|
Compensations include actions like planting trees, refreshing rivers and so on.
|
||||||
"""
|
"""
|
||||||
action_type = models.ForeignKey(
|
action_type = models.ManyToManyField(
|
||||||
KonovaCode,
|
KonovaCode,
|
||||||
on_delete=models.SET_NULL,
|
|
||||||
null=True,
|
|
||||||
blank=True,
|
blank=True,
|
||||||
limit_choices_to={
|
limit_choices_to={
|
||||||
"code_lists__in": [CODELIST_COMPENSATION_ACTION_ID],
|
"code_lists__in": [CODELIST_COMPENSATION_ACTION_ID],
|
||||||
@@ -56,10 +53,8 @@ class CompensationAction(BaseResource):
|
|||||||
unit = models.CharField(max_length=100, null=True, blank=True, choices=UnitChoices.choices)
|
unit = models.CharField(max_length=100, null=True, blank=True, choices=UnitChoices.choices)
|
||||||
comment = models.TextField(blank=True, null=True, help_text="Additional comment")
|
comment = models.TextField(blank=True, null=True, help_text="Additional comment")
|
||||||
|
|
||||||
objects = CompensationActionManager()
|
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return f"{self.action_type} | {self.amount} {self.unit}"
|
return f"{self.action_type.all()} | {self.amount} {self.unit}"
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def unit_humanize(self):
|
def unit_humanize(self):
|
||||||
|
|||||||
@@ -8,23 +8,28 @@ Created on: 16.11.21
|
|||||||
import shutil
|
import shutil
|
||||||
|
|
||||||
from django.contrib import messages
|
from django.contrib import messages
|
||||||
from user.models import User
|
|
||||||
|
from codelist.models import KonovaCode
|
||||||
|
from user.models import User, Team
|
||||||
from django.db import models, transaction
|
from django.db import models, transaction
|
||||||
from django.db.models import QuerySet, Sum
|
from django.db.models import QuerySet, Sum
|
||||||
from django.http import HttpRequest
|
from django.http import HttpRequest
|
||||||
from django.utils.translation import gettext_lazy as _
|
|
||||||
|
|
||||||
from compensation.managers import CompensationManager
|
from compensation.managers import CompensationManager
|
||||||
from compensation.models import CompensationState, CompensationAction
|
from compensation.models import CompensationState, CompensationAction
|
||||||
from compensation.utils.quality import CompensationQualityChecker
|
from compensation.utils.quality import CompensationQualityChecker
|
||||||
from konova.models import BaseObject, AbstractDocument, Deadline, generate_document_file_upload_path, \
|
from konova.models import BaseObject, AbstractDocument, Deadline, generate_document_file_upload_path, \
|
||||||
GeoReferencedMixin
|
GeoReferencedMixin, DeadlineType, ResubmitableObjectMixin
|
||||||
from konova.settings import DEFAULT_SRID_RLP, LANIS_LINK_TEMPLATE
|
from konova.utils.message_templates import DATA_UNSHARED_EXPLANATION, COMPENSATION_REMOVED_TEMPLATE, \
|
||||||
from konova.utils.message_templates import DATA_UNSHARED_EXPLANATION
|
DOCUMENT_REMOVED_TEMPLATE, DEADLINE_REMOVED, ADDED_DEADLINE, \
|
||||||
|
COMPENSATION_ACTION_REMOVED, COMPENSATION_STATE_REMOVED, INTERVENTION_HAS_REVOCATIONS_TEMPLATE
|
||||||
from user.models import UserActionLogEntry
|
from user.models import UserActionLogEntry
|
||||||
|
|
||||||
|
|
||||||
class AbstractCompensation(BaseObject, GeoReferencedMixin):
|
class AbstractCompensation(BaseObject,
|
||||||
|
GeoReferencedMixin,
|
||||||
|
ResubmitableObjectMixin
|
||||||
|
):
|
||||||
"""
|
"""
|
||||||
Abstract compensation model which holds basic attributes, shared by subclasses like the regular Compensation,
|
Abstract compensation model which holds basic attributes, shared by subclasses like the regular Compensation,
|
||||||
EMA or EcoAccount.
|
EMA or EcoAccount.
|
||||||
@@ -60,7 +65,6 @@ class AbstractCompensation(BaseObject, GeoReferencedMixin):
|
|||||||
user = form.user
|
user = form.user
|
||||||
with transaction.atomic():
|
with transaction.atomic():
|
||||||
created_action = UserActionLogEntry.get_created_action(user)
|
created_action = UserActionLogEntry.get_created_action(user)
|
||||||
edited_action = UserActionLogEntry.get_edited_action(user, _("Added deadline"))
|
|
||||||
|
|
||||||
deadline = Deadline.objects.create(
|
deadline = Deadline.objects.create(
|
||||||
type=form_data["type"],
|
type=form_data["type"],
|
||||||
@@ -69,12 +73,26 @@ class AbstractCompensation(BaseObject, GeoReferencedMixin):
|
|||||||
created=created_action,
|
created=created_action,
|
||||||
)
|
)
|
||||||
|
|
||||||
self.modified = edited_action
|
|
||||||
self.save()
|
self.save()
|
||||||
self.log.add(edited_action)
|
|
||||||
self.deadlines.add(deadline)
|
self.deadlines.add(deadline)
|
||||||
|
self.mark_as_edited(user, edit_comment=ADDED_DEADLINE)
|
||||||
return deadline
|
return deadline
|
||||||
|
|
||||||
|
def remove_deadline(self, form):
|
||||||
|
""" Removes a deadline from the abstract compensation
|
||||||
|
|
||||||
|
Args:
|
||||||
|
form (RemoveDeadlineModalForm): The form holding all relevant data
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
|
||||||
|
"""
|
||||||
|
deadline = form.deadline
|
||||||
|
user = form.user
|
||||||
|
with transaction.atomic():
|
||||||
|
deadline.delete()
|
||||||
|
self.mark_as_edited(user, edit_comment=DEADLINE_REMOVED)
|
||||||
|
|
||||||
def add_action(self, form) -> CompensationAction:
|
def add_action(self, form) -> CompensationAction:
|
||||||
""" Adds a new action to the compensation
|
""" Adds a new action to the compensation
|
||||||
|
|
||||||
@@ -89,17 +107,32 @@ class AbstractCompensation(BaseObject, GeoReferencedMixin):
|
|||||||
with transaction.atomic():
|
with transaction.atomic():
|
||||||
user_action = UserActionLogEntry.get_created_action(user)
|
user_action = UserActionLogEntry.get_created_action(user)
|
||||||
comp_action = CompensationAction.objects.create(
|
comp_action = CompensationAction.objects.create(
|
||||||
action_type=form_data["action_type"],
|
|
||||||
amount=form_data["amount"],
|
amount=form_data["amount"],
|
||||||
unit=form_data["unit"],
|
unit=form_data["unit"],
|
||||||
comment=form_data["comment"],
|
comment=form_data["comment"],
|
||||||
created=user_action,
|
created=user_action,
|
||||||
)
|
)
|
||||||
|
comp_action.action_type.set(form_data.get("action_type", []))
|
||||||
comp_action_details = form_data["action_type_details"]
|
comp_action_details = form_data["action_type_details"]
|
||||||
comp_action.action_type_details.set(comp_action_details)
|
comp_action.action_type_details.set(comp_action_details)
|
||||||
self.actions.add(comp_action)
|
self.actions.add(comp_action)
|
||||||
return comp_action
|
return comp_action
|
||||||
|
|
||||||
|
def remove_action(self, form):
|
||||||
|
""" Removes a CompensationAction from the abstract compensation
|
||||||
|
|
||||||
|
Args:
|
||||||
|
form (RemoveCompensationActionModalForm): The form holding all relevant data
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
|
||||||
|
"""
|
||||||
|
action = form.action
|
||||||
|
user = form.user
|
||||||
|
with transaction.atomic():
|
||||||
|
action.delete()
|
||||||
|
self.mark_as_edited(user, edit_comment=COMPENSATION_ACTION_REMOVED)
|
||||||
|
|
||||||
def add_state(self, form, is_before_state: bool) -> CompensationState:
|
def add_state(self, form, is_before_state: bool) -> CompensationState:
|
||||||
""" Adds a new compensation state to the compensation
|
""" Adds a new compensation state to the compensation
|
||||||
|
|
||||||
@@ -112,8 +145,10 @@ class AbstractCompensation(BaseObject, GeoReferencedMixin):
|
|||||||
"""
|
"""
|
||||||
form_data = form.cleaned_data
|
form_data = form.cleaned_data
|
||||||
with transaction.atomic():
|
with transaction.atomic():
|
||||||
|
biotope_type_id = form_data["biotope_type"]
|
||||||
|
code = KonovaCode.objects.get(id=biotope_type_id)
|
||||||
state = CompensationState.objects.create(
|
state = CompensationState.objects.create(
|
||||||
biotope_type=form_data["biotope_type"],
|
biotope_type=code,
|
||||||
surface=form_data["surface"],
|
surface=form_data["surface"],
|
||||||
)
|
)
|
||||||
state_additional_types = form_data["biotope_extra"]
|
state_additional_types = form_data["biotope_extra"]
|
||||||
@@ -124,6 +159,21 @@ class AbstractCompensation(BaseObject, GeoReferencedMixin):
|
|||||||
self.after_states.add(state)
|
self.after_states.add(state)
|
||||||
return state
|
return state
|
||||||
|
|
||||||
|
def remove_state(self, form):
|
||||||
|
""" Removes a CompensationState from the abstract compensation
|
||||||
|
|
||||||
|
Args:
|
||||||
|
form (RemoveCompensationStateModalForm): The form holding all relevant data
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
|
||||||
|
"""
|
||||||
|
state = form.state
|
||||||
|
user = form.user
|
||||||
|
with transaction.atomic():
|
||||||
|
state.delete()
|
||||||
|
self.mark_as_edited(user, edit_comment=COMPENSATION_STATE_REMOVED)
|
||||||
|
|
||||||
def get_surface_after_states(self) -> float:
|
def get_surface_after_states(self) -> float:
|
||||||
""" Calculates the compensation's/account's surface
|
""" Calculates the compensation's/account's surface
|
||||||
|
|
||||||
@@ -177,6 +227,15 @@ class AbstractCompensation(BaseObject, GeoReferencedMixin):
|
|||||||
request = self.set_geometry_conflict_message(request)
|
request = self.set_geometry_conflict_message(request)
|
||||||
return request
|
return request
|
||||||
|
|
||||||
|
def get_finished_deadlines(self):
|
||||||
|
""" Getter for FINISHED-deadlines
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
queryset (QuerySet): The finished deadlines
|
||||||
|
"""
|
||||||
|
return self.deadlines.filter(
|
||||||
|
type=DeadlineType.FINISHED
|
||||||
|
)
|
||||||
|
|
||||||
class CEFMixin(models.Model):
|
class CEFMixin(models.Model):
|
||||||
""" Provides CEF flag as Mixin
|
""" Provides CEF flag as Mixin
|
||||||
@@ -208,7 +267,22 @@ class CoherenceMixin(models.Model):
|
|||||||
abstract = True
|
abstract = True
|
||||||
|
|
||||||
|
|
||||||
class Compensation(AbstractCompensation, CEFMixin, CoherenceMixin):
|
class PikMixin(models.Model):
|
||||||
|
""" Provides PIK flag as Mixin
|
||||||
|
|
||||||
|
"""
|
||||||
|
is_pik = models.BooleanField(
|
||||||
|
blank=True,
|
||||||
|
null=True,
|
||||||
|
default=False,
|
||||||
|
help_text="Flag if compensation is a 'Produktonsintegrierte Kompensation'"
|
||||||
|
)
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
abstract = True
|
||||||
|
|
||||||
|
|
||||||
|
class Compensation(AbstractCompensation, CEFMixin, CoherenceMixin, PikMixin):
|
||||||
"""
|
"""
|
||||||
Regular compensation, linked to an intervention
|
Regular compensation, linked to an intervention
|
||||||
"""
|
"""
|
||||||
@@ -235,6 +309,11 @@ class Compensation(AbstractCompensation, CEFMixin, CoherenceMixin):
|
|||||||
self.identifier = self.generate_new_identifier()
|
self.identifier = self.generate_new_identifier()
|
||||||
super().save(*args, **kwargs)
|
super().save(*args, **kwargs)
|
||||||
|
|
||||||
|
def mark_as_deleted(self, user, send_mail: bool = True):
|
||||||
|
super().mark_as_deleted(user, send_mail)
|
||||||
|
if user is not None:
|
||||||
|
self.intervention.mark_as_edited(user, edit_comment=COMPENSATION_REMOVED_TEMPLATE.format(self.identifier))
|
||||||
|
|
||||||
def is_shared_with(self, user: User):
|
def is_shared_with(self, user: User):
|
||||||
""" Access check
|
""" Access check
|
||||||
|
|
||||||
@@ -249,7 +328,7 @@ class Compensation(AbstractCompensation, CEFMixin, CoherenceMixin):
|
|||||||
# Compensations inherit their shared state from the interventions
|
# Compensations inherit their shared state from the interventions
|
||||||
return self.intervention.is_shared_with(user)
|
return self.intervention.is_shared_with(user)
|
||||||
|
|
||||||
def share_with(self, user: User):
|
def share_with_user(self, user: User):
|
||||||
""" Adds user to list of shared access users
|
""" Adds user to list of shared access users
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
@@ -258,10 +337,9 @@ class Compensation(AbstractCompensation, CEFMixin, CoherenceMixin):
|
|||||||
Returns:
|
Returns:
|
||||||
|
|
||||||
"""
|
"""
|
||||||
if not self.intervention.is_shared_with(user):
|
self.intervention.users.add(user)
|
||||||
self.intervention.users.add(user)
|
|
||||||
|
|
||||||
def share_with_list(self, user_list: list):
|
def share_with_user_list(self, user_list: list):
|
||||||
""" Sets the list of shared access users
|
""" Sets the list of shared access users
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
@@ -272,6 +350,28 @@ class Compensation(AbstractCompensation, CEFMixin, CoherenceMixin):
|
|||||||
"""
|
"""
|
||||||
self.intervention.users.set(user_list)
|
self.intervention.users.set(user_list)
|
||||||
|
|
||||||
|
def share_with_team(self, team: Team):
|
||||||
|
""" Adds team to list of shared access teams
|
||||||
|
|
||||||
|
Args:
|
||||||
|
team (Team): The team to be added to the object
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
|
||||||
|
"""
|
||||||
|
self.intervention.teams.add(team)
|
||||||
|
|
||||||
|
def share_with_team_list(self, team_list: list):
|
||||||
|
""" Sets the list of shared access teams
|
||||||
|
|
||||||
|
Args:
|
||||||
|
team_list (list): The teams to be added to the object
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
|
||||||
|
"""
|
||||||
|
self.intervention.teams.set(team_list)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def shared_users(self) -> QuerySet:
|
def shared_users(self) -> QuerySet:
|
||||||
""" Shortcut for fetching the users which have shared access on this object
|
""" Shortcut for fetching the users which have shared access on this object
|
||||||
@@ -281,27 +381,14 @@ class Compensation(AbstractCompensation, CEFMixin, CoherenceMixin):
|
|||||||
"""
|
"""
|
||||||
return self.intervention.users.all()
|
return self.intervention.users.all()
|
||||||
|
|
||||||
def get_LANIS_link(self) -> str:
|
@property
|
||||||
""" Generates a link for LANIS depending on the geometry
|
def shared_teams(self) -> QuerySet:
|
||||||
|
""" Shortcut for fetching the teams which have shared access on this object
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
|
users (QuerySet)
|
||||||
"""
|
"""
|
||||||
try:
|
return self.intervention.teams.all()
|
||||||
geom = self.geometry.geom.transform(DEFAULT_SRID_RLP, clone=True)
|
|
||||||
x = geom.centroid.x
|
|
||||||
y = geom.centroid.y
|
|
||||||
zoom_lvl = 16
|
|
||||||
except AttributeError:
|
|
||||||
# If no geometry has been added, yet.
|
|
||||||
x = 1
|
|
||||||
y = 1
|
|
||||||
zoom_lvl = 6
|
|
||||||
return LANIS_LINK_TEMPLATE.format(
|
|
||||||
zoom_lvl,
|
|
||||||
x,
|
|
||||||
y,
|
|
||||||
)
|
|
||||||
|
|
||||||
def get_documents(self) -> QuerySet:
|
def get_documents(self) -> QuerySet:
|
||||||
""" Getter for all documents of a compensation
|
""" Getter for all documents of a compensation
|
||||||
@@ -326,7 +413,9 @@ class Compensation(AbstractCompensation, CEFMixin, CoherenceMixin):
|
|||||||
Returns:
|
Returns:
|
||||||
|
|
||||||
"""
|
"""
|
||||||
self.intervention.mark_as_edited(user, request, edit_comment, reset_recorded)
|
self.intervention.unrecord(user, request)
|
||||||
|
action = super().mark_as_edited(user, edit_comment=edit_comment)
|
||||||
|
return action
|
||||||
|
|
||||||
def is_ready_for_publish(self) -> bool:
|
def is_ready_for_publish(self) -> bool:
|
||||||
""" Not inherited by RecordableObjectMixin
|
""" Not inherited by RecordableObjectMixin
|
||||||
@@ -338,6 +427,38 @@ class Compensation(AbstractCompensation, CEFMixin, CoherenceMixin):
|
|||||||
"""
|
"""
|
||||||
return self.intervention.is_ready_for_publish()
|
return self.intervention.is_ready_for_publish()
|
||||||
|
|
||||||
|
def set_status_messages(self, request: HttpRequest):
|
||||||
|
""" Setter for different information that need to be rendered
|
||||||
|
|
||||||
|
Adds messages to the given HttpRequest
|
||||||
|
|
||||||
|
Args:
|
||||||
|
request (HttpRequest): The incoming request
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
request (HttpRequest): The modified request
|
||||||
|
"""
|
||||||
|
if self.intervention.legal.revocations.exists():
|
||||||
|
messages.error(
|
||||||
|
request,
|
||||||
|
INTERVENTION_HAS_REVOCATIONS_TEMPLATE.format(self.intervention.legal.revocations.count()),
|
||||||
|
extra_tags="danger",
|
||||||
|
)
|
||||||
|
super().set_status_messages(request)
|
||||||
|
return request
|
||||||
|
|
||||||
|
@property
|
||||||
|
def is_recorded(self):
|
||||||
|
""" Getter for record status as property
|
||||||
|
|
||||||
|
Since compensations inherit their record status from their intervention, the intervention's status is being
|
||||||
|
returned
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
|
||||||
|
"""
|
||||||
|
return self.intervention.is_recorded
|
||||||
|
|
||||||
|
|
||||||
class CompensationDocument(AbstractDocument):
|
class CompensationDocument(AbstractDocument):
|
||||||
"""
|
"""
|
||||||
@@ -353,7 +474,7 @@ class CompensationDocument(AbstractDocument):
|
|||||||
max_length=1000,
|
max_length=1000,
|
||||||
)
|
)
|
||||||
|
|
||||||
def delete(self, *args, **kwargs):
|
def delete(self, user=None, *args, **kwargs):
|
||||||
"""
|
"""
|
||||||
Custom delete functionality for CompensationDocuments.
|
Custom delete functionality for CompensationDocuments.
|
||||||
Removes the folder from the file system if there are no further documents for this entry.
|
Removes the folder from the file system if there are no further documents for this entry.
|
||||||
@@ -375,6 +496,9 @@ class CompensationDocument(AbstractDocument):
|
|||||||
folder_path = self.file.path.split("/")[:-1]
|
folder_path = self.file.path.split("/")[:-1]
|
||||||
folder_path = "/".join(folder_path)
|
folder_path = "/".join(folder_path)
|
||||||
|
|
||||||
|
if user:
|
||||||
|
self.instance.mark_as_edited(user, edit_comment=DOCUMENT_REMOVED_TEMPLATE.format(self.title))
|
||||||
|
|
||||||
# Remove the file itself
|
# Remove the file itself
|
||||||
super().delete(*args, **kwargs)
|
super().delete(*args, **kwargs)
|
||||||
|
|
||||||
|
|||||||
@@ -7,23 +7,24 @@ Created on: 16.11.21
|
|||||||
"""
|
"""
|
||||||
import shutil
|
import shutil
|
||||||
|
|
||||||
from user.models import User
|
from django.urls import reverse
|
||||||
|
|
||||||
|
from konova.utils.message_templates import DEDUCTION_REMOVED, DOCUMENT_REMOVED_TEMPLATE
|
||||||
from django.core.exceptions import ValidationError
|
from django.core.exceptions import ValidationError
|
||||||
from django.core.validators import MinValueValidator
|
from django.core.validators import MinValueValidator
|
||||||
from django.db import models, transaction
|
from django.db import models
|
||||||
from django.db.models import Sum, QuerySet
|
from django.db.models import Sum, QuerySet
|
||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
|
|
||||||
from compensation.managers import EcoAccountManager, EcoAccountDeductionManager
|
from compensation.managers import EcoAccountManager, EcoAccountDeductionManager
|
||||||
from compensation.models.compensation import AbstractCompensation
|
from compensation.models.compensation import AbstractCompensation, PikMixin
|
||||||
from compensation.utils.quality import EcoAccountQualityChecker
|
from compensation.utils.quality import EcoAccountQualityChecker
|
||||||
from konova.models import ShareableObjectMixin, RecordableObjectMixin, AbstractDocument, BaseResource, \
|
from konova.models import ShareableObjectMixin, RecordableObjectMixin, AbstractDocument, BaseResource, \
|
||||||
generate_document_file_upload_path
|
generate_document_file_upload_path
|
||||||
from konova.settings import DEFAULT_SRID_RLP, LANIS_LINK_TEMPLATE
|
from konova.tasks import celery_send_mail_deduction_changed, celery_send_mail_deduction_changed_team
|
||||||
from user.models import UserActionLogEntry
|
|
||||||
|
|
||||||
|
|
||||||
class EcoAccount(AbstractCompensation, ShareableObjectMixin, RecordableObjectMixin):
|
class EcoAccount(AbstractCompensation, ShareableObjectMixin, RecordableObjectMixin, PikMixin):
|
||||||
"""
|
"""
|
||||||
An eco account is a kind of 'prepaid' compensation. It can be compared to an account that already has been filled
|
An eco account is a kind of 'prepaid' compensation. It can be compared to an account that already has been filled
|
||||||
with some kind of currency. From this account one is able to deduct currency for current projects.
|
with some kind of currency. From this account one is able to deduct currency for current projects.
|
||||||
@@ -122,28 +123,6 @@ class EcoAccount(AbstractCompensation, ShareableObjectMixin, RecordableObjectMix
|
|||||||
|
|
||||||
return ret_val_total, ret_val_relative
|
return ret_val_total, ret_val_relative
|
||||||
|
|
||||||
def get_LANIS_link(self) -> str:
|
|
||||||
""" Generates a link for LANIS depending on the geometry
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
|
|
||||||
"""
|
|
||||||
try:
|
|
||||||
geom = self.geometry.geom.transform(DEFAULT_SRID_RLP, clone=True)
|
|
||||||
x = geom.centroid.x
|
|
||||||
y = geom.centroid.y
|
|
||||||
zoom_lvl = 16
|
|
||||||
except AttributeError:
|
|
||||||
# If no geometry has been added, yet.
|
|
||||||
x = 1
|
|
||||||
y = 1
|
|
||||||
zoom_lvl = 6
|
|
||||||
return LANIS_LINK_TEMPLATE.format(
|
|
||||||
zoom_lvl,
|
|
||||||
x,
|
|
||||||
y,
|
|
||||||
)
|
|
||||||
|
|
||||||
def quality_check(self) -> EcoAccountQualityChecker:
|
def quality_check(self) -> EcoAccountQualityChecker:
|
||||||
""" Quality check
|
""" Quality check
|
||||||
|
|
||||||
@@ -165,34 +144,6 @@ class EcoAccount(AbstractCompensation, ShareableObjectMixin, RecordableObjectMix
|
|||||||
)
|
)
|
||||||
return docs
|
return docs
|
||||||
|
|
||||||
def add_deduction(self, form):
|
|
||||||
""" Adds a new deduction to the intervention
|
|
||||||
|
|
||||||
Args:
|
|
||||||
form (NewDeductionModalForm): The form holding the data
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
|
|
||||||
"""
|
|
||||||
form_data = form.cleaned_data
|
|
||||||
user = form.user
|
|
||||||
|
|
||||||
with transaction.atomic():
|
|
||||||
# Create log entry
|
|
||||||
user_action_create = UserActionLogEntry.get_created_action(user)
|
|
||||||
user_action_edit = UserActionLogEntry.get_edited_action(user)
|
|
||||||
self.log.add(user_action_edit)
|
|
||||||
self.modified = user_action_edit
|
|
||||||
self.save()
|
|
||||||
|
|
||||||
deduction = EcoAccountDeduction.objects.create(
|
|
||||||
intervention=form_data["intervention"],
|
|
||||||
account=self,
|
|
||||||
surface=form_data["surface"],
|
|
||||||
created=user_action_create,
|
|
||||||
)
|
|
||||||
return deduction
|
|
||||||
|
|
||||||
def is_ready_for_publish(self) -> bool:
|
def is_ready_for_publish(self) -> bool:
|
||||||
""" Checks whether the data passes all constraints for being publishable
|
""" Checks whether the data passes all constraints for being publishable
|
||||||
|
|
||||||
@@ -203,6 +154,33 @@ class EcoAccount(AbstractCompensation, ShareableObjectMixin, RecordableObjectMix
|
|||||||
is_ready = is_recorded
|
is_ready = is_recorded
|
||||||
return is_ready
|
return is_ready
|
||||||
|
|
||||||
|
def get_share_link(self):
|
||||||
|
""" Returns the share url for the object
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
|
||||||
|
"""
|
||||||
|
return reverse("compensation:acc:share", args=(self.id, self.access_token))
|
||||||
|
|
||||||
|
def send_notification_mail_on_deduction_change(self, data_change: dict):
|
||||||
|
""" Sends notification mails for changes on the deduction
|
||||||
|
|
||||||
|
Args:
|
||||||
|
data_change ():
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
|
||||||
|
"""
|
||||||
|
# Send mail
|
||||||
|
shared_users = self.shared_users.values_list("id", flat=True)
|
||||||
|
for user_id in shared_users:
|
||||||
|
celery_send_mail_deduction_changed.delay(self.identifier, self.title, user_id, data_change)
|
||||||
|
|
||||||
|
# Send mail
|
||||||
|
shared_teams = self.shared_teams.values_list("id", flat=True)
|
||||||
|
for team_id in shared_teams:
|
||||||
|
celery_send_mail_deduction_changed_team.delay(self.identifier, self.title, team_id, data_change)
|
||||||
|
|
||||||
|
|
||||||
class EcoAccountDocument(AbstractDocument):
|
class EcoAccountDocument(AbstractDocument):
|
||||||
"""
|
"""
|
||||||
@@ -218,7 +196,7 @@ class EcoAccountDocument(AbstractDocument):
|
|||||||
max_length=1000,
|
max_length=1000,
|
||||||
)
|
)
|
||||||
|
|
||||||
def delete(self, *args, **kwargs):
|
def delete(self, user=None, *args, **kwargs):
|
||||||
"""
|
"""
|
||||||
Custom delete functionality for EcoAccountDocuments.
|
Custom delete functionality for EcoAccountDocuments.
|
||||||
Removes the folder from the file system if there are no further documents for this entry.
|
Removes the folder from the file system if there are no further documents for this entry.
|
||||||
@@ -240,6 +218,9 @@ class EcoAccountDocument(AbstractDocument):
|
|||||||
folder_path = self.file.path.split("/")[:-1]
|
folder_path = self.file.path.split("/")[:-1]
|
||||||
folder_path = "/".join(folder_path)
|
folder_path = "/".join(folder_path)
|
||||||
|
|
||||||
|
if user:
|
||||||
|
self.instance.mark_as_edited(user, edit_comment=DOCUMENT_REMOVED_TEMPLATE.format(self.title))
|
||||||
|
|
||||||
# Remove the file itself
|
# Remove the file itself
|
||||||
super().delete(*args, **kwargs)
|
super().delete(*args, **kwargs)
|
||||||
|
|
||||||
@@ -285,3 +266,9 @@ class EcoAccountDeduction(BaseResource):
|
|||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return "{} of {}".format(self.surface, self.account)
|
return "{} of {}".format(self.surface, self.account)
|
||||||
|
|
||||||
|
def delete(self, user=None, *args, **kwargs):
|
||||||
|
if user is not None:
|
||||||
|
self.intervention.mark_as_edited(user, edit_comment=DEDUCTION_REMOVED)
|
||||||
|
self.account.mark_as_edited(user, edit_comment=DEDUCTION_REMOVED)
|
||||||
|
super().delete(*args, **kwargs)
|
||||||
|
|||||||
@@ -10,6 +10,8 @@ from django.db import models
|
|||||||
|
|
||||||
from intervention.models import Intervention
|
from intervention.models import Intervention
|
||||||
from konova.models import BaseResource
|
from konova.models import BaseResource
|
||||||
|
from konova.utils.message_templates import PAYMENT_REMOVED
|
||||||
|
from user.models import UserActionLogEntry
|
||||||
|
|
||||||
|
|
||||||
class Payment(BaseResource):
|
class Payment(BaseResource):
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ Created on: 16.11.21
|
|||||||
|
|
||||||
"""
|
"""
|
||||||
from django.db import models
|
from django.db import models
|
||||||
|
from django.db.models import Q
|
||||||
|
|
||||||
from codelist.models import KonovaCode
|
from codelist.models import KonovaCode
|
||||||
from codelist.settings import CODELIST_BIOTOPES_ID, CODELIST_BIOTOPES_EXTRA_CODES_ID
|
from codelist.settings import CODELIST_BIOTOPES_ID, CODELIST_BIOTOPES_EXTRA_CODES_ID
|
||||||
|
|||||||
@@ -5,17 +5,15 @@ Contact: michel.peltriaux@sgdnord.rlp.de
|
|||||||
Created on: 01.12.20
|
Created on: 01.12.20
|
||||||
|
|
||||||
"""
|
"""
|
||||||
from user.models import User
|
from konova.utils.message_templates import DATA_IS_UNCHECKED, DATA_CHECKED_ON_TEMPLATE, DATA_CHECKED_PREVIOUSLY_TEMPLATE
|
||||||
from django.http import HttpRequest
|
from django.http import HttpRequest
|
||||||
from django.template.loader import render_to_string
|
from django.template.loader import render_to_string
|
||||||
from django.urls import reverse
|
from django.urls import reverse
|
||||||
from django.utils.html import format_html
|
from django.utils.html import format_html
|
||||||
from django.utils.timezone import localtime
|
|
||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
|
|
||||||
from compensation.filters import CompensationTableFilter, EcoAccountTableFilter
|
from compensation.filters import CompensationTableFilter, EcoAccountTableFilter
|
||||||
from compensation.models import Compensation, EcoAccount
|
from compensation.models import Compensation, EcoAccount
|
||||||
from konova.sub_settings.django_settings import DEFAULT_DATE_TIME_FORMAT
|
|
||||||
from konova.utils.tables import BaseTable, TableRenderMixin
|
from konova.utils.tables import BaseTable, TableRenderMixin
|
||||||
import django_tables2 as tables
|
import django_tables2 as tables
|
||||||
|
|
||||||
@@ -31,6 +29,11 @@ class CompensationTable(BaseTable, TableRenderMixin):
|
|||||||
orderable=True,
|
orderable=True,
|
||||||
accessor="title",
|
accessor="title",
|
||||||
)
|
)
|
||||||
|
d = tables.Column(
|
||||||
|
verbose_name=_("Parcel gmrkng"),
|
||||||
|
orderable=True,
|
||||||
|
accessor="geometry",
|
||||||
|
)
|
||||||
c = tables.Column(
|
c = tables.Column(
|
||||||
verbose_name=_("Checked"),
|
verbose_name=_("Checked"),
|
||||||
orderable=True,
|
orderable=True,
|
||||||
@@ -80,14 +83,17 @@ class CompensationTable(BaseTable, TableRenderMixin):
|
|||||||
Returns:
|
Returns:
|
||||||
|
|
||||||
"""
|
"""
|
||||||
html = ""
|
context = {
|
||||||
html += self.render_link(
|
"tooltip": _("Open {}").format(_("Intervention")),
|
||||||
tooltip=_("Open {}").format(_("Compensation")),
|
"content": value,
|
||||||
href=reverse("compensation:detail", args=(record.id,)),
|
"url": reverse("compensation:detail", args=(record.id,)),
|
||||||
txt=value,
|
"has_revocations": record.intervention.legal.revocations.exists()
|
||||||
new_tab=False,
|
}
|
||||||
|
html = render_to_string(
|
||||||
|
"table/revocation_warning_col.html",
|
||||||
|
context
|
||||||
)
|
)
|
||||||
return format_html(html)
|
return html
|
||||||
|
|
||||||
def render_c(self, value, record: Compensation):
|
def render_c(self, value, record: Compensation):
|
||||||
""" Renders the checked column for a compensation
|
""" Renders the checked column for a compensation
|
||||||
@@ -103,18 +109,45 @@ class CompensationTable(BaseTable, TableRenderMixin):
|
|||||||
"""
|
"""
|
||||||
html = ""
|
html = ""
|
||||||
checked = value is not None
|
checked = value is not None
|
||||||
tooltip = _("Not checked yet")
|
tooltip = DATA_IS_UNCHECKED
|
||||||
|
previously_checked = record.intervention.get_last_checked_action()
|
||||||
if checked:
|
if checked:
|
||||||
value = value.timestamp
|
checked_on = value.get_timestamp_str_formatted()
|
||||||
value = localtime(value)
|
tooltip = DATA_CHECKED_ON_TEMPLATE.format(checked_on, record.intervention.checked.user)
|
||||||
checked_on = value.strftime(DEFAULT_DATE_TIME_FORMAT)
|
|
||||||
tooltip = _("Checked on {} by {}").format(checked_on, record.intervention.checked.user)
|
|
||||||
html += self.render_checked_star(
|
html += self.render_checked_star(
|
||||||
tooltip=tooltip,
|
tooltip=tooltip,
|
||||||
icn_filled=checked,
|
icn_filled=checked,
|
||||||
)
|
)
|
||||||
|
if previously_checked and not checked:
|
||||||
|
checked_on = previously_checked.get_timestamp_str_formatted()
|
||||||
|
tooltip = DATA_CHECKED_PREVIOUSLY_TEMPLATE.format(checked_on, previously_checked.user)
|
||||||
|
html += self.render_previously_checked_star(
|
||||||
|
tooltip=tooltip,
|
||||||
|
)
|
||||||
return format_html(html)
|
return format_html(html)
|
||||||
|
|
||||||
|
def render_d(self, value, record: Compensation):
|
||||||
|
""" Renders the parcel district column for a compensation
|
||||||
|
|
||||||
|
Args:
|
||||||
|
value (str): The geometry
|
||||||
|
record (Compensation): The compensation record
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
|
||||||
|
"""
|
||||||
|
parcels = value.get_underlying_parcels().values_list(
|
||||||
|
"parcel_group__name",
|
||||||
|
flat=True
|
||||||
|
).distinct()
|
||||||
|
html = render_to_string(
|
||||||
|
"table/gmrkng_col.html",
|
||||||
|
{
|
||||||
|
"entries": parcels
|
||||||
|
}
|
||||||
|
)
|
||||||
|
return html
|
||||||
|
|
||||||
def render_r(self, value, record: Compensation):
|
def render_r(self, value, record: Compensation):
|
||||||
""" Renders the registered column for a compensation
|
""" Renders the registered column for a compensation
|
||||||
|
|
||||||
@@ -129,9 +162,7 @@ class CompensationTable(BaseTable, TableRenderMixin):
|
|||||||
recorded = value is not None
|
recorded = value is not None
|
||||||
tooltip = _("Not recorded yet")
|
tooltip = _("Not recorded yet")
|
||||||
if recorded:
|
if recorded:
|
||||||
value = value.timestamp
|
on = value.get_timestamp_str_formatted()
|
||||||
value = localtime(value)
|
|
||||||
on = value.strftime(DEFAULT_DATE_TIME_FORMAT)
|
|
||||||
tooltip = _("Recorded on {} by {}").format(on, record.intervention.recorded.user)
|
tooltip = _("Recorded on {} by {}").format(on, record.intervention.recorded.user)
|
||||||
html += self.render_bookmark(
|
html += self.render_bookmark(
|
||||||
tooltip=tooltip,
|
tooltip=tooltip,
|
||||||
@@ -149,11 +180,7 @@ class CompensationTable(BaseTable, TableRenderMixin):
|
|||||||
Returns:
|
Returns:
|
||||||
|
|
||||||
"""
|
"""
|
||||||
if value is None:
|
has_access = record.is_shared_with(self.user)
|
||||||
value = User.objects.none()
|
|
||||||
has_access = value.filter(
|
|
||||||
id=self.user.id
|
|
||||||
).exists()
|
|
||||||
|
|
||||||
html = self.render_icn(
|
html = self.render_icn(
|
||||||
tooltip=_("Full access granted") if has_access else _("Access not granted"),
|
tooltip=_("Full access granted") if has_access else _("Access not granted"),
|
||||||
@@ -173,10 +200,20 @@ class EcoAccountTable(BaseTable, TableRenderMixin):
|
|||||||
orderable=True,
|
orderable=True,
|
||||||
accessor="title",
|
accessor="title",
|
||||||
)
|
)
|
||||||
|
d = tables.Column(
|
||||||
|
verbose_name=_("Parcel gmrkng"),
|
||||||
|
orderable=True,
|
||||||
|
accessor="geometry",
|
||||||
|
)
|
||||||
av = tables.Column(
|
av = tables.Column(
|
||||||
verbose_name=_("Available"),
|
verbose_name=_("Available"),
|
||||||
orderable=True,
|
orderable=True,
|
||||||
empty_values=[],
|
empty_values=[],
|
||||||
|
attrs={
|
||||||
|
"th": {
|
||||||
|
"class": "w-20",
|
||||||
|
}
|
||||||
|
}
|
||||||
)
|
)
|
||||||
r = tables.Column(
|
r = tables.Column(
|
||||||
verbose_name=_("Recorded"),
|
verbose_name=_("Recorded"),
|
||||||
@@ -201,7 +238,7 @@ class EcoAccountTable(BaseTable, TableRenderMixin):
|
|||||||
|
|
||||||
def __init__(self, request: HttpRequest, *args, **kwargs):
|
def __init__(self, request: HttpRequest, *args, **kwargs):
|
||||||
self.title = _("Eco Accounts")
|
self.title = _("Eco Accounts")
|
||||||
self.add_new_url = reverse("compensation:acc-new")
|
self.add_new_url = reverse("compensation:acc:new")
|
||||||
qs = kwargs.get("queryset", None)
|
qs = kwargs.get("queryset", None)
|
||||||
self.filter = EcoAccountTableFilter(
|
self.filter = EcoAccountTableFilter(
|
||||||
user=request.user,
|
user=request.user,
|
||||||
@@ -224,7 +261,7 @@ class EcoAccountTable(BaseTable, TableRenderMixin):
|
|||||||
html = ""
|
html = ""
|
||||||
html += self.render_link(
|
html += self.render_link(
|
||||||
tooltip=_("Open {}").format(_("Eco-account")),
|
tooltip=_("Open {}").format(_("Eco-account")),
|
||||||
href=reverse("compensation:acc-detail", args=(record.id,)),
|
href=reverse("compensation:acc:detail", args=(record.id,)),
|
||||||
txt=value,
|
txt=value,
|
||||||
new_tab=False,
|
new_tab=False,
|
||||||
)
|
)
|
||||||
@@ -244,6 +281,28 @@ class EcoAccountTable(BaseTable, TableRenderMixin):
|
|||||||
html = render_to_string("konova/widgets/progressbar.html", {"value": value_relative})
|
html = render_to_string("konova/widgets/progressbar.html", {"value": value_relative})
|
||||||
return format_html(html)
|
return format_html(html)
|
||||||
|
|
||||||
|
def render_d(self, value, record: Compensation):
|
||||||
|
""" Renders the parcel district column for a compensation
|
||||||
|
|
||||||
|
Args:
|
||||||
|
value (str): The geometry
|
||||||
|
record (Compensation): The compensation record
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
|
||||||
|
"""
|
||||||
|
parcels = value.get_underlying_parcels().values_list(
|
||||||
|
"parcel_group__name",
|
||||||
|
flat=True
|
||||||
|
).distinct()
|
||||||
|
html = render_to_string(
|
||||||
|
"table/gmrkng_col.html",
|
||||||
|
{
|
||||||
|
"entries": parcels
|
||||||
|
}
|
||||||
|
)
|
||||||
|
return html
|
||||||
|
|
||||||
def render_r(self, value, record: EcoAccount):
|
def render_r(self, value, record: EcoAccount):
|
||||||
""" Renders the recorded column for an eco account
|
""" Renders the recorded column for an eco account
|
||||||
|
|
||||||
@@ -258,9 +317,7 @@ class EcoAccountTable(BaseTable, TableRenderMixin):
|
|||||||
checked = value is not None
|
checked = value is not None
|
||||||
tooltip = _("Not recorded yet. Can not be used for deductions, yet.")
|
tooltip = _("Not recorded yet. Can not be used for deductions, yet.")
|
||||||
if checked:
|
if checked:
|
||||||
value = value.timestamp
|
on = value.get_timestamp_str_formatted()
|
||||||
value = localtime(value)
|
|
||||||
on = value.strftime(DEFAULT_DATE_TIME_FORMAT)
|
|
||||||
tooltip = _("Recorded on {} by {}").format(on, record.recorded.user)
|
tooltip = _("Recorded on {} by {}").format(on, record.recorded.user)
|
||||||
html += self.render_bookmark(
|
html += self.render_bookmark(
|
||||||
tooltip=tooltip,
|
tooltip=tooltip,
|
||||||
@@ -281,7 +338,7 @@ class EcoAccountTable(BaseTable, TableRenderMixin):
|
|||||||
html = ""
|
html = ""
|
||||||
# Do not use value in here, since value does use unprefetched 'users' manager, where record has already
|
# Do not use value in here, since value does use unprefetched 'users' manager, where record has already
|
||||||
# prefetched users data
|
# prefetched users data
|
||||||
has_access = self.user in record.users.all()
|
has_access = record.is_shared_with(self.user)
|
||||||
html += self.render_icn(
|
html += self.render_icn(
|
||||||
tooltip=_("Full access granted") if has_access else _("Access not granted"),
|
tooltip=_("Full access granted") if has_access else _("Access not granted"),
|
||||||
icn_class="fas fa-edit rlp-r-inv" if has_access else "far fa-edit",
|
icn_class="fas fa-edit rlp-r-inv" if has_access else "far fa-edit",
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
{% load i18n l10n fontawesome_5 humanize %}
|
{% load i18n l10n fontawesome_5 humanize ksp_filters %}
|
||||||
|
|
||||||
<div id="actions" class="card">
|
<div id="actions" class="card">
|
||||||
<div class="card-header rlp-r">
|
<div class="card-header rlp-r">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
@@ -20,16 +21,13 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="card-body scroll-300">
|
<div class="card-body scroll-300 p-2">
|
||||||
<table class="table table-hover">
|
<table class="table table-hover">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th class="w-25" scope="col">
|
<th class="" scope="col">
|
||||||
{% trans 'Action type' %}
|
{% trans 'Action type' %}
|
||||||
</th>
|
</th>
|
||||||
<th class="w-25" scope="col">
|
|
||||||
{% trans 'Action type details' %}
|
|
||||||
</th>
|
|
||||||
<th scope="col">
|
<th scope="col">
|
||||||
{% trans 'Amount' context 'Compensation' %}
|
{% trans 'Amount' context 'Compensation' %}
|
||||||
</th>
|
</th>
|
||||||
@@ -37,8 +35,10 @@
|
|||||||
{% trans 'Comment' %}
|
{% trans 'Comment' %}
|
||||||
</th>
|
</th>
|
||||||
{% if is_default_member and has_access %}
|
{% if is_default_member and has_access %}
|
||||||
<th scope="col">
|
<th class="w-10" scope="col">
|
||||||
{% trans 'Action' %}
|
<span class="float-right">
|
||||||
|
{% trans 'Action' %}
|
||||||
|
</span>
|
||||||
</th>
|
</th>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</tr>
|
</tr>
|
||||||
@@ -46,18 +46,28 @@
|
|||||||
<tbody>
|
<tbody>
|
||||||
{% for action in actions %}
|
{% for action in actions %}
|
||||||
<tr>
|
<tr>
|
||||||
<td class="align-middle">
|
<td class="">
|
||||||
{{ action.action_type }}
|
{% for type in action.action_type.all %}
|
||||||
</td>
|
<div> {{type.parent.parent.long_name}} {% fa5_icon 'angle-right' %} {{type.parent.long_name}} {% fa5_icon 'angle-right' %} {{type.long_name}} </div>
|
||||||
<td class="align-middle">
|
<hr>
|
||||||
|
{% endfor %}
|
||||||
{% for detail in action.action_type_details.all %}
|
{% for detail in action.action_type_details.all %}
|
||||||
<div class="mb-2" title="{{detail}}">{{detail.long_name}}</div>
|
<span class="badge badge-pill rlp-r" title="{{detail}}">{{detail.long_name}}</span>
|
||||||
|
{% empty %}
|
||||||
|
<span class="badge badge-pill rlp-r-outline" title="{% trans 'No action type details' %}">{% trans 'No action type details' %}</span>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</td>
|
</td>
|
||||||
<td class="align-middle">{{ action.amount|floatformat:2|intcomma }} {{ action.unit_humanize }}</td>
|
<td class="">{{ action.amount|floatformat:2|intcomma }} {{ action.unit_humanize }}</td>
|
||||||
<td class="align-middle">{{ action.comment|default_if_none:"" }}</td>
|
<td class="">
|
||||||
<td class="align-middle">
|
<div class="scroll-150">
|
||||||
|
{{ action.comment }}
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td class="align-middle float-right">
|
||||||
{% if is_default_member and has_access %}
|
{% if is_default_member and has_access %}
|
||||||
|
<button data-form-url="{% url 'compensation:action-edit' obj.id action.id %}" class="btn btn-default btn-modal" title="{% trans 'Edit action' %}">
|
||||||
|
{% fa5_icon 'edit' %}
|
||||||
|
</button>
|
||||||
<button data-form-url="{% url 'compensation:action-remove' obj.id action.id %}" class="btn btn-default btn-modal" title="{% trans 'Remove action' %}">
|
<button data-form-url="{% url 'compensation:action-remove' obj.id action.id %}" class="btn btn-default btn-modal" title="{% trans 'Remove action' %}">
|
||||||
{% fa5_icon 'trash' %}
|
{% fa5_icon 'trash' %}
|
||||||
</button>
|
</button>
|
||||||
|
|||||||
@@ -12,6 +12,9 @@
|
|||||||
</button>
|
</button>
|
||||||
</a>
|
</a>
|
||||||
{% if has_access %}
|
{% if has_access %}
|
||||||
|
<button class="btn btn-default btn-modal mr-2" title="{% trans 'Resubmission' %}" data-form-url="{% url 'compensation:resubmission-create' obj.id %}">
|
||||||
|
{% fa5_icon 'bell' %}
|
||||||
|
</button>
|
||||||
{% if is_default_member %}
|
{% if is_default_member %}
|
||||||
<a href="{% url 'compensation:edit' obj.id %}" class="mr-2">
|
<a href="{% url 'compensation:edit' obj.id %}" class="mr-2">
|
||||||
<button class="btn btn-default" title="{% trans 'Edit' %}">
|
<button class="btn btn-default" title="{% trans 'Edit' %}">
|
||||||
|
|||||||
@@ -20,7 +20,12 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="card-body scroll-300">
|
{% if not has_finished_deadlines %}
|
||||||
|
<div class="alert alert-danger mb-0">
|
||||||
|
{% trans 'Missing finished deadline ' %}
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
|
<div class="card-body scroll-300 p-2">
|
||||||
<table class="table table-hover">
|
<table class="table table-hover">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
@@ -34,8 +39,10 @@
|
|||||||
{% trans 'Comment' %}
|
{% trans 'Comment' %}
|
||||||
</th>
|
</th>
|
||||||
{% if is_default_member and has_access %}
|
{% if is_default_member and has_access %}
|
||||||
<th scope="col">
|
<th class="w-10" scope="col">
|
||||||
{% trans 'Action' %}
|
<span class="float-right">
|
||||||
|
{% trans 'Action' %}
|
||||||
|
</span>
|
||||||
</th>
|
</th>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</tr>
|
</tr>
|
||||||
@@ -47,10 +54,17 @@
|
|||||||
{% trans deadline.type_humanized %}
|
{% trans deadline.type_humanized %}
|
||||||
</td>
|
</td>
|
||||||
<td class="align-middle">{{ deadline.date|default_if_none:"---" }}</td>
|
<td class="align-middle">{{ deadline.date|default_if_none:"---" }}</td>
|
||||||
<td class="align-middle">{{ deadline.comment }}</td>
|
<td class="align-middle">
|
||||||
<td>
|
<div class="scroll-150">
|
||||||
|
{{ deadline.comment }}
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td class="align-middle float-right">
|
||||||
{% if is_default_member and has_access %}
|
{% if is_default_member and has_access %}
|
||||||
<button data-form-url="{% url 'deadline-remove' deadline.id %}" class="btn btn-default btn-modal" title="{% trans 'Remove deadline' %}">
|
<button data-form-url="{% url 'compensation:deadline-edit' obj.id deadline.id %}" class="btn btn-default btn-modal" title="{% trans 'Edit deadline' %}">
|
||||||
|
{% fa5_icon 'edit' %}
|
||||||
|
</button>
|
||||||
|
<button data-form-url="{% url 'compensation:deadline-remove' obj.id deadline.id %}" class="btn btn-default btn-modal" title="{% trans 'Remove deadline' %}">
|
||||||
{% fa5_icon 'trash' %}
|
{% fa5_icon 'trash' %}
|
||||||
</button>
|
</button>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|||||||
@@ -20,19 +20,24 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="card-body scroll-300">
|
<div class="card-body scroll-300 p-2">
|
||||||
<table class="table table-hover">
|
<table class="table table-hover">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th scope="col">
|
<th scope="col">
|
||||||
{% trans 'Title' %}
|
{% trans 'Title' %}
|
||||||
</th>
|
</th>
|
||||||
|
<th scope="col">
|
||||||
|
{% trans 'Created on' %}
|
||||||
|
</th>
|
||||||
<th scope="col">
|
<th scope="col">
|
||||||
{% trans 'Comment' %}
|
{% trans 'Comment' %}
|
||||||
</th>
|
</th>
|
||||||
{% if is_default_member and has_access %}
|
{% if is_default_member and has_access %}
|
||||||
<th scope="col">
|
<th class="w-10" scope="col">
|
||||||
{% trans 'Action' %}
|
<span class="float-right">
|
||||||
|
{% trans 'Action' %}
|
||||||
|
</span>
|
||||||
</th>
|
</th>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</tr>
|
</tr>
|
||||||
@@ -41,14 +46,24 @@
|
|||||||
{% for doc in obj.documents.all %}
|
{% for doc in obj.documents.all %}
|
||||||
<tr>
|
<tr>
|
||||||
<td class="align-middle">
|
<td class="align-middle">
|
||||||
<a href="{% url 'compensation:get-doc' doc.id %}">
|
<a href="{% url 'compensation:get-doc' obj.id doc.id %}">
|
||||||
{{ doc.title }}
|
{{ doc.title }}
|
||||||
</a>
|
</a>
|
||||||
</td>
|
</td>
|
||||||
<td class="align-middle">{{ doc.comment }}</td>
|
<td class="align-middle">
|
||||||
<td>
|
{{ doc.date_of_creation }}
|
||||||
|
</td>
|
||||||
|
<td class="align-middle">
|
||||||
|
<div class="scroll-150">
|
||||||
|
{{ doc.comment }}
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td class="align-middle float-right">
|
||||||
{% if is_default_member and has_access %}
|
{% if is_default_member and has_access %}
|
||||||
<button data-form-url="{% url 'compensation:remove-doc' doc.id %}" class="btn btn-default btn-modal" title="{% trans 'Remove document' %}">
|
<button data-form-url="{% url 'compensation:edit-doc' obj.id doc.id %}" class="btn btn-default btn-modal" title="{% trans 'Edit document' %}">
|
||||||
|
{% fa5_icon 'edit' %}
|
||||||
|
</button>
|
||||||
|
<button data-form-url="{% url 'compensation:remove-doc' obj.id doc.id %}" class="btn btn-default btn-modal" title="{% trans 'Remove document' %}">
|
||||||
{% fa5_icon 'trash' %}
|
{% fa5_icon 'trash' %}
|
||||||
</button>
|
</button>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|||||||
@@ -20,27 +20,26 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="card-body scroll-300">
|
{% if sum_before_states > sum_after_states %}
|
||||||
{% if sum_before_states > sum_after_states %}
|
<div class="alert alert-danger mb-0">
|
||||||
<div class="row alert alert-danger">
|
{% trans 'Missing surfaces according to states before: ' %}{{ diff_states|floatformat:2 }} m²
|
||||||
{% trans 'Missing surfaces according to states before: ' %}{{ diff_states|floatformat:2 }} m²
|
</div>
|
||||||
</div>
|
{% endif %}
|
||||||
{% endif %}
|
<div class="card-body scroll-300 p-2">
|
||||||
<table class="table table-hover">
|
<table class="table table-hover">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th class="w-25" scope="col">
|
<th class="w-50" scope="col">
|
||||||
{% trans 'Biotope type' %}
|
{% trans 'Biotope type' %}
|
||||||
</th>
|
</th>
|
||||||
<th class="w-25" scope="col">
|
|
||||||
{% trans 'Biotope additional type' %}
|
|
||||||
</th>
|
|
||||||
<th scope="col">
|
<th scope="col">
|
||||||
{% trans 'Surface' %}
|
{% trans 'Surface' %}
|
||||||
</th>
|
</th>
|
||||||
{% if is_default_member and has_access %}
|
{% if is_default_member and has_access %}
|
||||||
<th scope="col">
|
<th class="w-10" scope="col">
|
||||||
{% trans 'Action' %}
|
<span class="float-right">
|
||||||
|
{% trans 'Action' %}
|
||||||
|
</span>
|
||||||
</th>
|
</th>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</tr>
|
</tr>
|
||||||
@@ -48,19 +47,21 @@
|
|||||||
<tbody>
|
<tbody>
|
||||||
{% for state in after_states %}
|
{% for state in after_states %}
|
||||||
<tr>
|
<tr>
|
||||||
<td class="align-middle">
|
<td>
|
||||||
{{ state.biotope_type }}
|
<span>{{ state.biotope_type.parent.long_name }} {% fa5_icon 'angle-right' %} {{ state.biotope_type.long_name }} ({{state.biotope_type.short_name}})</span>
|
||||||
</td>
|
<br>
|
||||||
<td class="align-middle">
|
{% for detail in state.biotope_type_details.all %}
|
||||||
{% for biotope_extra in state.biotope_type_details.all %}
|
<span class="badge badge-pill rlp-r" title="{{detail}}">{{detail.long_name}}</span>
|
||||||
<div class="mb-2" title="{{ biotope_extra }}">
|
{% empty %}
|
||||||
{{ biotope_extra.long_name }}
|
<span class="badge badge-pill rlp-r-outline" title="{% trans 'No biotope type details' %}">{% trans 'No biotope type details' %}</span>
|
||||||
</div>
|
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</td>
|
</td>
|
||||||
<td class="align-middle">{{ state.surface|floatformat:2 }} m²</td>
|
<td>{{ state.surface|floatformat:2 }} m²</td>
|
||||||
<td class="align-middle">
|
<td class="align-middle float-right">
|
||||||
{% if is_default_member and has_access %}
|
{% if is_default_member and has_access %}
|
||||||
|
<button data-form-url="{% url 'compensation:state-edit' obj.id state.id %}" class="btn btn-default btn-modal" title="{% trans 'Edit state' %}">
|
||||||
|
{% fa5_icon 'edit' %}
|
||||||
|
</button>
|
||||||
<button data-form-url="{% url 'compensation:state-remove' obj.id state.id %}" class="btn btn-default btn-modal" title="{% trans 'Remove state' %}">
|
<button data-form-url="{% url 'compensation:state-remove' obj.id state.id %}" class="btn btn-default btn-modal" title="{% trans 'Remove state' %}">
|
||||||
{% fa5_icon 'trash' %}
|
{% fa5_icon 'trash' %}
|
||||||
</button>
|
</button>
|
||||||
|
|||||||
@@ -20,27 +20,26 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="card-body scroll-300">
|
{% if sum_before_states < sum_after_states %}
|
||||||
{% if sum_before_states < sum_after_states %}
|
<div class="alert alert-danger mb-0">
|
||||||
<div class="row alert alert-danger">
|
{% trans 'Missing surfaces according to states after: ' %}{{ diff_states|floatformat:2 }} m²
|
||||||
{% trans 'Missing surfaces according to states after: ' %}{{ diff_states|floatformat:2 }} m²
|
</div>
|
||||||
</div>
|
{% endif %}
|
||||||
{% endif %}
|
<div class="card-body scroll-300 p-2">
|
||||||
<table class="table table-hover">
|
<table class="table table-hover">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th class="w-25" scope="col">
|
<th class="w-50" scope="col">
|
||||||
{% trans 'Biotope type' %}
|
{% trans 'Biotope type' %}
|
||||||
</th>
|
</th>
|
||||||
<th class="w-25" scope="col">
|
|
||||||
{% trans 'Biotope additional type' %}
|
|
||||||
</th>
|
|
||||||
<th scope="col">
|
<th scope="col">
|
||||||
{% trans 'Surface' %}
|
{% trans 'Surface' %}
|
||||||
</th>
|
</th>
|
||||||
{% if is_default_member and has_access %}
|
{% if is_default_member and has_access %}
|
||||||
<th scope="col">
|
<th class="w-10" scope="col">
|
||||||
{% trans 'Action' %}
|
<span class="float-right">
|
||||||
|
{% trans 'Action' %}
|
||||||
|
</span>
|
||||||
</th>
|
</th>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</tr>
|
</tr>
|
||||||
@@ -48,19 +47,21 @@
|
|||||||
<tbody>
|
<tbody>
|
||||||
{% for state in before_states %}
|
{% for state in before_states %}
|
||||||
<tr>
|
<tr>
|
||||||
<td class="align-middle">
|
<td>
|
||||||
{{ state.biotope_type }}
|
<span>{{ state.biotope_type.parent.long_name }} {% fa5_icon 'angle-right' %} {{ state.biotope_type.long_name }} ({{state.biotope_type.short_name}})</span>
|
||||||
</td>
|
<br>
|
||||||
<td class="align-middle">
|
{% for detail in state.biotope_type_details.all %}
|
||||||
{% for biotope_extra in state.biotope_type_details.all %}
|
<span class="badge badge-pill rlp-r" title="{{detail}}">{{detail.long_name}}</span>
|
||||||
<div class="mb-2" title="{{ biotope_extra }}">
|
{% empty %}
|
||||||
{{ biotope_extra.long_name }}
|
<span class="badge badge-pill rlp-r-outline" title="{% trans 'No biotope type details' %}">{% trans 'No biotope type details' %}</span>
|
||||||
</div>
|
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</td>
|
</td>
|
||||||
<td class="align-middle">{{ state.surface|floatformat:2 }} m²</td>
|
<td>{{ state.surface|floatformat:2 }} m²</td>
|
||||||
<td class="align-middle">
|
<td class="align-middle float-right">
|
||||||
{% if is_default_member and has_access %}
|
{% if is_default_member and has_access %}
|
||||||
|
<button data-form-url="{% url 'compensation:state-edit' obj.id state.id %}" class="btn btn-default btn-modal" title="{% trans 'Edit state' %}">
|
||||||
|
{% fa5_icon 'edit' %}
|
||||||
|
</button>
|
||||||
<button data-form-url="{% url 'compensation:state-remove' obj.id state.id %}" class="btn btn-default btn-modal" title="{% trans 'Remove state' %}">
|
<button data-form-url="{% url 'compensation:state-remove' obj.id state.id %}" class="btn btn-default btn-modal" title="{% trans 'Remove state' %}">
|
||||||
{% fa5_icon 'trash' %}
|
{% fa5_icon 'trash' %}
|
||||||
</button>
|
</button>
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
{% load i18n l10n static fontawesome_5 humanize ksp_filters %}
|
{% load i18n l10n static fontawesome_5 humanize ksp_filters %}
|
||||||
|
|
||||||
{% block head %}
|
{% block head %}
|
||||||
|
|
||||||
{% comment %}
|
{% comment %}
|
||||||
dal documentation (django-autocomplete-light) states using form.media for adding needed scripts.
|
dal documentation (django-autocomplete-light) states using form.media for adding needed scripts.
|
||||||
This does not work properly with modal forms, as the scripts are not loaded properly inside the modal.
|
This does not work properly with modal forms, as the scripts are not loaded properly inside the modal.
|
||||||
@@ -14,16 +15,16 @@
|
|||||||
{% block body %}
|
{% block body %}
|
||||||
|
|
||||||
<div id="detail-header" class="row">
|
<div id="detail-header" class="row">
|
||||||
<div class="col-sm-12 col-md-12 col-lg-6">
|
<div class="col-sm-12 col-md-12 col-lg-12 col-xl-6">
|
||||||
<h3>{% trans 'Compensation' %}<br> {{obj.identifier}}</h3>
|
<h3>{% trans 'Compensation' %}<br> {{obj.identifier}}</h3>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-sm-12 col-md-12 col-lg-6">
|
<div class="col-sm-12 col-md-12 col-lg-12 col-xl-6">
|
||||||
{% include 'compensation/detail/compensation/includes/controls.html' %}
|
{% include 'compensation/detail/compensation/includes/controls.html' %}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<hr>
|
<hr>
|
||||||
<div id="data" class="row">
|
<div id="data" class="row">
|
||||||
<div class="col-sm-12 col-md-12 col-lg-6">
|
<div class="col-sm-12 col-md-12 col-lg-12 col-xl-6">
|
||||||
<div class="table-container">
|
<div class="table-container">
|
||||||
<table class="table table-hover">
|
<table class="table table-hover">
|
||||||
<tr>
|
<tr>
|
||||||
@@ -38,6 +39,16 @@
|
|||||||
</a>
|
</a>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<th scope="row">{% trans 'Is PIK' %}</th>
|
||||||
|
<td class="align-middle">
|
||||||
|
{% if obj.is_pik %}
|
||||||
|
{% trans 'Yes' %}
|
||||||
|
{% else %}
|
||||||
|
{% trans 'No' %}
|
||||||
|
{% endif %}
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<th scope="row">{% trans 'Is CEF compensation' %}</th>
|
<th scope="row">{% trans 'Is CEF compensation' %}</th>
|
||||||
<td class="align-middle">
|
<td class="align-middle">
|
||||||
@@ -65,6 +76,11 @@
|
|||||||
<span>
|
<span>
|
||||||
{% fa5_icon 'star' 'far' %}
|
{% fa5_icon 'star' 'far' %}
|
||||||
</span>
|
</span>
|
||||||
|
{% if last_checked %}
|
||||||
|
<span class="rlp-gd-inv" title="{{last_checked_tooltip}}">
|
||||||
|
{% fa5_icon 'star' 'fas' %}
|
||||||
|
</span>
|
||||||
|
{% endif %}
|
||||||
{% else %}
|
{% else %}
|
||||||
<span class="check-star" title="{% trans 'Checked on '%} {{obj.intervention.checked.timestamp}} {% trans 'by' %} {{obj.intervention.checked.user}}">
|
<span class="check-star" title="{% trans 'Checked on '%} {{obj.intervention.checked.timestamp}} {% trans 'by' %} {{obj.intervention.checked.user}}">
|
||||||
{% fa5_icon 'star' %}
|
{% fa5_icon 'star' %}
|
||||||
@@ -89,55 +105,77 @@
|
|||||||
<tr>
|
<tr>
|
||||||
<th scope="row">{% trans 'Last modified' %}</th>
|
<th scope="row">{% trans 'Last modified' %}</th>
|
||||||
<td class="align-middle">
|
<td class="align-middle">
|
||||||
{{obj.modified.timestamp|default_if_none:""|naturalday}}
|
{% if obj.modified %}
|
||||||
<br>
|
{{obj.modified.timestamp|default_if_none:""}}
|
||||||
{{obj.modified.user.username}}
|
<br>
|
||||||
|
{{obj.modified.user.username}}
|
||||||
|
{% else %}
|
||||||
|
{{obj.created.timestamp|default_if_none:""}}
|
||||||
|
<br>
|
||||||
|
{{obj.created.user.username}}
|
||||||
|
{% endif %}
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<th scope="row">{% trans 'Shared with' %}</th>
|
<th scope="row">{% trans 'Shared with' %}</th>
|
||||||
<td class="align-middle">
|
<td class="align-middle">
|
||||||
{% for user in obj.intervention.users.all %}
|
{% for team in obj.intervention.shared_teams %}
|
||||||
{% include 'user/includes/contact_modal_button.html' %}
|
{% include 'user/includes/team_data_modal_button.html' %}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
<hr>
|
||||||
|
{% if has_access %}
|
||||||
|
{% for user in obj.users.all %}
|
||||||
|
{% include 'user/includes/contact_modal_button.html' %}
|
||||||
|
{% endfor %}
|
||||||
|
{% else %}
|
||||||
|
<span title="{% trans 'The data must be shared with you, if you want to see which other users have shared access as well.' %}">
|
||||||
|
{% fa5_icon 'eye-slash' %}
|
||||||
|
{{obj.users.count}} {% trans 'other users' %}
|
||||||
|
</span>
|
||||||
|
{% endif %}
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-sm-12 col-md-12 col-lg-6">
|
<div class="col-sm-12 col-md-12 col-lg-12 col-xl-6">
|
||||||
<div class="row">
|
<div class="col">
|
||||||
{% include 'map/geom_form.html' %}
|
<div class="row">
|
||||||
</div>
|
<div class="col-sm-12">
|
||||||
<div class="row">
|
{% include 'map/geom_form.html' %}
|
||||||
{% include 'konova/includes/parcels.html' %}
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
{% include 'konova/includes/comment_card.html' %}
|
{% include 'konova/includes/parcels/parcels.html' %}
|
||||||
|
</div>
|
||||||
|
<div class="row">
|
||||||
|
{% include 'konova/includes/comment_card.html' %}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<hr>
|
<hr>
|
||||||
|
<div id="related_data">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-sm-12 col-md-12 col-lg-6">
|
<div class="col-sm-12 col-md-12 col-lg-12 col-xl-6">
|
||||||
{% include 'compensation/detail/compensation/includes/states-before.html' %}
|
{% include 'compensation/detail/compensation/includes/states-before.html' %}
|
||||||
|
</div>
|
||||||
|
<div class="col-sm-12 col-md-12 col-lg-12 col-xl-6">
|
||||||
|
{% include 'compensation/detail/compensation/includes/states-after.html' %}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-sm-12 col-md-12 col-lg-6">
|
<div class="row">
|
||||||
{% include 'compensation/detail/compensation/includes/states-after.html' %}
|
<div class="col-sm-12 col-md-12 col-lg-12 col-xl-6">
|
||||||
|
{% include 'compensation/detail/compensation/includes/actions.html' %}
|
||||||
|
</div>
|
||||||
|
<div class="col-sm-12 col-md-12 col-lg-12 col-xl-6">
|
||||||
|
{% include 'compensation/detail/compensation/includes/deadlines.html' %}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
<div class="row">
|
||||||
<div class="row">
|
<div class="col-sm-12 col-md-12 col-lg-12 col-xl-6">
|
||||||
<div class="col-sm-12 col-md-12 col-lg-6">
|
{% include 'compensation/detail/compensation/includes/documents.html' %}
|
||||||
{% include 'compensation/detail/compensation/includes/actions.html' %}
|
</div>
|
||||||
</div>
|
|
||||||
<div class="col-sm-12 col-md-12 col-lg-6">
|
|
||||||
{% include 'compensation/detail/compensation/includes/deadlines.html' %}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="row">
|
|
||||||
<div class="col-sm-12 col-md-12 col-lg-6">
|
|
||||||
{% include 'compensation/detail/compensation/includes/documents.html' %}
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
{% load i18n l10n fontawesome_5 humanize %}
|
{% load i18n l10n fontawesome_5 humanize ksp_filters %}
|
||||||
<div id="actions" class="card">
|
<div id="actions" class="card">
|
||||||
<div class="card-header rlp-r">
|
<div class="card-header rlp-r">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
@@ -11,7 +11,7 @@
|
|||||||
<div class="col-sm-6">
|
<div class="col-sm-6">
|
||||||
<div class="d-flex justify-content-end">
|
<div class="d-flex justify-content-end">
|
||||||
{% if is_default_member and has_access %}
|
{% if is_default_member and has_access %}
|
||||||
<button class="btn btn-outline-default btn-modal" data-form-url="{% url 'compensation:acc-new-action' obj.id %}" title="{% trans 'Add new action' %}">
|
<button class="btn btn-outline-default btn-modal" data-form-url="{% url 'compensation:acc:new-action' obj.id %}" title="{% trans 'Add new action' %}">
|
||||||
{% fa5_icon 'plus' %}
|
{% fa5_icon 'plus' %}
|
||||||
{% fa5_icon 'seedling' %}
|
{% fa5_icon 'seedling' %}
|
||||||
</button>
|
</button>
|
||||||
@@ -20,25 +20,24 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="card-body scroll-300">
|
<div class="card-body scroll-300 p-2">
|
||||||
<table class="table table-hover">
|
<table class="table table-hover">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th class="w-25" scope="col">
|
<th class="" scope="col">
|
||||||
{% trans 'Action type' %}
|
{% trans 'Action type' %}
|
||||||
</th>
|
</th>
|
||||||
<th class="w-25" scope="col">
|
|
||||||
{% trans 'Action type details' %}
|
|
||||||
</th>
|
|
||||||
<th scope="col">
|
<th scope="col">
|
||||||
{% trans 'Amount' context 'Compensation' %}
|
{% trans 'Amount' context 'Compensation' %}
|
||||||
</th>
|
</th>
|
||||||
<th scope="col">
|
<th scope="col">
|
||||||
{% trans 'Comment' %}
|
{% trans 'Comment' %}
|
||||||
</th>
|
</th>
|
||||||
{% if default_member and has_access %}
|
{% if is_default_member and has_access %}
|
||||||
<th scope="col">
|
<th class="w-10" scope="col">
|
||||||
{% trans 'Action' %}
|
<span class="float-right">
|
||||||
|
{% trans 'Action' %}
|
||||||
|
</span>
|
||||||
</th>
|
</th>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</tr>
|
</tr>
|
||||||
@@ -46,19 +45,29 @@
|
|||||||
<tbody>
|
<tbody>
|
||||||
{% for action in actions %}
|
{% for action in actions %}
|
||||||
<tr>
|
<tr>
|
||||||
<td class="align-middle">
|
<td class="">
|
||||||
{{ action.action_type }}
|
{% for type in action.action_type.all %}
|
||||||
</td>
|
<div> {{type.parent.parent.long_name}} {% fa5_icon 'angle-right' %} {{type.parent.long_name}} {% fa5_icon 'angle-right' %} {{type.long_name}} </div>
|
||||||
<td class="align-middle">
|
<hr>
|
||||||
|
{% endfor %}
|
||||||
{% for detail in action.action_type_details.all %}
|
{% for detail in action.action_type_details.all %}
|
||||||
<div class="mb-2" title="{{detail}}">{{detail.long_name}}</div>
|
<span class="badge badge-pill rlp-r" title="{{detail}}">{{detail.long_name}}</span>
|
||||||
|
{% empty %}
|
||||||
|
<span class="badge badge-pill rlp-r-outline" title="{% trans 'No action type details' %}">{% trans 'No action type details' %}</span>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</td>
|
</td>
|
||||||
<td class="align-middle">{{ action.amount|floatformat:2|intcomma }} {{ action.unit_humanize }}</td>
|
<td class="">{{ action.amount|floatformat:2|intcomma }} {{ action.unit_humanize }}</td>
|
||||||
<td class="align-middle">{{ action.comment|default_if_none:"" }}</td>
|
<td class="">
|
||||||
<td class="align-middle">
|
<div class="scroll-150">
|
||||||
|
{{ action.comment }}
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td class="align-middle float-right">
|
||||||
{% if is_default_member and has_access %}
|
{% if is_default_member and has_access %}
|
||||||
<button data-form-url="{% url 'compensation:acc-action-remove' obj.id action.id %}" class="btn btn-default btn-modal" title="{% trans 'Remove action' %}">
|
<button data-form-url="{% url 'compensation:acc:action-edit' obj.id action.id %}" class="btn btn-default btn-modal" title="{% trans 'Edit action' %}">
|
||||||
|
{% fa5_icon 'edit' %}
|
||||||
|
</button>
|
||||||
|
<button data-form-url="{% url 'compensation:acc:action-remove' obj.id action.id %}" class="btn btn-default btn-modal" title="{% trans 'Remove action' %}">
|
||||||
{% fa5_icon 'trash' %}
|
{% fa5_icon 'trash' %}
|
||||||
</button>
|
</button>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|||||||
@@ -6,36 +6,39 @@
|
|||||||
LANIS
|
LANIS
|
||||||
</button>
|
</button>
|
||||||
</a>
|
</a>
|
||||||
<a href="{% url 'compensation:acc-report' obj.id %}" target="_blank" class="mr-2">
|
<a href="{% url 'compensation:acc:report' obj.id %}" target="_blank" class="mr-2">
|
||||||
<button class="btn btn-default" title="{% trans 'Public report' %}">
|
<button class="btn btn-default" title="{% trans 'Public report' %}">
|
||||||
{% fa5_icon 'file-alt' %}
|
{% fa5_icon 'file-alt' %}
|
||||||
</button>
|
</button>
|
||||||
</a>
|
</a>
|
||||||
{% if has_access %}
|
{% if has_access %}
|
||||||
<button class="btn btn-default btn-modal mr-2" title="{% trans 'Share' %}" data-form-url="{% url 'compensation:share-create' obj.id %}">
|
<button class="btn btn-default btn-modal mr-2" title="{% trans 'Resubmission' %}" data-form-url="{% url 'compensation:acc:resubmission-create' obj.id %}">
|
||||||
|
{% fa5_icon 'bell' %}
|
||||||
|
</button>
|
||||||
|
<button class="btn btn-default btn-modal mr-2" title="{% trans 'Share' %}" data-form-url="{% url 'compensation:acc:share-create' obj.id %}">
|
||||||
{% fa5_icon 'share-alt' %}
|
{% fa5_icon 'share-alt' %}
|
||||||
</button>
|
</button>
|
||||||
{% if is_ets_member %}
|
{% if is_ets_member %}
|
||||||
{% if obj.recorded %}
|
{% if obj.recorded %}
|
||||||
<button class="btn btn-default btn-modal mr-2" title="{% trans 'Unrecord' %}" data-form-url="{% url 'compensation:acc-record' obj.id %}">
|
<button class="btn btn-default btn-modal mr-2" title="{% trans 'Unrecord' %}" data-form-url="{% url 'compensation:acc:record' obj.id %}">
|
||||||
{% fa5_icon 'bookmark' 'far' %}
|
{% fa5_icon 'bookmark' 'far' %}
|
||||||
</button>
|
</button>
|
||||||
{% else %}
|
{% else %}
|
||||||
<button class="btn btn-default btn-modal mr-2" title="{% trans 'Record' %}" data-form-url="{% url 'compensation:acc-record' obj.id %}">
|
<button class="btn btn-default btn-modal mr-2" title="{% trans 'Record' %}" data-form-url="{% url 'compensation:acc:record' obj.id %}">
|
||||||
{% fa5_icon 'bookmark' %}
|
{% fa5_icon 'bookmark' %}
|
||||||
</button>
|
</button>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if is_default_member %}
|
{% if is_default_member %}
|
||||||
<a href="{% url 'compensation:acc-edit' obj.id %}" class="mr-2">
|
<a href="{% url 'compensation:acc:edit' obj.id %}" class="mr-2">
|
||||||
<button class="btn btn-default" title="{% trans 'Edit' %}">
|
<button class="btn btn-default" title="{% trans 'Edit' %}">
|
||||||
{% fa5_icon 'edit' %}
|
{% fa5_icon 'edit' %}
|
||||||
</button>
|
</button>
|
||||||
</a>
|
</a>
|
||||||
<button class="btn btn-default btn-modal mr-2" data-form-url="{% url 'compensation:acc-log' obj.id %}" title="{% trans 'Show log' %}">
|
<button class="btn btn-default btn-modal mr-2" data-form-url="{% url 'compensation:acc:log' obj.id %}" title="{% trans 'Show log' %}">
|
||||||
{% fa5_icon 'history' %}
|
{% fa5_icon 'history' %}
|
||||||
</button>
|
</button>
|
||||||
<button class="btn btn-default btn-modal" data-form-url="{% url 'compensation:acc-remove' obj.id %}" title="{% trans 'Delete' %}">
|
<button class="btn btn-default btn-modal" data-form-url="{% url 'compensation:acc:remove' obj.id %}" title="{% trans 'Delete' %}">
|
||||||
{% fa5_icon 'trash' %}
|
{% fa5_icon 'trash' %}
|
||||||
</button>
|
</button>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|||||||
@@ -11,7 +11,7 @@
|
|||||||
<div class="col-sm-6">
|
<div class="col-sm-6">
|
||||||
<div class="d-flex justify-content-end">
|
<div class="d-flex justify-content-end">
|
||||||
{% if is_default_member and has_access %}
|
{% if is_default_member and has_access %}
|
||||||
<button class="btn btn-outline-default btn-modal" data-form-url="{% url 'compensation:acc-new-deadline' obj.id %}" title="{% trans 'Add new deadline' %}">
|
<button class="btn btn-outline-default btn-modal" data-form-url="{% url 'compensation:acc:new-deadline' obj.id %}" title="{% trans 'Add new deadline' %}">
|
||||||
{% fa5_icon 'plus' %}
|
{% fa5_icon 'plus' %}
|
||||||
{% fa5_icon 'calendar-check' %}
|
{% fa5_icon 'calendar-check' %}
|
||||||
</button>
|
</button>
|
||||||
@@ -20,7 +20,12 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="card-body scroll-300">
|
{% if not has_finished_deadlines %}
|
||||||
|
<div class="alert alert-danger mb-0">
|
||||||
|
{% trans 'Missing finished deadline ' %}
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
|
<div class="card-body scroll-300 p-2">
|
||||||
<table class="table table-hover">
|
<table class="table table-hover">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
@@ -33,8 +38,10 @@
|
|||||||
<th scope="col">
|
<th scope="col">
|
||||||
{% trans 'Comment' %}
|
{% trans 'Comment' %}
|
||||||
</th>
|
</th>
|
||||||
<th scope="col">
|
<th class="w-10" scope="col">
|
||||||
{% trans 'Action' %}
|
<span class="float-right">
|
||||||
|
{% trans 'Action' %}
|
||||||
|
</span>
|
||||||
</th>
|
</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
@@ -45,10 +52,17 @@
|
|||||||
{% trans deadline.type_humanized %}
|
{% trans deadline.type_humanized %}
|
||||||
</td>
|
</td>
|
||||||
<td class="align-middle">{{ deadline.date|default_if_none:"---" }}</td>
|
<td class="align-middle">{{ deadline.date|default_if_none:"---" }}</td>
|
||||||
<td class="align-middle">{{ deadline.comment }}</td>
|
<td class="align-middle">
|
||||||
<td>
|
<div class="scroll-150">
|
||||||
|
{{ deadline.comment }}
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td class="align-middle float-right">
|
||||||
{% if is_default_member and has_access %}
|
{% if is_default_member and has_access %}
|
||||||
<button data-form-url="{% url 'deadline-remove' deadline.id %}" class="btn btn-default btn-modal" title="{% trans 'Remove deadline' %}">
|
<button data-form-url="{% url 'compensation:acc:deadline-edit' obj.id deadline.id %}" class="btn btn-default btn-modal" title="{% trans 'Edit deadline' %}">
|
||||||
|
{% fa5_icon 'edit' %}
|
||||||
|
</button>
|
||||||
|
<button data-form-url="{% url 'compensation:acc:deadline-remove' obj.id deadline.id %}" class="btn btn-default btn-modal" title="{% trans 'Remove deadline' %}">
|
||||||
{% fa5_icon 'trash' %}
|
{% fa5_icon 'trash' %}
|
||||||
</button>
|
</button>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|||||||
@@ -10,8 +10,8 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="col-sm-6">
|
<div class="col-sm-6">
|
||||||
<div class="d-flex justify-content-end">
|
<div class="d-flex justify-content-end">
|
||||||
{% if is_default_member and has_access %}
|
{% if is_default_member and obj.recorded %}
|
||||||
<button class="btn btn-outline-default btn-modal" data-form-url="{% url 'compensation:acc-new-deduction' obj.id %}" title="{% trans 'Add new deduction' %}">
|
<button class="btn btn-outline-default btn-modal" data-form-url="{% url 'compensation:acc:new-deduction' obj.id %}" title="{% trans 'Add new deduction' %}">
|
||||||
{% fa5_icon 'plus' %}
|
{% fa5_icon 'plus' %}
|
||||||
{% fa5_icon 'tree' %}
|
{% fa5_icon 'tree' %}
|
||||||
</button>
|
</button>
|
||||||
@@ -20,7 +20,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="card-body scroll-300">
|
<div class="card-body scroll-300 p-2">
|
||||||
<table class="table table-hover">
|
<table class="table table-hover">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
@@ -36,8 +36,10 @@
|
|||||||
<th scope="col">
|
<th scope="col">
|
||||||
{% trans 'Created' %}
|
{% trans 'Created' %}
|
||||||
</th>
|
</th>
|
||||||
<th scope="col">
|
<th class="w-10" scope="col">
|
||||||
{% trans 'Action' %}
|
<span class="float-right">
|
||||||
|
{% trans 'Action' %}
|
||||||
|
</span>
|
||||||
</th>
|
</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
@@ -58,9 +60,12 @@
|
|||||||
</td>
|
</td>
|
||||||
<td class="align-middle">{{ deduction.surface|floatformat:2|intcomma }} m²</td>
|
<td class="align-middle">{{ deduction.surface|floatformat:2|intcomma }} m²</td>
|
||||||
<td class="align-middle">{{ deduction.created.timestamp|default_if_none:""|naturalday}}</td>
|
<td class="align-middle">{{ deduction.created.timestamp|default_if_none:""|naturalday}}</td>
|
||||||
<td>
|
<td class="align-middle float-right">
|
||||||
{% if is_default_member and has_access %}
|
{% if is_default_member and has_access or is_default_member and user in deduction.intervention.shared_users %}
|
||||||
<button data-form-url="{% url 'compensation:acc-remove-deduction' deduction.account.id deduction.id %}" class="btn btn-default btn-modal" title="{% trans 'Remove Deduction' %}">
|
<button data-form-url="{% url 'compensation:acc:edit-deduction' deduction.account.id deduction.id %}" class="btn btn-default btn-modal" title="{% trans 'Edit Deduction' %}">
|
||||||
|
{% fa5_icon 'edit' %}
|
||||||
|
</button>
|
||||||
|
<button data-form-url="{% url 'compensation:acc:remove-deduction' deduction.account.id deduction.id %}" class="btn btn-default btn-modal" title="{% trans 'Remove Deduction' %}">
|
||||||
{% fa5_icon 'trash' %}
|
{% fa5_icon 'trash' %}
|
||||||
</button>
|
</button>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|||||||
@@ -11,7 +11,7 @@
|
|||||||
<div class="col-sm-6">
|
<div class="col-sm-6">
|
||||||
<div class="d-flex justify-content-end">
|
<div class="d-flex justify-content-end">
|
||||||
{% if is_default_member and has_access %}
|
{% if is_default_member and has_access %}
|
||||||
<button class="btn btn-outline-default btn-modal" data-form-url="{% url 'compensation:acc-new-doc' obj.id %}" title="{% trans 'Add new document' %}">
|
<button class="btn btn-outline-default btn-modal" data-form-url="{% url 'compensation:acc:new-doc' obj.id %}" title="{% trans 'Add new document' %}">
|
||||||
{% fa5_icon 'plus' %}
|
{% fa5_icon 'plus' %}
|
||||||
{% fa5_icon 'file' %}
|
{% fa5_icon 'file' %}
|
||||||
</button>
|
</button>
|
||||||
@@ -20,7 +20,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="card-body scroll-300">
|
<div class="card-body scroll-300 p-2">
|
||||||
<table class="table table-hover">
|
<table class="table table-hover">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
@@ -28,10 +28,15 @@
|
|||||||
{% trans 'Title' %}
|
{% trans 'Title' %}
|
||||||
</th>
|
</th>
|
||||||
<th scope="col">
|
<th scope="col">
|
||||||
{% trans 'Comment' %}
|
{% trans 'Created on' %}
|
||||||
</th>
|
</th>
|
||||||
<th scope="col">
|
<th scope="col">
|
||||||
{% trans 'Action' %}
|
{% trans 'Comment' %}
|
||||||
|
</th>
|
||||||
|
<th class="w-10" scope="col">
|
||||||
|
<span class="float-right">
|
||||||
|
{% trans 'Action' %}
|
||||||
|
</span>
|
||||||
</th>
|
</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
@@ -39,14 +44,24 @@
|
|||||||
{% for doc in obj.documents.all %}
|
{% for doc in obj.documents.all %}
|
||||||
<tr>
|
<tr>
|
||||||
<td class="align-middle">
|
<td class="align-middle">
|
||||||
<a href="{% url 'compensation:acc-get-doc' doc.id %}">
|
<a href="{% url 'compensation:acc:get-doc' obj.id doc.id %}">
|
||||||
{{ doc.title }}
|
{{ doc.title }}
|
||||||
</a>
|
</a>
|
||||||
</td>
|
</td>
|
||||||
<td class="align-middle">{{ doc.comment }}</td>
|
<td class="align-middle">
|
||||||
<td>
|
{{ doc.date_of_creation }}
|
||||||
|
</td>
|
||||||
|
<td class="align-middle">
|
||||||
|
<div class="scroll-150">
|
||||||
|
{{ doc.comment }}
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td class="align-middle float-right">
|
||||||
{% if is_default_member and has_access %}
|
{% if is_default_member and has_access %}
|
||||||
<button data-form-url="{% url 'compensation:acc-remove-doc' doc.id %}" class="btn btn-default btn-modal" title="{% trans 'Remove document' %}">
|
<button data-form-url="{% url 'compensation:acc:edit-doc' obj.id doc.id %}" class="btn btn-default btn-modal" title="{% trans 'Edit document' %}">
|
||||||
|
{% fa5_icon 'edit' %}
|
||||||
|
</button>
|
||||||
|
<button data-form-url="{% url 'compensation:acc:remove-doc' obj.id doc.id %}" class="btn btn-default btn-modal" title="{% trans 'Remove document' %}">
|
||||||
{% fa5_icon 'trash' %}
|
{% fa5_icon 'trash' %}
|
||||||
</button>
|
</button>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|||||||
@@ -11,7 +11,7 @@
|
|||||||
<div class="col-sm-6">
|
<div class="col-sm-6">
|
||||||
<div class="d-flex justify-content-end">
|
<div class="d-flex justify-content-end">
|
||||||
{% if is_default_member and has_access %}
|
{% if is_default_member and has_access %}
|
||||||
<button class="btn btn-outline-default btn-modal" data-form-url="{% url 'compensation:acc-new-state' obj.id %}" title="{% trans 'Add new state after' %}">
|
<button class="btn btn-outline-default btn-modal" data-form-url="{% url 'compensation:acc:new-state' obj.id %}" title="{% trans 'Add new state after' %}">
|
||||||
{% fa5_icon 'plus' %}
|
{% fa5_icon 'plus' %}
|
||||||
{% fa5_icon 'layer-group' %}
|
{% fa5_icon 'layer-group' %}
|
||||||
</button>
|
</button>
|
||||||
@@ -20,27 +20,26 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="card-body scroll-300">
|
{% if sum_before_states > sum_after_states %}
|
||||||
{% if sum_before_states > sum_after_states %}
|
<div class="alert alert-danger mb-0">
|
||||||
<div class="row alert alert-danger">
|
{% trans 'Missing surfaces according to states before: ' %}{{ diff_states|floatformat:2 }} m²
|
||||||
{% trans 'Missing surfaces according to states before: ' %}{{ diff_states|floatformat:2 }} m²
|
</div>
|
||||||
</div>
|
{% endif %}
|
||||||
{% endif %}
|
<div class="card-body scroll-300 p-2">
|
||||||
<table class="table table-hover">
|
<table class="table table-hover">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th class="w-25" scope="col">
|
<th class="w-50" scope="col">
|
||||||
{% trans 'Biotope type' %}
|
{% trans 'Biotope type' %}
|
||||||
</th>
|
</th>
|
||||||
<th class="w-25" scope="col">
|
|
||||||
{% trans 'Biotope additional type' %}
|
|
||||||
</th>
|
|
||||||
<th scope="col">
|
<th scope="col">
|
||||||
{% trans 'Surface' %}
|
{% trans 'Surface' %}
|
||||||
</th>
|
</th>
|
||||||
{% if is_default_member and has_access %}
|
{% if is_default_member and has_access %}
|
||||||
<th scope="col">
|
<th class="w-10" scope="col">
|
||||||
{% trans 'Action' %}
|
<span class="float-right">
|
||||||
|
{% trans 'Action' %}
|
||||||
|
</span>
|
||||||
</th>
|
</th>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</tr>
|
</tr>
|
||||||
@@ -48,20 +47,22 @@
|
|||||||
<tbody>
|
<tbody>
|
||||||
{% for state in after_states %}
|
{% for state in after_states %}
|
||||||
<tr>
|
<tr>
|
||||||
<td class="align-middle">
|
<td>
|
||||||
{{ state.biotope_type }}
|
<span>{{ state.biotope_type.parent.long_name }} {% fa5_icon 'angle-right' %} {{ state.biotope_type.long_name }} ({{state.biotope_type.short_name}})</span>
|
||||||
</td>
|
<br>
|
||||||
<td class="align-middle">
|
{% for detail in state.biotope_type_details.all %}
|
||||||
{% for biotope_extra in state.biotope_type_details.all %}
|
<span class="badge badge-pill rlp-r" title="{{detail}}">{{detail.long_name}}</span>
|
||||||
<div class="mb-2" title="{{ biotope_extra }}">
|
{% empty %}
|
||||||
{{ biotope_extra.long_name }}
|
<span class="badge badge-pill rlp-r-outline" title="{% trans 'No biotope type details' %}">{% trans 'No biotope type details' %}</span>
|
||||||
</div>
|
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</td>
|
</td>
|
||||||
<td class="align-middle">{{ state.surface|floatformat:2 }} m²</td>
|
<td>{{ state.surface|floatformat:2 }} m²</td>
|
||||||
<td class="align-middle">
|
<td class="align-middle float-right">
|
||||||
{% if is_default_member and has_access %}
|
{% if is_default_member and has_access %}
|
||||||
<button data-form-url="{% url 'compensation:acc-state-remove' obj.id state.id %}" class="btn btn-default btn-modal" title="{% trans 'Remove state' %}">
|
<button data-form-url="{% url 'compensation:acc:state-edit' obj.id state.id %}" class="btn btn-default btn-modal" title="{% trans 'Edit state' %}">
|
||||||
|
{% fa5_icon 'edit' %}
|
||||||
|
</button>
|
||||||
|
<button data-form-url="{% url 'compensation:acc:state-remove' obj.id state.id %}" class="btn btn-default btn-modal" title="{% trans 'Remove state' %}">
|
||||||
{% fa5_icon 'trash' %}
|
{% fa5_icon 'trash' %}
|
||||||
</button>
|
</button>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|||||||
@@ -11,7 +11,7 @@
|
|||||||
<div class="col-sm-6">
|
<div class="col-sm-6">
|
||||||
<div class="d-flex justify-content-end">
|
<div class="d-flex justify-content-end">
|
||||||
{% if is_default_member and has_access %}
|
{% if is_default_member and has_access %}
|
||||||
<button class="btn btn-outline-default btn-modal" data-form-url="{% url 'compensation:acc-new-state' obj.id %}?before=true" title="{% trans 'Add new state before' %}">
|
<button class="btn btn-outline-default btn-modal" data-form-url="{% url 'compensation:acc:new-state' obj.id %}?before=true" title="{% trans 'Add new state before' %}">
|
||||||
{% fa5_icon 'plus' %}
|
{% fa5_icon 'plus' %}
|
||||||
{% fa5_icon 'layer-group' %}
|
{% fa5_icon 'layer-group' %}
|
||||||
</button>
|
</button>
|
||||||
@@ -20,27 +20,26 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="card-body scroll-300">
|
{% if sum_before_states < sum_after_states %}
|
||||||
{% if sum_before_states < sum_after_states %}
|
<div class="alert alert-danger mb-0">
|
||||||
<div class="row alert alert-danger">
|
{% trans 'Missing surfaces according to states after: ' %}{{ diff_states|floatformat:2 }} m²
|
||||||
{% trans 'Missing surfaces according to states after: ' %}{{ diff_states|floatformat:2 }} m²
|
</div>
|
||||||
</div>
|
{% endif %}
|
||||||
{% endif %}
|
<div class="card-body scroll-300 p-2">
|
||||||
<table class="table table-hover">
|
<table class="table table-hover">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th class="w-25" scope="col">
|
<th class="w-50" scope="col">
|
||||||
{% trans 'Biotope type' %}
|
{% trans 'Biotope type' %}
|
||||||
</th>
|
</th>
|
||||||
<th class="w-25" scope="col">
|
|
||||||
{% trans 'Biotope additional type' %}
|
|
||||||
</th>
|
|
||||||
<th scope="col">
|
<th scope="col">
|
||||||
{% trans 'Surface' %}
|
{% trans 'Surface' %}
|
||||||
</th>
|
</th>
|
||||||
{% if is_default_member and has_access %}
|
{% if is_default_member and has_access %}
|
||||||
<th scope="col">
|
<th class="w-10" scope="col">
|
||||||
{% trans 'Action' %}
|
<span class="float-right">
|
||||||
|
{% trans 'Action' %}
|
||||||
|
</span>
|
||||||
</th>
|
</th>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</tr>
|
</tr>
|
||||||
@@ -48,20 +47,22 @@
|
|||||||
<tbody>
|
<tbody>
|
||||||
{% for state in before_states %}
|
{% for state in before_states %}
|
||||||
<tr>
|
<tr>
|
||||||
<td class="align-middle">
|
<td>
|
||||||
{{ state.biotope_type }}
|
<span>{{ state.biotope_type.parent.long_name }} {% fa5_icon 'angle-right' %} {{ state.biotope_type.long_name }} ({{state.biotope_type.short_name}})</span>
|
||||||
</td>
|
<br>
|
||||||
<td class="align-middle">
|
{% for detail in state.biotope_type_details.all %}
|
||||||
{% for biotope_extra in state.biotope_type_details.all %}
|
<span class="badge badge-pill rlp-r" title="{{detail}}">{{detail.long_name}}</span>
|
||||||
<div class="mb-2" title="{{ biotope_extra }}">
|
{% empty %}
|
||||||
{{ biotope_extra.long_name }}
|
<span class="badge badge-pill rlp-r-outline" title="{% trans 'No biotope type details' %}">{% trans 'No biotope type details' %}</span>
|
||||||
</div>
|
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</td>
|
</td>
|
||||||
<td class="align-middle">{{ state.surface|floatformat:2 }} m²</td>
|
<td>{{ state.surface|floatformat:2 }} m²</td>
|
||||||
<td class="align-middle">
|
<td class="align-middle float-right">
|
||||||
{% if is_default_member and has_access %}
|
{% if is_default_member and has_access %}
|
||||||
<button data-form-url="{% url 'compensation:acc-state-remove' obj.id state.id %}" class="btn btn-default btn-modal" title="{% trans 'Remove state' %}">
|
<button data-form-url="{% url 'compensation:acc:state-edit' obj.id state.id %}" class="btn btn-default btn-modal" title="{% trans 'Edit state' %}">
|
||||||
|
{% fa5_icon 'edit' %}
|
||||||
|
</button>
|
||||||
|
<button data-form-url="{% url 'compensation:acc:state-remove' obj.id state.id %}" class="btn btn-default btn-modal" title="{% trans 'Remove state' %}">
|
||||||
{% fa5_icon 'trash' %}
|
{% fa5_icon 'trash' %}
|
||||||
</button>
|
</button>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
{% load i18n l10n static fontawesome_5 humanize %}
|
{% load i18n l10n static fontawesome_5 humanize %}
|
||||||
|
|
||||||
{% block head %}
|
{% block head %}
|
||||||
|
|
||||||
{% comment %}
|
{% comment %}
|
||||||
dal documentation (django-autocomplete-light) states using form.media for adding needed scripts.
|
dal documentation (django-autocomplete-light) states using form.media for adding needed scripts.
|
||||||
This does not work properly with modal forms, as the scripts are not loaded properly inside the modal.
|
This does not work properly with modal forms, as the scripts are not loaded properly inside the modal.
|
||||||
@@ -14,16 +15,16 @@
|
|||||||
{% block body %}
|
{% block body %}
|
||||||
|
|
||||||
<div id="detail-header" class="row">
|
<div id="detail-header" class="row">
|
||||||
<div class="col-sm-12 col-md-12 col-lg-6">
|
<div class="col-sm-12 col-md-12 col-lg-12 col-xl-6">
|
||||||
<h3>{% trans 'Eco-account' %}<br> {{obj.identifier}}</h3>
|
<h3>{% trans 'Eco-account' %}<br> {{obj.identifier}}</h3>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-sm-12 col-md-12 col-lg-6">
|
<div class="col-sm-12 col-md-12 col-lg-12 col-xl-6">
|
||||||
{% include 'compensation/detail/eco_account/includes/controls.html' %}
|
{% include 'compensation/detail/eco_account/includes/controls.html' %}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<hr>
|
<hr>
|
||||||
<div id="data" class="row">
|
<div id="data" class="row">
|
||||||
<div class="col-sm-12 col-md-12 col-lg-6">
|
<div class="col-sm-12 col-md-12 col-lg-12 col-xl-6">
|
||||||
<div class="table-container">
|
<div class="table-container">
|
||||||
<table class="table table-hover">
|
<table class="table table-hover">
|
||||||
<tr>
|
<tr>
|
||||||
@@ -69,31 +70,60 @@
|
|||||||
<th scope="row">{% trans 'Action handler' %}</th>
|
<th scope="row">{% trans 'Action handler' %}</th>
|
||||||
<td class="align-middle">{{obj.responsible.handler|default_if_none:""}}</td>
|
<td class="align-middle">{{obj.responsible.handler|default_if_none:""}}</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<th scope="row">{% trans 'Is PIK' %}</th>
|
||||||
|
<td class="align-middle">
|
||||||
|
{% if obj.is_pik %}
|
||||||
|
{% trans 'Yes' %}
|
||||||
|
{% else %}
|
||||||
|
{% trans 'No' %}
|
||||||
|
{% endif %}
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<th scope="row">{% trans 'Last modified' %}</th>
|
<th scope="row">{% trans 'Last modified' %}</th>
|
||||||
<td class="align-middle">
|
<td class="align-middle">
|
||||||
{{obj.modified.timestamp|default_if_none:""|naturalday}}
|
{% if obj.modified %}
|
||||||
<br>
|
{{obj.modified.timestamp|default_if_none:""}}
|
||||||
{{obj.modified.user.username}}
|
<br>
|
||||||
|
{{obj.modified.user.username}}
|
||||||
|
{% else %}
|
||||||
|
{{obj.created.timestamp|default_if_none:""}}
|
||||||
|
<br>
|
||||||
|
{{obj.created.user.username}}
|
||||||
|
{% endif %}
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<th scope="row">{% trans 'Shared with' %}</th>
|
<th scope="row">{% trans 'Shared with' %}</th>
|
||||||
<td class="align-middle">
|
<td class="align-middle">
|
||||||
{% for user in obj.users.all %}
|
{% for team in obj.shared_teams %}
|
||||||
{% include 'user/includes/contact_modal_button.html' %}
|
{% include 'user/includes/team_data_modal_button.html' %}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
<hr>
|
||||||
|
{% if has_access %}
|
||||||
|
{% for user in obj.users.all %}
|
||||||
|
{% include 'user/includes/contact_modal_button.html' %}
|
||||||
|
{% endfor %}
|
||||||
|
{% else %}
|
||||||
|
<span title="{% trans 'The data must be shared with you, if you want to see which other users have shared access as well.' %}">
|
||||||
|
{% fa5_icon 'eye-slash' %}
|
||||||
|
{{obj.users.count}} {% trans 'other users' %}
|
||||||
|
</span>
|
||||||
|
{% endif %}
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-sm-12 col-md-12 col-lg-6">
|
<div class="col-sm-12 col-md-12 col-lg-12 col-xl-6">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
{% include 'map/geom_form.html' %}
|
<div class="col-sm-12">
|
||||||
|
{% include 'map/geom_form.html' %}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
{% include 'konova/includes/parcels.html' %}
|
{% include 'konova/includes/parcels/parcels.html' %}
|
||||||
</div>
|
</div>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
{% include 'konova/includes/comment_card.html' %}
|
{% include 'konova/includes/comment_card.html' %}
|
||||||
@@ -102,28 +132,30 @@
|
|||||||
</div>
|
</div>
|
||||||
<hr>
|
<hr>
|
||||||
|
|
||||||
<div class="row">
|
<div id="related_data">
|
||||||
<div class="col-sm-12 col-md-12 col-lg-6">
|
<div class="row">
|
||||||
{% include 'compensation/detail/eco_account/includes/states-before.html' %}
|
<div class="col-sm-12 col-md-12 col-lg-12 col-xl-6">
|
||||||
|
{% include 'compensation/detail/eco_account/includes/states-before.html' %}
|
||||||
|
</div>
|
||||||
|
<div class="col-sm-12 col-md-12 col-lg-12 col-xl-6">
|
||||||
|
{% include 'compensation/detail/eco_account/includes/states-after.html' %}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-sm-12 col-md-12 col-lg-6">
|
<div class="row">
|
||||||
{% include 'compensation/detail/eco_account/includes/states-after.html' %}
|
<div class="col-sm-12 col-md-12 col-lg-12 col-xl-6">
|
||||||
|
{% include 'compensation/detail/eco_account/includes/actions.html' %}
|
||||||
|
</div>
|
||||||
|
<div class="col-sm-12 col-md-12 col-lg-12 col-xl-6">
|
||||||
|
{% include 'compensation/detail/eco_account/includes/deadlines.html' %}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
<div class="row">
|
||||||
<div class="row">
|
<div class="col-sm-12 col-md-12 col-lg-12 col-xl-6">
|
||||||
<div class="col-sm-12 col-md-12 col-lg-6">
|
{% include 'compensation/detail/eco_account/includes/documents.html' %}
|
||||||
{% include 'compensation/detail/eco_account/includes/actions.html' %}
|
</div>
|
||||||
</div>
|
<div class="col-sm-12 col-md-12 col-lg-12 col-xl-6">
|
||||||
<div class="col-sm-12 col-md-12 col-lg-6">
|
{% include 'compensation/detail/eco_account/includes/deductions.html' %}
|
||||||
{% include 'compensation/detail/eco_account/includes/deadlines.html' %}
|
</div>
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="row">
|
|
||||||
<div class="col-sm-12 col-md-12 col-lg-6">
|
|
||||||
{% include 'compensation/detail/eco_account/includes/documents.html' %}
|
|
||||||
</div>
|
|
||||||
<div class="col-sm-12 col-md-12 col-lg-6">
|
|
||||||
{% include 'compensation/detail/eco_account/includes/deductions.html' %}
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
{% block body %}
|
{% block body %}
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-sm-12 col-md-12 col-lg-6">
|
<div class="col-sm-12 col-md-12 col-lg-12 col-xl-6">
|
||||||
<h3>{% trans 'Report' %}</h3>
|
<h3>{% trans 'Report' %}</h3>
|
||||||
<h4>{{obj.identifier}}</h4>
|
<h4>{{obj.identifier}}</h4>
|
||||||
<div class="table-container">
|
<div class="table-container">
|
||||||
@@ -20,6 +20,36 @@
|
|||||||
</a>
|
</a>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<th scope="row">{% trans 'Is PIK' %}</th>
|
||||||
|
<td class="align-middle">
|
||||||
|
{% if obj.is_pik %}
|
||||||
|
{% trans 'Yes' %}
|
||||||
|
{% else %}
|
||||||
|
{% trans 'No' %}
|
||||||
|
{% endif %}
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<th scope="row">{% trans 'Is CEF' %}</th>
|
||||||
|
<td class="align-middle">
|
||||||
|
{% if obj.is_cef %}
|
||||||
|
{% trans 'Yes' %}
|
||||||
|
{% else %}
|
||||||
|
{% trans 'No' %}
|
||||||
|
{% endif %}
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<th scope="row">{% trans 'Is coherence keeping' %}</th>
|
||||||
|
<td class="align-middle">
|
||||||
|
{% if obj.is_coherence_keeping %}
|
||||||
|
{% trans 'Yes' %}
|
||||||
|
{% else %}
|
||||||
|
{% trans 'No' %}
|
||||||
|
{% endif %}
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<th scope="row">{% trans 'Last modified' %}</th>
|
<th scope="row">{% trans 'Last modified' %}</th>
|
||||||
<td class="align-middle">
|
<td class="align-middle">
|
||||||
@@ -33,22 +63,17 @@
|
|||||||
{% include 'compensation/detail/compensation/includes/states-after.html' %}
|
{% include 'compensation/detail/compensation/includes/states-after.html' %}
|
||||||
{% include 'compensation/detail/compensation/includes/actions.html' %}
|
{% include 'compensation/detail/compensation/includes/actions.html' %}
|
||||||
</div>
|
</div>
|
||||||
<div class="col-sm-12 col-md-12 col-lg-6">
|
<div class="col-sm-12 col-md-12 col-lg-12 col-xl-6">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
{% include 'map/geom_form.html' %}
|
<div class="col-sm-12">
|
||||||
|
{% include 'map/geom_form.html' %}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
{% include 'konova/includes/parcels.html' %}
|
{% include 'konova/includes/parcels/parcels.html' %}
|
||||||
</div>
|
</div>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-sm-6 col-md-6 col-lg-6">
|
{% include 'konova/includes/report/qrcodes.html' %}
|
||||||
<h4>{% trans 'Open in browser' %}</h4>
|
|
||||||
{{ qrcode|safe }}
|
|
||||||
</div>
|
|
||||||
<div class="col-sm-6 col-md-6 col-lg-6">
|
|
||||||
<h4>{% trans 'View in LANIS' %}</h4>
|
|
||||||
{{ qrcode_lanis|safe }}
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
{% block body %}
|
{% block body %}
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-sm-12 col-md-12 col-lg-6">
|
<div class="col-sm-12 col-md-12 col-lg-12 col-xl-6">
|
||||||
<h3>{% trans 'Report' %}</h3>
|
<h3>{% trans 'Report' %}</h3>
|
||||||
<h4>{{obj.identifier}}</h4>
|
<h4>{{obj.identifier}}</h4>
|
||||||
<div class="table-container">
|
<div class="table-container">
|
||||||
@@ -21,8 +21,14 @@
|
|||||||
<td class="align-middle">{{obj.responsible.conservation_file_number|default_if_none:""}}</td>
|
<td class="align-middle">{{obj.responsible.conservation_file_number|default_if_none:""}}</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<th scope="row">{% trans 'Action handler' %}</th>
|
<th scope="row">{% trans 'Is PIK' %}</th>
|
||||||
<td class="align-middle">{{obj.responsible.handler|default_if_none:""}}</td>
|
<td class="align-middle">
|
||||||
|
{% if obj.is_pik %}
|
||||||
|
{% trans 'Yes' %}
|
||||||
|
{% else %}
|
||||||
|
{% trans 'No' %}
|
||||||
|
{% endif %}
|
||||||
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<th scope="row">{% trans 'Deductions for' %}</th>
|
<th scope="row">{% trans 'Deductions for' %}</th>
|
||||||
@@ -50,22 +56,17 @@
|
|||||||
{% include 'compensation/detail/compensation/includes/states-after.html' %}
|
{% include 'compensation/detail/compensation/includes/states-after.html' %}
|
||||||
{% include 'compensation/detail/compensation/includes/actions.html' %}
|
{% include 'compensation/detail/compensation/includes/actions.html' %}
|
||||||
</div>
|
</div>
|
||||||
<div class="col-sm-12 col-md-12 col-lg-6">
|
<div class="col-sm-12 col-md-12 col-lg-12 col-xl-6">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
{% include 'map/geom_form.html' %}
|
<div class="col-sm-12">
|
||||||
|
{% include 'map/geom_form.html' %}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
{% include 'konova/includes/parcels.html' %}
|
{% include 'konova/includes/parcels/parcels.html' %}
|
||||||
</div>
|
</div>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-sm-6 col-md-6 col-lg-6">
|
{% include 'konova/includes/report/qrcodes.html' %}
|
||||||
<h4>{% trans 'Open in browser' %}</h4>
|
|
||||||
{{ qrcode|safe }}
|
|
||||||
</div>
|
|
||||||
<div class="col-sm-6 col-md-6 col-lg-6">
|
|
||||||
<h4>{% trans 'View in LANIS' %}</h4>
|
|
||||||
{{ qrcode_lanis|safe }}
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
7
compensation/tests/compensation/__init__.py
Normal file
7
compensation/tests/compensation/__init__.py
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
"""
|
||||||
|
Author: Michel Peltriaux
|
||||||
|
Organization: Struktur- und Genehmigungsdirektion Nord, Rhineland-Palatinate, Germany
|
||||||
|
Contact: michel.peltriaux@sgdnord.rlp.de
|
||||||
|
Created on: 07.02.22
|
||||||
|
|
||||||
|
"""
|
||||||
248
compensation/tests/compensation/test_views.py
Normal file
248
compensation/tests/compensation/test_views.py
Normal file
@@ -0,0 +1,248 @@
|
|||||||
|
"""
|
||||||
|
Author: Michel Peltriaux
|
||||||
|
Organization: Struktur- und Genehmigungsdirektion Nord, Rhineland-Palatinate, Germany
|
||||||
|
Contact: michel.peltriaux@sgdnord.rlp.de
|
||||||
|
Created on: 07.02.22
|
||||||
|
|
||||||
|
"""
|
||||||
|
from django.test.client import Client
|
||||||
|
from django.urls import reverse
|
||||||
|
|
||||||
|
from konova.models import Deadline, DeadlineType
|
||||||
|
from konova.settings import DEFAULT_GROUP
|
||||||
|
from konova.tests.test_views import BaseViewTestCase
|
||||||
|
|
||||||
|
|
||||||
|
class CompensationViewTestCase(BaseViewTestCase):
|
||||||
|
"""
|
||||||
|
These tests focus on proper returned views depending on the user's groups privileges and login status
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def setUpTestData(cls) -> None:
|
||||||
|
super().setUpTestData()
|
||||||
|
|
||||||
|
def setUp(self) -> None:
|
||||||
|
super().setUp()
|
||||||
|
state = self.create_dummy_states()
|
||||||
|
self.compensation.before_states.set([state])
|
||||||
|
self.compensation.after_states.set([state])
|
||||||
|
|
||||||
|
action = self.create_dummy_action()
|
||||||
|
self.compensation.actions.set([action])
|
||||||
|
|
||||||
|
self.deadline = Deadline.objects.get_or_create(
|
||||||
|
type=DeadlineType.FINISHED,
|
||||||
|
date="2020-01-01",
|
||||||
|
comment="TESTDEADDLINECOMMENT"
|
||||||
|
)[0]
|
||||||
|
self.compensation.deadlines.add(self.deadline)
|
||||||
|
|
||||||
|
# Prepare urls
|
||||||
|
self.index_url = reverse("compensation:index", args=())
|
||||||
|
self.new_url = reverse("compensation:new", args=(self.intervention.id,))
|
||||||
|
self.new_id_url = reverse("compensation:new-id", args=())
|
||||||
|
self.detail_url = reverse("compensation:detail", args=(self.compensation.id,))
|
||||||
|
self.log_url = reverse("compensation:log", args=(self.compensation.id,))
|
||||||
|
self.edit_url = reverse("compensation:edit", args=(self.compensation.id,))
|
||||||
|
self.remove_url = reverse("compensation:remove", args=(self.compensation.id,))
|
||||||
|
self.report_url = reverse("compensation:report", args=(self.compensation.id,))
|
||||||
|
self.state_new_url = reverse("compensation:new-state", args=(self.compensation.id,))
|
||||||
|
self.action_new_url = reverse("compensation:new-action", args=(self.compensation.id,))
|
||||||
|
self.deadline_new_url = reverse("compensation:new-deadline", args=(self.compensation.id,))
|
||||||
|
self.deadline_edit_url = reverse("compensation:deadline-edit", args=(self.compensation.id, self.deadline.id))
|
||||||
|
self.deadline_remove_url = reverse("compensation:deadline-remove", args=(self.compensation.id, self.deadline.id))
|
||||||
|
self.new_doc_url = reverse("compensation:new-doc", args=(self.compensation.id,))
|
||||||
|
|
||||||
|
self.state_remove_url = reverse("compensation:state-remove", args=(self.compensation.id, self.comp_state.id,))
|
||||||
|
self.action_remove_url = reverse("compensation:action-remove", args=(self.compensation.id, self.comp_action.id,))
|
||||||
|
|
||||||
|
def test_anonymous_user(self):
|
||||||
|
""" Check correct status code for all requests
|
||||||
|
|
||||||
|
Assumption: User not logged in
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
|
||||||
|
"""
|
||||||
|
client = Client()
|
||||||
|
|
||||||
|
success_urls = [
|
||||||
|
self.report_url,
|
||||||
|
]
|
||||||
|
fail_urls = [
|
||||||
|
self.index_url,
|
||||||
|
self.detail_url,
|
||||||
|
self.new_url,
|
||||||
|
self.new_id_url,
|
||||||
|
self.log_url,
|
||||||
|
self.edit_url,
|
||||||
|
self.remove_url,
|
||||||
|
self.state_new_url,
|
||||||
|
self.action_new_url,
|
||||||
|
self.deadline_new_url,
|
||||||
|
self.deadline_edit_url,
|
||||||
|
self.deadline_remove_url,
|
||||||
|
self.state_remove_url,
|
||||||
|
self.action_remove_url,
|
||||||
|
self.new_doc_url,
|
||||||
|
]
|
||||||
|
|
||||||
|
self.assert_url_success(client, success_urls)
|
||||||
|
self.assert_url_fail(client, fail_urls)
|
||||||
|
|
||||||
|
def test_logged_in_no_groups_shared(self):
|
||||||
|
""" Check correct status code for all requests
|
||||||
|
|
||||||
|
Assumption: User logged in and has no groups and data is shared
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
|
||||||
|
"""
|
||||||
|
client = Client()
|
||||||
|
client.login(username=self.superuser.username, password=self.superuser_pw)
|
||||||
|
self.superuser.groups.set([])
|
||||||
|
self.intervention.share_with_user_list([self.superuser])
|
||||||
|
|
||||||
|
# Since the user has no groups, it does not matter that data has been shared. There SHOULD not be any difference
|
||||||
|
# to a user without access, since the important permissions are missing
|
||||||
|
success_urls = [
|
||||||
|
self.index_url,
|
||||||
|
self.detail_url,
|
||||||
|
self.report_url,
|
||||||
|
]
|
||||||
|
fail_urls = [
|
||||||
|
self.new_url,
|
||||||
|
self.new_id_url,
|
||||||
|
self.log_url,
|
||||||
|
self.edit_url,
|
||||||
|
self.remove_url,
|
||||||
|
self.state_new_url,
|
||||||
|
self.action_new_url,
|
||||||
|
self.deadline_new_url,
|
||||||
|
self.deadline_edit_url,
|
||||||
|
self.deadline_remove_url,
|
||||||
|
self.state_remove_url,
|
||||||
|
self.action_remove_url,
|
||||||
|
self.new_doc_url,
|
||||||
|
]
|
||||||
|
|
||||||
|
self.assert_url_success(client, success_urls)
|
||||||
|
self.assert_url_fail(client, fail_urls)
|
||||||
|
|
||||||
|
def test_logged_in_no_groups_unshared(self):
|
||||||
|
""" Check correct status code for all requests
|
||||||
|
|
||||||
|
Assumption: User logged in and has no groups and data is not shared
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
|
||||||
|
"""
|
||||||
|
client = Client()
|
||||||
|
client.login(username=self.superuser.username, password=self.superuser_pw)
|
||||||
|
self.superuser.groups.set([])
|
||||||
|
# Sharing is inherited by base intervention for compensation. Therefore configure the interventions share state
|
||||||
|
self.intervention.share_with_user_list([])
|
||||||
|
|
||||||
|
# Since the user has no groups, it does not matter that data is unshared. There SHOULD not be any difference
|
||||||
|
# to a user having shared access, since all important permissions are missing
|
||||||
|
success_urls = [
|
||||||
|
self.index_url,
|
||||||
|
self.detail_url,
|
||||||
|
self.report_url,
|
||||||
|
]
|
||||||
|
fail_urls = [
|
||||||
|
self.new_url,
|
||||||
|
self.new_id_url,
|
||||||
|
self.log_url,
|
||||||
|
self.edit_url,
|
||||||
|
self.remove_url,
|
||||||
|
self.state_new_url,
|
||||||
|
self.action_new_url,
|
||||||
|
self.deadline_new_url,
|
||||||
|
self.deadline_edit_url,
|
||||||
|
self.deadline_remove_url,
|
||||||
|
self.state_remove_url,
|
||||||
|
self.action_remove_url,
|
||||||
|
self.new_doc_url,
|
||||||
|
]
|
||||||
|
|
||||||
|
self.assert_url_success(client, success_urls)
|
||||||
|
self.assert_url_fail(client, fail_urls)
|
||||||
|
|
||||||
|
def test_logged_in_default_group_shared(self):
|
||||||
|
""" Check correct status code for all requests
|
||||||
|
|
||||||
|
Assumption: User logged in, is default group member and data is shared
|
||||||
|
--> Default group necessary since all base functionalities depend on this group membership
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
|
||||||
|
"""
|
||||||
|
client = Client()
|
||||||
|
client.login(username=self.superuser.username, password=self.superuser_pw)
|
||||||
|
group = self.groups.get(name=DEFAULT_GROUP)
|
||||||
|
self.superuser.groups.set([group])
|
||||||
|
# Sharing is inherited by base intervention for compensation. Therefore configure the interventions share state
|
||||||
|
self.intervention.share_with_user_list([self.superuser])
|
||||||
|
|
||||||
|
success_urls = [
|
||||||
|
self.index_url,
|
||||||
|
self.detail_url,
|
||||||
|
self.report_url,
|
||||||
|
self.new_url,
|
||||||
|
self.new_id_url,
|
||||||
|
self.edit_url,
|
||||||
|
self.state_new_url,
|
||||||
|
self.action_new_url,
|
||||||
|
self.deadline_new_url,
|
||||||
|
self.deadline_edit_url,
|
||||||
|
self.deadline_remove_url,
|
||||||
|
self.state_remove_url,
|
||||||
|
self.action_remove_url,
|
||||||
|
self.new_doc_url,
|
||||||
|
self.log_url,
|
||||||
|
self.remove_url,
|
||||||
|
]
|
||||||
|
self.assert_url_success(client, success_urls)
|
||||||
|
|
||||||
|
def test_logged_in_default_group_unshared(self):
|
||||||
|
""" Check correct status code for all requests
|
||||||
|
|
||||||
|
Assumption: User logged in, is default group member and data is NOT shared
|
||||||
|
--> Default group necessary since all base functionalities depend on this group membership
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
|
||||||
|
"""
|
||||||
|
client = Client()
|
||||||
|
client.login(username=self.superuser.username, password=self.superuser_pw)
|
||||||
|
group = self.groups.get(name=DEFAULT_GROUP)
|
||||||
|
self.superuser.groups.set([group])
|
||||||
|
# Sharing is inherited by base intervention for compensation. Therefore configure the interventions share state
|
||||||
|
self.intervention.share_with_user_list([])
|
||||||
|
|
||||||
|
success_urls = [
|
||||||
|
self.index_url,
|
||||||
|
self.detail_url,
|
||||||
|
self.report_url,
|
||||||
|
self.new_id_url,
|
||||||
|
]
|
||||||
|
fail_urls = [
|
||||||
|
self.new_url,
|
||||||
|
self.edit_url,
|
||||||
|
self.state_new_url,
|
||||||
|
self.action_new_url,
|
||||||
|
self.deadline_new_url,
|
||||||
|
self.deadline_edit_url,
|
||||||
|
self.deadline_remove_url,
|
||||||
|
self.state_remove_url,
|
||||||
|
self.action_remove_url,
|
||||||
|
self.new_doc_url,
|
||||||
|
self.log_url,
|
||||||
|
self.remove_url,
|
||||||
|
]
|
||||||
|
self.assert_url_fail(client, fail_urls)
|
||||||
|
self.assert_url_success(client, success_urls)
|
||||||
|
|
||||||
@@ -2,7 +2,7 @@
|
|||||||
Author: Michel Peltriaux
|
Author: Michel Peltriaux
|
||||||
Organization: Struktur- und Genehmigungsdirektion Nord, Rhineland-Palatinate, Germany
|
Organization: Struktur- und Genehmigungsdirektion Nord, Rhineland-Palatinate, Germany
|
||||||
Contact: michel.peltriaux@sgdnord.rlp.de
|
Contact: michel.peltriaux@sgdnord.rlp.de
|
||||||
Created on: 11.11.21
|
Created on: 07.02.22
|
||||||
|
|
||||||
"""
|
"""
|
||||||
import datetime
|
import datetime
|
||||||
@@ -11,7 +11,7 @@ from django.contrib.gis.geos import MultiPolygon
|
|||||||
from django.urls import reverse
|
from django.urls import reverse
|
||||||
|
|
||||||
from compensation.models import Compensation
|
from compensation.models import Compensation
|
||||||
from konova.settings import ETS_GROUP, ZB_GROUP
|
from konova.settings import ZB_GROUP, ETS_GROUP
|
||||||
from konova.tests.test_views import BaseWorkflowTestCase
|
from konova.tests.test_views import BaseWorkflowTestCase
|
||||||
from user.models import UserAction
|
from user.models import UserAction
|
||||||
|
|
||||||
@@ -21,17 +21,18 @@ class CompensationWorkflowTestCase(BaseWorkflowTestCase):
|
|||||||
def setUpTestData(cls):
|
def setUpTestData(cls):
|
||||||
super().setUpTestData()
|
super().setUpTestData()
|
||||||
|
|
||||||
# Give the user shared access to the dummy intervention -> inherits the access to the compensation
|
|
||||||
cls.intervention.share_with(cls.superuser)
|
|
||||||
|
|
||||||
# Make sure the intervention itself would be fine with valid data
|
|
||||||
cls.intervention = cls.fill_out_intervention(cls.intervention)
|
|
||||||
|
|
||||||
# Make sure the compensation is linked to the intervention
|
|
||||||
cls.intervention.compensations.set([cls.compensation])
|
|
||||||
|
|
||||||
def setUp(self) -> None:
|
def setUp(self) -> None:
|
||||||
super().setUp()
|
super().setUp()
|
||||||
|
|
||||||
|
# Give the user shared access to the dummy intervention -> inherits the access to the compensation
|
||||||
|
self.intervention.share_with_user(self.superuser)
|
||||||
|
|
||||||
|
# Make sure the intervention itself would be fine with valid data
|
||||||
|
self.intervention = self.fill_out_intervention(self.intervention)
|
||||||
|
|
||||||
|
# Make sure the compensation is linked to the intervention
|
||||||
|
self.intervention.compensations.set([self.compensation])
|
||||||
|
|
||||||
# Delete all existing compensations, which might be created by tests
|
# Delete all existing compensations, which might be created by tests
|
||||||
Compensation.objects.all().delete()
|
Compensation.objects.all().delete()
|
||||||
|
|
||||||
@@ -49,23 +50,33 @@ class CompensationWorkflowTestCase(BaseWorkflowTestCase):
|
|||||||
test_id = self.create_dummy_string()
|
test_id = self.create_dummy_string()
|
||||||
test_title = self.create_dummy_string()
|
test_title = self.create_dummy_string()
|
||||||
test_geom = self.create_dummy_geometry()
|
test_geom = self.create_dummy_geometry()
|
||||||
|
geom_json = self.create_geojson(test_geom)
|
||||||
post_data = {
|
post_data = {
|
||||||
"identifier": test_id,
|
"identifier": test_id,
|
||||||
"title": test_title,
|
"title": test_title,
|
||||||
"geom": test_geom.geojson,
|
"geom": geom_json,
|
||||||
"intervention": self.intervention.id,
|
"intervention": self.intervention.id,
|
||||||
}
|
}
|
||||||
|
pre_creation_intervention_log_count = self.intervention.log.count()
|
||||||
|
|
||||||
# Preserve the current number of intervention's compensations
|
# Preserve the current number of intervention's compensations
|
||||||
num_compensations = self.intervention.compensations.count()
|
num_compensations = self.intervention.compensations.count()
|
||||||
self.client_user.post(new_url, post_data)
|
response = self.client_user.post(new_url, post_data)
|
||||||
|
|
||||||
|
self.assertEqual(302, response.status_code)
|
||||||
self.intervention.refresh_from_db()
|
self.intervention.refresh_from_db()
|
||||||
self.assertEqual(num_compensations + 1, self.intervention.compensations.count())
|
self.assertEqual(num_compensations + 1, self.intervention.compensations.count())
|
||||||
new_compensation = self.intervention.compensations.get(identifier=test_id)
|
new_compensation = self.intervention.compensations.get(identifier=test_id)
|
||||||
self.assertEqual(new_compensation.identifier, test_id)
|
self.assertEqual(new_compensation.identifier, test_id)
|
||||||
self.assertEqual(new_compensation.title, test_title)
|
self.assertEqual(new_compensation.title, test_title)
|
||||||
self.assert_equal_geometries(new_compensation.geometry.geom, test_geom)
|
self.assert_equal_geometries(new_compensation.geometry.geom, test_geom)
|
||||||
|
self.assertEqual(new_compensation.log.count(), 1)
|
||||||
|
|
||||||
|
# Expect logs to be set
|
||||||
|
self.assertEqual(pre_creation_intervention_log_count + 1, self.intervention.log.count())
|
||||||
|
self.assertEqual(new_compensation.log.count(), 1)
|
||||||
|
self.assertEqual(self.intervention.log.first().action, UserAction.EDITED)
|
||||||
|
self.assertEqual(new_compensation.log.first().action, UserAction.CREATED)
|
||||||
|
|
||||||
def test_new_from_intervention(self):
|
def test_new_from_intervention(self):
|
||||||
""" Test the creation of a compensation from a given intervention
|
""" Test the creation of a compensation from a given intervention
|
||||||
@@ -78,11 +89,13 @@ class CompensationWorkflowTestCase(BaseWorkflowTestCase):
|
|||||||
test_id = self.create_dummy_string()
|
test_id = self.create_dummy_string()
|
||||||
test_title = self.create_dummy_string()
|
test_title = self.create_dummy_string()
|
||||||
test_geom = self.create_dummy_geometry()
|
test_geom = self.create_dummy_geometry()
|
||||||
|
geom_json = self.create_geojson(test_geom)
|
||||||
post_data = {
|
post_data = {
|
||||||
"identifier": test_id,
|
"identifier": test_id,
|
||||||
"title": test_title,
|
"title": test_title,
|
||||||
"geom": test_geom.geojson,
|
"geom": geom_json,
|
||||||
}
|
}
|
||||||
|
pre_creation_intervention_log_count = self.intervention.log.count()
|
||||||
|
|
||||||
# Preserve the current number of intervention's compensations
|
# Preserve the current number of intervention's compensations
|
||||||
num_compensations = self.intervention.compensations.count()
|
num_compensations = self.intervention.compensations.count()
|
||||||
@@ -95,6 +108,12 @@ class CompensationWorkflowTestCase(BaseWorkflowTestCase):
|
|||||||
self.assertEqual(new_compensation.title, test_title)
|
self.assertEqual(new_compensation.title, test_title)
|
||||||
self.assert_equal_geometries(new_compensation.geometry.geom, test_geom)
|
self.assert_equal_geometries(new_compensation.geometry.geom, test_geom)
|
||||||
|
|
||||||
|
# Expect logs to be set
|
||||||
|
self.assertEqual(new_compensation.log.count(), 1)
|
||||||
|
self.assertEqual(new_compensation.log.first().action, UserAction.CREATED)
|
||||||
|
self.assertEqual(pre_creation_intervention_log_count + 1, self.intervention.log.count())
|
||||||
|
self.assertEqual(self.intervention.log.first().action, UserAction.EDITED)
|
||||||
|
|
||||||
def test_edit(self):
|
def test_edit(self):
|
||||||
""" Checks that the editing of a compensation works
|
""" Checks that the editing of a compensation works
|
||||||
|
|
||||||
@@ -103,11 +122,13 @@ class CompensationWorkflowTestCase(BaseWorkflowTestCase):
|
|||||||
"""
|
"""
|
||||||
url = reverse("compensation:edit", args=(self.compensation.id,))
|
url = reverse("compensation:edit", args=(self.compensation.id,))
|
||||||
self.compensation = self.fill_out_compensation(self.compensation)
|
self.compensation = self.fill_out_compensation(self.compensation)
|
||||||
|
pre_edit_log_count = self.compensation.log.count()
|
||||||
|
|
||||||
new_title = self.create_dummy_string()
|
new_title = self.create_dummy_string()
|
||||||
new_identifier = self.create_dummy_string()
|
new_identifier = self.create_dummy_string()
|
||||||
new_comment = self.create_dummy_string()
|
new_comment = self.create_dummy_string()
|
||||||
new_geometry = MultiPolygon(srid=4326) # Create an empty geometry
|
new_geometry = MultiPolygon(srid=4326) # Create an empty geometry
|
||||||
|
geojson = self.create_geojson(new_geometry)
|
||||||
|
|
||||||
check_on_elements = {
|
check_on_elements = {
|
||||||
self.compensation.title: new_title,
|
self.compensation.title: new_title,
|
||||||
@@ -122,7 +143,7 @@ class CompensationWorkflowTestCase(BaseWorkflowTestCase):
|
|||||||
"title": new_title,
|
"title": new_title,
|
||||||
"intervention": self.intervention.id, # just keep the intervention as it is
|
"intervention": self.intervention.id, # just keep the intervention as it is
|
||||||
"comment": new_comment,
|
"comment": new_comment,
|
||||||
"geom": new_geometry.geojson,
|
"geom": geojson,
|
||||||
}
|
}
|
||||||
self.client_user.post(url, post_data)
|
self.client_user.post(url, post_data)
|
||||||
self.compensation.refresh_from_db()
|
self.compensation.refresh_from_db()
|
||||||
@@ -138,6 +159,10 @@ class CompensationWorkflowTestCase(BaseWorkflowTestCase):
|
|||||||
|
|
||||||
self.assert_equal_geometries(self.compensation.geometry.geom, new_geometry)
|
self.assert_equal_geometries(self.compensation.geometry.geom, new_geometry)
|
||||||
|
|
||||||
|
# Expect logs to be set
|
||||||
|
self.assertEqual(pre_edit_log_count + 1, self.compensation.log.count())
|
||||||
|
self.assertEqual(self.compensation.log.first().action, UserAction.EDITED)
|
||||||
|
|
||||||
def test_checkability(self):
|
def test_checkability(self):
|
||||||
"""
|
"""
|
||||||
This tests if the checkability of the compensation (which is defined by the linked intervention's checked
|
This tests if the checkability of the compensation (which is defined by the linked intervention's checked
|
||||||
@@ -152,6 +177,8 @@ class CompensationWorkflowTestCase(BaseWorkflowTestCase):
|
|||||||
# Add proper privilege for the user
|
# Add proper privilege for the user
|
||||||
self.superuser.groups.add(self.groups.get(name=ZB_GROUP))
|
self.superuser.groups.add(self.groups.get(name=ZB_GROUP))
|
||||||
|
|
||||||
|
pre_check_log_count = self.compensation.log.count()
|
||||||
|
|
||||||
# Prepare url and form data
|
# Prepare url and form data
|
||||||
url = reverse("intervention:check", args=(self.intervention.id,))
|
url = reverse("intervention:check", args=(self.intervention.id,))
|
||||||
post_data = {
|
post_data = {
|
||||||
@@ -186,6 +213,7 @@ class CompensationWorkflowTestCase(BaseWorkflowTestCase):
|
|||||||
|
|
||||||
# Expect the user action to be in the log
|
# Expect the user action to be in the log
|
||||||
self.assertIn(checked, self.compensation.log.all())
|
self.assertIn(checked, self.compensation.log.all())
|
||||||
|
self.assertEqual(pre_check_log_count + 1, self.compensation.log.count())
|
||||||
|
|
||||||
def test_recordability(self):
|
def test_recordability(self):
|
||||||
"""
|
"""
|
||||||
@@ -200,6 +228,7 @@ class CompensationWorkflowTestCase(BaseWorkflowTestCase):
|
|||||||
"""
|
"""
|
||||||
# Add proper privilege for the user
|
# Add proper privilege for the user
|
||||||
self.superuser.groups.add(self.groups.get(name=ETS_GROUP))
|
self.superuser.groups.add(self.groups.get(name=ETS_GROUP))
|
||||||
|
pre_record_log_count = self.compensation.log.count()
|
||||||
|
|
||||||
# Prepare url and form data
|
# Prepare url and form data
|
||||||
record_url = reverse("intervention:record", args=(self.intervention.id,))
|
record_url = reverse("intervention:record", args=(self.intervention.id,))
|
||||||
@@ -234,62 +263,28 @@ class CompensationWorkflowTestCase(BaseWorkflowTestCase):
|
|||||||
|
|
||||||
# Expect the user action to be in the log
|
# Expect the user action to be in the log
|
||||||
self.assertIn(recorded, self.compensation.log.all())
|
self.assertIn(recorded, self.compensation.log.all())
|
||||||
|
self.assertEqual(pre_record_log_count + 1, self.compensation.log.count())
|
||||||
|
|
||||||
|
def test_non_editable_after_recording(self):
|
||||||
|
""" Tests that the compensation can not be edited after being recorded
|
||||||
|
|
||||||
class EcoAccountWorkflowTestCase(BaseWorkflowTestCase):
|
User must be redirected to another page
|
||||||
@classmethod
|
|
||||||
def setUpTestData(cls):
|
|
||||||
super().setUpTestData()
|
|
||||||
|
|
||||||
# Add user to conservation office group and give shared access to the account
|
|
||||||
cls.superuser.groups.add(cls.groups.get(name=ETS_GROUP))
|
|
||||||
cls.eco_account.share_with_list([cls.superuser])
|
|
||||||
|
|
||||||
def test_deductability(self):
|
|
||||||
"""
|
|
||||||
This tests the deductability of an eco account.
|
|
||||||
|
|
||||||
An eco account should only be deductible if it is recorded.
|
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
|
|
||||||
"""
|
"""
|
||||||
# Give user shared access to the dummy intervention, which will be needed here
|
self.assertIsNotNone(self.compensation)
|
||||||
self.intervention.share_with(self.superuser)
|
self.assertFalse(self.compensation.is_recorded)
|
||||||
|
edit_url = reverse("compensation:edit", args=(self.compensation.id,))
|
||||||
# Prepare data for deduction creation
|
response = self.client_user.get(edit_url)
|
||||||
deduct_url = reverse("compensation:acc-new-deduction", args=(self.eco_account.id,))
|
has_redirect = response.status_code == 302
|
||||||
test_surface = 10.00
|
self.assertFalse(has_redirect)
|
||||||
post_data = {
|
|
||||||
"surface": test_surface,
|
|
||||||
"account": self.id,
|
|
||||||
"intervention": self.intervention.id,
|
|
||||||
}
|
|
||||||
# Perform request --> expect to fail
|
|
||||||
self.client_user.post(deduct_url, post_data)
|
|
||||||
|
|
||||||
# Expect that no deduction has been created
|
|
||||||
self.assertEqual(0, self.eco_account.deductions.count())
|
|
||||||
self.assertEqual(0, self.intervention.deductions.count())
|
|
||||||
|
|
||||||
# Now mock the eco account as it would be recorded (with invalid data)
|
|
||||||
# Make sure the deductible surface is high enough for the request
|
|
||||||
self.eco_account.set_recorded(self.superuser)
|
|
||||||
self.eco_account.refresh_from_db()
|
|
||||||
self.eco_account.deductable_surface = test_surface + 1.00
|
|
||||||
self.eco_account.save()
|
|
||||||
self.assertIsNotNone(self.eco_account.recorded)
|
|
||||||
self.assertGreater(self.eco_account.deductable_surface, test_surface)
|
|
||||||
|
|
||||||
# Rerun the request
|
|
||||||
self.client_user.post(deduct_url, post_data)
|
|
||||||
|
|
||||||
# Expect that the deduction has been created
|
|
||||||
self.assertEqual(1, self.eco_account.deductions.count())
|
|
||||||
self.assertEqual(1, self.intervention.deductions.count())
|
|
||||||
deduction = self.eco_account.deductions.first()
|
|
||||||
self.assertEqual(deduction.surface, test_surface)
|
|
||||||
self.assertEqual(deduction.account, self.eco_account)
|
|
||||||
self.assertEqual(deduction.intervention, self.intervention)
|
|
||||||
|
|
||||||
|
self.compensation.intervention.set_recorded(self.user)
|
||||||
|
self.assertTrue(self.compensation.is_recorded)
|
||||||
|
|
||||||
|
edit_url = reverse("compensation:edit", args=(self.compensation.id,))
|
||||||
|
response = self.client_user.get(edit_url)
|
||||||
|
has_redirect = response.status_code == 302
|
||||||
|
self.assertTrue(has_redirect)
|
||||||
|
self.compensation.intervention.set_unrecorded(self.user)
|
||||||
7
compensation/tests/ecoaccount/__init__.py
Normal file
7
compensation/tests/ecoaccount/__init__.py
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
"""
|
||||||
|
Author: Michel Peltriaux
|
||||||
|
Organization: Struktur- und Genehmigungsdirektion Nord, Rhineland-Palatinate, Germany
|
||||||
|
Contact: michel.peltriaux@sgdnord.rlp.de
|
||||||
|
Created on: 07.02.22
|
||||||
|
|
||||||
|
"""
|
||||||
229
compensation/tests/ecoaccount/test_views.py
Normal file
229
compensation/tests/ecoaccount/test_views.py
Normal file
@@ -0,0 +1,229 @@
|
|||||||
|
"""
|
||||||
|
Author: Michel Peltriaux
|
||||||
|
Organization: Struktur- und Genehmigungsdirektion Nord, Rhineland-Palatinate, Germany
|
||||||
|
Contact: michel.peltriaux@sgdnord.rlp.de
|
||||||
|
Created on: 27.10.21
|
||||||
|
|
||||||
|
"""
|
||||||
|
from django.urls import reverse
|
||||||
|
from django.test import Client
|
||||||
|
|
||||||
|
from compensation.tests.compensation.test_views import CompensationViewTestCase
|
||||||
|
from konova.models import DeadlineType, Deadline
|
||||||
|
from konova.settings import DEFAULT_GROUP
|
||||||
|
|
||||||
|
|
||||||
|
class EcoAccountViewTestCase(CompensationViewTestCase):
|
||||||
|
"""
|
||||||
|
These tests focus on proper returned views depending on the user's groups privileges and login status
|
||||||
|
|
||||||
|
EcoAccounts can inherit the same tests used for compensations.
|
||||||
|
|
||||||
|
"""
|
||||||
|
comp_state = None
|
||||||
|
comp_action = None
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def setUpTestData(cls) -> None:
|
||||||
|
super().setUpTestData()
|
||||||
|
|
||||||
|
def setUp(self) -> None:
|
||||||
|
super().setUp()
|
||||||
|
state = self.create_dummy_states()
|
||||||
|
self.eco_account.before_states.set([state])
|
||||||
|
self.eco_account.after_states.set([state])
|
||||||
|
|
||||||
|
action = self.create_dummy_action()
|
||||||
|
self.eco_account.actions.set([action])
|
||||||
|
|
||||||
|
# Prepare urls
|
||||||
|
self.index_url = reverse("compensation:acc:index", args=())
|
||||||
|
self.new_url = reverse("compensation:acc:new", args=())
|
||||||
|
self.new_id_url = reverse("compensation:acc:new-id", args=())
|
||||||
|
self.detail_url = reverse("compensation:acc:detail", args=(self.eco_account.id,))
|
||||||
|
self.log_url = reverse("compensation:acc:log", args=(self.eco_account.id,))
|
||||||
|
self.edit_url = reverse("compensation:acc:edit", args=(self.eco_account.id,))
|
||||||
|
self.remove_url = reverse("compensation:acc:remove", args=(self.eco_account.id,))
|
||||||
|
self.report_url = reverse("compensation:acc:report", args=(self.eco_account.id,))
|
||||||
|
|
||||||
|
self.state_new_url = reverse("compensation:acc:new-state", args=(self.eco_account.id,))
|
||||||
|
self.state_edit_url = reverse("compensation:acc:state-edit", args=(self.eco_account.id, self.comp_state.id))
|
||||||
|
self.state_remove_url = reverse("compensation:acc:state-remove", args=(self.eco_account.id, self.comp_state.id,))
|
||||||
|
|
||||||
|
self.action_new_url = reverse("compensation:acc:new-action", args=(self.eco_account.id,))
|
||||||
|
self.action_edit_url = reverse("compensation:acc:action-edit", args=(self.eco_account.id, self.comp_action.id))
|
||||||
|
self.action_remove_url = reverse("compensation:acc:action-remove", args=(self.eco_account.id, self.comp_action.id,))
|
||||||
|
|
||||||
|
self.deadline = Deadline.objects.get_or_create(
|
||||||
|
type=DeadlineType.FINISHED,
|
||||||
|
date="2020-01-01",
|
||||||
|
comment="DEADLINE COMMENT"
|
||||||
|
)[0]
|
||||||
|
self.eco_account.deadlines.add(self.deadline)
|
||||||
|
|
||||||
|
self.deadline_new_url = reverse("compensation:acc:new-deadline", args=(self.eco_account.id,))
|
||||||
|
self.deadline_edit_url = reverse("compensation:acc:deadline-edit", args=(self.eco_account.id, self.deadline.id))
|
||||||
|
self.deadline_remove_url = reverse("compensation:acc:deadline-remove", args=(self.eco_account.id, self.deadline.id))
|
||||||
|
|
||||||
|
self.new_doc_url = reverse("compensation:acc:new-doc", args=(self.eco_account.id,))
|
||||||
|
|
||||||
|
def test_logged_in_no_groups_shared(self):
|
||||||
|
""" Check correct status code for all requests
|
||||||
|
|
||||||
|
Assumption: User logged in and has no groups and data is shared
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
|
||||||
|
"""
|
||||||
|
client = Client()
|
||||||
|
client.login(username=self.superuser.username, password=self.superuser_pw)
|
||||||
|
self.superuser.groups.set([])
|
||||||
|
self.eco_account.share_with_user_list([self.superuser])
|
||||||
|
|
||||||
|
# Since the user has no groups, it does not matter that data has been shared. There SHOULD not be any difference
|
||||||
|
# to a user without access, since the important permissions are missing
|
||||||
|
success_urls = [
|
||||||
|
self.index_url,
|
||||||
|
self.detail_url,
|
||||||
|
self.report_url,
|
||||||
|
]
|
||||||
|
fail_urls = [
|
||||||
|
self.new_url,
|
||||||
|
self.new_id_url,
|
||||||
|
self.log_url,
|
||||||
|
self.edit_url,
|
||||||
|
self.remove_url,
|
||||||
|
self.state_new_url,
|
||||||
|
self.state_edit_url,
|
||||||
|
self.state_remove_url,
|
||||||
|
self.action_new_url,
|
||||||
|
self.action_edit_url,
|
||||||
|
self.action_remove_url,
|
||||||
|
self.deadline_new_url,
|
||||||
|
self.deadline_edit_url,
|
||||||
|
self.deadline_remove_url,
|
||||||
|
self.new_doc_url,
|
||||||
|
]
|
||||||
|
|
||||||
|
self.assert_url_success(client, success_urls)
|
||||||
|
self.assert_url_fail(client, fail_urls)
|
||||||
|
|
||||||
|
def test_logged_in_no_groups_unshared(self):
|
||||||
|
""" Check correct status code for all requests
|
||||||
|
|
||||||
|
Assumption: User logged in and has no groups and data is shared
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
|
||||||
|
"""
|
||||||
|
client = Client()
|
||||||
|
client.login(username=self.superuser.username, password=self.superuser_pw)
|
||||||
|
self.superuser.groups.set([])
|
||||||
|
self.eco_account.share_with_user_list([])
|
||||||
|
|
||||||
|
# Since the user has no groups, it does not matter that data is unshared. There SHOULD not be any difference
|
||||||
|
# to a user having shared access, since all important permissions are missing
|
||||||
|
success_urls = [
|
||||||
|
self.index_url,
|
||||||
|
self.detail_url,
|
||||||
|
self.report_url,
|
||||||
|
]
|
||||||
|
fail_urls = [
|
||||||
|
self.new_url,
|
||||||
|
self.new_id_url,
|
||||||
|
self.log_url,
|
||||||
|
self.edit_url,
|
||||||
|
self.remove_url,
|
||||||
|
self.state_new_url,
|
||||||
|
self.state_edit_url,
|
||||||
|
self.state_remove_url,
|
||||||
|
self.action_new_url,
|
||||||
|
self.action_edit_url,
|
||||||
|
self.action_remove_url,
|
||||||
|
self.deadline_new_url,
|
||||||
|
self.deadline_edit_url,
|
||||||
|
self.deadline_remove_url,
|
||||||
|
self.new_doc_url,
|
||||||
|
]
|
||||||
|
|
||||||
|
self.assert_url_success(client, success_urls)
|
||||||
|
self.assert_url_fail(client, fail_urls)
|
||||||
|
|
||||||
|
def test_logged_in_default_group_shared(self):
|
||||||
|
""" Check correct status code for all requests
|
||||||
|
|
||||||
|
Assumption: User logged in, is default group member and data is shared
|
||||||
|
--> Default group necessary since all base functionalities depend on this group membership
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
|
||||||
|
"""
|
||||||
|
client = Client()
|
||||||
|
client.login(username=self.superuser.username, password=self.superuser_pw)
|
||||||
|
group = self.groups.get(name=DEFAULT_GROUP)
|
||||||
|
self.superuser.groups.set([group])
|
||||||
|
# Sharing is inherited by base intervention for compensation. Therefore configure the interventions share state
|
||||||
|
self.eco_account.share_with_user_list([self.superuser])
|
||||||
|
|
||||||
|
success_urls = [
|
||||||
|
self.index_url,
|
||||||
|
self.detail_url,
|
||||||
|
self.report_url,
|
||||||
|
self.new_url,
|
||||||
|
self.new_id_url,
|
||||||
|
self.edit_url,
|
||||||
|
self.state_new_url,
|
||||||
|
self.state_edit_url,
|
||||||
|
self.state_remove_url,
|
||||||
|
self.action_new_url,
|
||||||
|
self.action_edit_url,
|
||||||
|
self.action_remove_url,
|
||||||
|
self.new_doc_url,
|
||||||
|
self.deadline_new_url,
|
||||||
|
self.deadline_edit_url,
|
||||||
|
self.deadline_remove_url,
|
||||||
|
self.log_url,
|
||||||
|
self.remove_url,
|
||||||
|
]
|
||||||
|
self.assert_url_success(client, success_urls)
|
||||||
|
|
||||||
|
def test_logged_in_default_group_unshared(self):
|
||||||
|
""" Check correct status code for all requests
|
||||||
|
|
||||||
|
Assumption: User logged in, is default group member and data is NOT shared
|
||||||
|
--> Default group necessary since all base functionalities depend on this group membership
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
|
||||||
|
"""
|
||||||
|
client = Client()
|
||||||
|
client.login(username=self.superuser.username, password=self.superuser_pw)
|
||||||
|
group = self.groups.get(name=DEFAULT_GROUP)
|
||||||
|
self.superuser.groups.set([group])
|
||||||
|
self.eco_account.share_with_user_list([])
|
||||||
|
|
||||||
|
success_urls = [
|
||||||
|
self.index_url,
|
||||||
|
self.detail_url,
|
||||||
|
self.report_url,
|
||||||
|
self.new_id_url,
|
||||||
|
self.new_url,
|
||||||
|
]
|
||||||
|
fail_urls = [
|
||||||
|
self.edit_url,
|
||||||
|
self.state_new_url,
|
||||||
|
self.state_edit_url,
|
||||||
|
self.state_remove_url,
|
||||||
|
self.action_new_url,
|
||||||
|
self.action_edit_url,
|
||||||
|
self.action_remove_url,
|
||||||
|
self.new_doc_url,
|
||||||
|
self.log_url,
|
||||||
|
self.remove_url,
|
||||||
|
self.deadline_new_url,
|
||||||
|
self.deadline_edit_url,
|
||||||
|
self.deadline_remove_url,
|
||||||
|
]
|
||||||
|
self.assert_url_fail(client, fail_urls)
|
||||||
|
self.assert_url_success(client, success_urls)
|
||||||
|
|
||||||
329
compensation/tests/ecoaccount/test_workflow.py
Normal file
329
compensation/tests/ecoaccount/test_workflow.py
Normal file
@@ -0,0 +1,329 @@
|
|||||||
|
"""
|
||||||
|
Author: Michel Peltriaux
|
||||||
|
Organization: Struktur- und Genehmigungsdirektion Nord, Rhineland-Palatinate, Germany
|
||||||
|
Contact: michel.peltriaux@sgdnord.rlp.de
|
||||||
|
Created on: 11.11.21
|
||||||
|
|
||||||
|
"""
|
||||||
|
import datetime
|
||||||
|
|
||||||
|
from django.contrib.gis.geos import MultiPolygon
|
||||||
|
from django.core.exceptions import ObjectDoesNotExist
|
||||||
|
from django.urls import reverse
|
||||||
|
|
||||||
|
from compensation.models import EcoAccount, EcoAccountDeduction
|
||||||
|
from konova.settings import ETS_GROUP, DEFAULT_GROUP
|
||||||
|
from konova.tests.test_views import BaseWorkflowTestCase
|
||||||
|
from user.models import UserAction
|
||||||
|
|
||||||
|
|
||||||
|
class EcoAccountWorkflowTestCase(BaseWorkflowTestCase):
|
||||||
|
@classmethod
|
||||||
|
def setUpTestData(cls):
|
||||||
|
super().setUpTestData()
|
||||||
|
|
||||||
|
def setUp(self) -> None:
|
||||||
|
super().setUp()
|
||||||
|
# Add user to conservation office group and give shared access to the account
|
||||||
|
self.superuser.groups.add(self.groups.get(name=DEFAULT_GROUP))
|
||||||
|
self.superuser.groups.add(self.groups.get(name=ETS_GROUP))
|
||||||
|
self.eco_account.share_with_user_list([self.superuser])
|
||||||
|
|
||||||
|
def test_new(self):
|
||||||
|
""" Test the creation of an EcoAccount
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
|
||||||
|
"""
|
||||||
|
# Prepare url and form data to be posted
|
||||||
|
new_url = reverse("compensation:acc:new")
|
||||||
|
test_id = self.create_dummy_string()
|
||||||
|
test_title = self.create_dummy_string()
|
||||||
|
test_geom = self.create_dummy_geometry()
|
||||||
|
geom_json = self.create_geojson(test_geom)
|
||||||
|
test_deductable_surface = 1000
|
||||||
|
test_conservation_office = self.get_conservation_office_code()
|
||||||
|
post_data = {
|
||||||
|
"identifier": test_id,
|
||||||
|
"title": test_title,
|
||||||
|
"geom": geom_json,
|
||||||
|
"deductable_surface": test_deductable_surface,
|
||||||
|
"conservation_office": test_conservation_office.id
|
||||||
|
}
|
||||||
|
self.client_user.post(new_url, post_data)
|
||||||
|
|
||||||
|
try:
|
||||||
|
acc = EcoAccount.objects.get(
|
||||||
|
identifier=test_id
|
||||||
|
)
|
||||||
|
except ObjectDoesNotExist:
|
||||||
|
self.fail(msg="EcoAccount not created")
|
||||||
|
|
||||||
|
self.assertEqual(acc.identifier, test_id)
|
||||||
|
self.assertEqual(acc.title, test_title)
|
||||||
|
self.assert_equal_geometries(acc.geometry.geom, test_geom)
|
||||||
|
self.assertEqual(acc.log.count(), 1)
|
||||||
|
|
||||||
|
# Expect logs to be set
|
||||||
|
self.assertEqual(acc.log.count(), 1)
|
||||||
|
self.assertEqual(acc.log.first().action, UserAction.CREATED)
|
||||||
|
|
||||||
|
def test_edit(self):
|
||||||
|
""" Checks that the editing of an EcoAccount works
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
|
||||||
|
"""
|
||||||
|
self.eco_account.share_with_user(self.superuser)
|
||||||
|
|
||||||
|
url = reverse("compensation:acc:edit", args=(self.eco_account.id,))
|
||||||
|
pre_edit_log_count = self.eco_account.log.count()
|
||||||
|
|
||||||
|
new_title = self.create_dummy_string()
|
||||||
|
new_identifier = self.create_dummy_string()
|
||||||
|
new_comment = self.create_dummy_string()
|
||||||
|
new_geometry = MultiPolygon(srid=4326) # Create an empty geometry
|
||||||
|
test_conservation_office = self.get_conservation_office_code()
|
||||||
|
test_deductable_surface = 10005
|
||||||
|
|
||||||
|
check_on_elements = {
|
||||||
|
self.eco_account.title: new_title,
|
||||||
|
self.eco_account.identifier: new_identifier,
|
||||||
|
self.eco_account.comment: new_comment,
|
||||||
|
self.eco_account.deductable_surface: test_deductable_surface,
|
||||||
|
}
|
||||||
|
for k, v in check_on_elements.items():
|
||||||
|
self.assertNotEqual(k, v)
|
||||||
|
|
||||||
|
post_data = {
|
||||||
|
"identifier": new_identifier,
|
||||||
|
"title": new_title,
|
||||||
|
"comment": new_comment,
|
||||||
|
"geom": new_geometry.geojson,
|
||||||
|
"surface": test_deductable_surface,
|
||||||
|
"conservation_office": test_conservation_office.id
|
||||||
|
}
|
||||||
|
self.client_user.post(url, post_data)
|
||||||
|
self.eco_account.refresh_from_db()
|
||||||
|
|
||||||
|
check_on_elements = {
|
||||||
|
self.eco_account.title: new_title,
|
||||||
|
self.eco_account.identifier: new_identifier,
|
||||||
|
self.eco_account.deductable_surface: test_deductable_surface,
|
||||||
|
self.eco_account.comment: new_comment,
|
||||||
|
}
|
||||||
|
|
||||||
|
for k, v in check_on_elements.items():
|
||||||
|
self.assertEqual(k, v)
|
||||||
|
|
||||||
|
self.assert_equal_geometries(self.eco_account.geometry.geom, new_geometry)
|
||||||
|
|
||||||
|
# Expect logs to be set
|
||||||
|
self.assertEqual(pre_edit_log_count + 1, self.eco_account.log.count())
|
||||||
|
self.assertEqual(self.eco_account.log.first().action, UserAction.EDITED)
|
||||||
|
|
||||||
|
def test_recordability(self):
|
||||||
|
"""
|
||||||
|
This tests if the recordability of the EcoAccount is triggered by the quality of it's data (e.g. not all fields filled)
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
|
||||||
|
"""
|
||||||
|
# Add proper privilege for the user
|
||||||
|
self.eco_account.share_with_user(self.superuser)
|
||||||
|
pre_record_log_count = self.eco_account.log.count()
|
||||||
|
|
||||||
|
# Prepare url and form data
|
||||||
|
record_url = reverse("compensation:acc:record", args=(self.eco_account.id,))
|
||||||
|
post_data = {
|
||||||
|
"confirm": True,
|
||||||
|
}
|
||||||
|
self.eco_account.refresh_from_db()
|
||||||
|
|
||||||
|
# Make sure the account is not recorded
|
||||||
|
self.assertIsNone(self.eco_account.recorded)
|
||||||
|
|
||||||
|
# Run the request --> expect fail, since the account is not valid, yet
|
||||||
|
self.client_user.post(record_url, post_data)
|
||||||
|
|
||||||
|
# Check that the account is still not recorded
|
||||||
|
self.assertIsNone(self.eco_account.recorded)
|
||||||
|
|
||||||
|
# Now fill out the data for an ecoaccount
|
||||||
|
self.eco_account = self.fill_out_eco_account(self.eco_account)
|
||||||
|
|
||||||
|
# Rerun the request
|
||||||
|
self.client_user.post(record_url, post_data)
|
||||||
|
|
||||||
|
# Expect the EcoAccount now to be recorded
|
||||||
|
# Attention: We can only test the date part of the timestamp,
|
||||||
|
# since the delay in microseconds would lead to fail
|
||||||
|
self.eco_account.refresh_from_db()
|
||||||
|
recorded = self.eco_account.recorded
|
||||||
|
self.assertIsNotNone(recorded)
|
||||||
|
self.assertEqual(self.superuser, recorded.user)
|
||||||
|
self.assertEqual(UserAction.RECORDED, recorded.action)
|
||||||
|
self.assertEqual(datetime.date.today(), recorded.timestamp.date())
|
||||||
|
|
||||||
|
# Expect the user action to be in the log
|
||||||
|
self.assertIn(recorded, self.eco_account.log.all())
|
||||||
|
self.assertEqual(pre_record_log_count + 1, self.eco_account.log.count())
|
||||||
|
|
||||||
|
def test_new_deduction(self):
|
||||||
|
"""
|
||||||
|
This tests the deductability of an eco account.
|
||||||
|
|
||||||
|
An eco account should only be deductible if it is recorded.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
|
||||||
|
"""
|
||||||
|
# Give user shared access to the dummy intervention, which will be needed here
|
||||||
|
self.intervention.share_with_user(self.superuser)
|
||||||
|
pre_deduction_acc_log_count = self.eco_account.log.count()
|
||||||
|
pre_deduction_int_log_count = self.intervention.log.count()
|
||||||
|
|
||||||
|
# Prepare data for deduction creation
|
||||||
|
deduct_url = reverse("compensation:acc:new-deduction", args=(self.eco_account.id,))
|
||||||
|
test_surface = 10.00
|
||||||
|
post_data = {
|
||||||
|
"surface": test_surface,
|
||||||
|
"account": self.eco_account.id,
|
||||||
|
"intervention": self.intervention.id,
|
||||||
|
}
|
||||||
|
# Perform request --> expect to fail
|
||||||
|
self.client_user.post(deduct_url, post_data)
|
||||||
|
|
||||||
|
# Expect that no deduction has been created
|
||||||
|
self.assertEqual(0, self.eco_account.deductions.count())
|
||||||
|
self.assertEqual(0, self.intervention.deductions.count())
|
||||||
|
self.assertEqual(pre_deduction_acc_log_count, 0)
|
||||||
|
self.assertEqual(pre_deduction_int_log_count, 0)
|
||||||
|
|
||||||
|
# Now mock the eco account as it would be recorded (with invalid data)
|
||||||
|
# Make sure the deductible surface is high enough for the request
|
||||||
|
self.eco_account.set_recorded(self.superuser)
|
||||||
|
self.eco_account.refresh_from_db()
|
||||||
|
self.eco_account.deductable_surface = test_surface + 1.00
|
||||||
|
self.eco_account.save()
|
||||||
|
self.assertIsNotNone(self.eco_account.recorded)
|
||||||
|
self.assertGreater(self.eco_account.deductable_surface, test_surface)
|
||||||
|
# Expect the recorded entry in the log
|
||||||
|
self.assertEqual(pre_deduction_acc_log_count + 1, self.eco_account.log.count())
|
||||||
|
self.assertTrue(self.eco_account.log.first().action == UserAction.RECORDED)
|
||||||
|
|
||||||
|
# Rerun the request
|
||||||
|
self.client_user.post(deduct_url, post_data)
|
||||||
|
|
||||||
|
# Expect that the deduction has been created
|
||||||
|
self.assertEqual(1, self.eco_account.deductions.count())
|
||||||
|
self.assertEqual(1, self.intervention.deductions.count())
|
||||||
|
deduction = self.eco_account.deductions.first()
|
||||||
|
self.assertEqual(deduction.surface, test_surface)
|
||||||
|
self.assertEqual(deduction.account, self.eco_account)
|
||||||
|
self.assertEqual(deduction.intervention, self.intervention)
|
||||||
|
|
||||||
|
# Expect entries in the log
|
||||||
|
self.assertEqual(pre_deduction_acc_log_count + 2, self.eco_account.log.count())
|
||||||
|
self.assertTrue(self.eco_account.log.first().action == UserAction.EDITED)
|
||||||
|
self.assertEqual(pre_deduction_int_log_count + 1, self.intervention.log.count())
|
||||||
|
self.assertTrue(self.intervention.log.first().action == UserAction.EDITED)
|
||||||
|
|
||||||
|
def test_edit_deduction(self):
|
||||||
|
test_surface = self.eco_account.get_available_rest()[0]
|
||||||
|
self.eco_account.set_recorded(self.superuser)
|
||||||
|
self.intervention.share_with_user(self.superuser)
|
||||||
|
self.eco_account.refresh_from_db()
|
||||||
|
self.assertTrue(self.superuser, self.intervention.is_shared_with(self.superuser))
|
||||||
|
|
||||||
|
deduction = EcoAccountDeduction.objects.create(
|
||||||
|
intervention=self.intervention,
|
||||||
|
account=self.eco_account,
|
||||||
|
surface=0
|
||||||
|
)
|
||||||
|
self.assertEqual(1, self.intervention.deductions.count())
|
||||||
|
self.assertEqual(1, self.eco_account.deductions.count())
|
||||||
|
|
||||||
|
# Prepare url and form data to be posted
|
||||||
|
new_url = reverse("compensation:acc:edit-deduction", args=(self.eco_account.id, deduction.id))
|
||||||
|
post_data = {
|
||||||
|
"intervention": deduction.intervention.id,
|
||||||
|
"account": deduction.account.id,
|
||||||
|
"surface": test_surface,
|
||||||
|
}
|
||||||
|
pre_edit_intervention_log_count = self.intervention.log.count()
|
||||||
|
pre_edit_account_log_count = self.eco_account.log.count()
|
||||||
|
num_deductions_intervention = self.intervention.deductions.count()
|
||||||
|
num_deductions_account = self.eco_account.deductions.count()
|
||||||
|
|
||||||
|
self.client_user.post(new_url, post_data)
|
||||||
|
|
||||||
|
self.intervention.refresh_from_db()
|
||||||
|
self.eco_account.refresh_from_db()
|
||||||
|
deduction.refresh_from_db()
|
||||||
|
|
||||||
|
self.assertEqual(num_deductions_intervention, self.intervention.deductions.count())
|
||||||
|
self.assertEqual(num_deductions_account, self.eco_account.deductions.count())
|
||||||
|
self.assertEqual(deduction.surface, test_surface)
|
||||||
|
|
||||||
|
# Expect logs to be set
|
||||||
|
self.assertEqual(pre_edit_intervention_log_count + 1, self.intervention.log.count())
|
||||||
|
self.assertEqual(pre_edit_account_log_count + 1, self.eco_account.log.count())
|
||||||
|
self.assertEqual(self.intervention.log.first().action, UserAction.EDITED)
|
||||||
|
self.assertEqual(self.eco_account.log.first().action, UserAction.EDITED)
|
||||||
|
|
||||||
|
def test_remove_deduction(self):
|
||||||
|
intervention = self.deduction.intervention
|
||||||
|
account = self.deduction.account
|
||||||
|
|
||||||
|
# Prepare url and form data to be posted
|
||||||
|
new_url = reverse("compensation:acc:remove-deduction", args=(account.id, self.deduction.id))
|
||||||
|
post_data = {
|
||||||
|
"confirm": True,
|
||||||
|
}
|
||||||
|
|
||||||
|
intervention.share_with_user(self.superuser)
|
||||||
|
account.share_with_user(self.superuser)
|
||||||
|
|
||||||
|
pre_edit_intervention_log_count = intervention.log.count()
|
||||||
|
pre_edit_account_log_count = account.log.count()
|
||||||
|
num_deductions_intervention = intervention.deductions.count()
|
||||||
|
num_deductions_account = account.deductions.count()
|
||||||
|
|
||||||
|
self.client_user.post(new_url, post_data)
|
||||||
|
|
||||||
|
intervention.refresh_from_db()
|
||||||
|
account.refresh_from_db()
|
||||||
|
|
||||||
|
self.assertEqual(num_deductions_intervention - 1, intervention.deductions.count())
|
||||||
|
self.assertEqual(num_deductions_account - 1, account.deductions.count())
|
||||||
|
|
||||||
|
# Expect logs to be set
|
||||||
|
self.assertEqual(pre_edit_intervention_log_count + 1, intervention.log.count())
|
||||||
|
self.assertEqual(pre_edit_account_log_count + 1, account.log.count())
|
||||||
|
self.assertEqual(intervention.log.first().action, UserAction.EDITED)
|
||||||
|
self.assertEqual(account.log.first().action, UserAction.EDITED)
|
||||||
|
|
||||||
|
def test_non_editable_after_recording(self):
|
||||||
|
""" Tests that the eco_account can not be edited after being recorded
|
||||||
|
|
||||||
|
User must be redirected to another page
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
|
||||||
|
"""
|
||||||
|
self.assertIsNotNone(self.eco_account)
|
||||||
|
self.assertFalse(self.eco_account.is_recorded)
|
||||||
|
edit_url = reverse("compensation:acc:edit", args=(self.eco_account.id,))
|
||||||
|
response = self.client_user.get(edit_url)
|
||||||
|
has_redirect = response.status_code == 302
|
||||||
|
self.assertFalse(has_redirect)
|
||||||
|
|
||||||
|
self.eco_account.set_recorded(self.user)
|
||||||
|
self.assertTrue(self.eco_account.is_recorded)
|
||||||
|
|
||||||
|
edit_url = reverse("compensation:acc:edit", args=(self.eco_account.id,))
|
||||||
|
response = self.client_user.get(edit_url)
|
||||||
|
has_redirect = response.status_code == 302
|
||||||
|
self.assertTrue(has_redirect)
|
||||||
|
self.eco_account.set_unrecorded(self.user)
|
||||||
7
compensation/tests/payment/__init__.py
Normal file
7
compensation/tests/payment/__init__.py
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
"""
|
||||||
|
Author: Michel Peltriaux
|
||||||
|
Organization: Struktur- und Genehmigungsdirektion Nord, Rhineland-Palatinate, Germany
|
||||||
|
Contact: michel.peltriaux@sgdnord.rlp.de
|
||||||
|
Created on: 09.02.22
|
||||||
|
|
||||||
|
"""
|
||||||
156
compensation/tests/payment/test_views.py
Normal file
156
compensation/tests/payment/test_views.py
Normal file
@@ -0,0 +1,156 @@
|
|||||||
|
"""
|
||||||
|
Author: Michel Peltriaux
|
||||||
|
Organization: Struktur- und Genehmigungsdirektion Nord, Rhineland-Palatinate, Germany
|
||||||
|
Contact: michel.peltriaux@sgdnord.rlp.de
|
||||||
|
Created on: 09.02.22
|
||||||
|
|
||||||
|
"""
|
||||||
|
from django.urls import reverse
|
||||||
|
from django.test.client import Client
|
||||||
|
|
||||||
|
from compensation.models import Payment
|
||||||
|
from konova.settings import DEFAULT_GROUP
|
||||||
|
from konova.tests.test_views import BaseViewTestCase
|
||||||
|
|
||||||
|
|
||||||
|
class PaymentViewTestCase(BaseViewTestCase):
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def setUpTestData(cls) -> None:
|
||||||
|
super().setUpTestData()
|
||||||
|
|
||||||
|
def setUp(self) -> None:
|
||||||
|
super().setUp()
|
||||||
|
self.payment = Payment.objects.get_or_create(
|
||||||
|
intervention=self.intervention,
|
||||||
|
amount=1,
|
||||||
|
due_on="2020-01-01",
|
||||||
|
comment="Testcomment"
|
||||||
|
)[0]
|
||||||
|
|
||||||
|
self.new_url = reverse("compensation:pay:new", args=(self.intervention.id,))
|
||||||
|
self.edit_url = reverse("compensation:pay:edit", args=(self.intervention.id, self.payment.id))
|
||||||
|
self.remove_url = reverse("compensation:pay:remove", args=(self.intervention.id, self.payment.id))
|
||||||
|
|
||||||
|
def test_anonymous_user(self):
|
||||||
|
""" Check correct status code for all requests
|
||||||
|
|
||||||
|
Assumption: User not logged in
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
|
||||||
|
"""
|
||||||
|
client = Client()
|
||||||
|
|
||||||
|
success_urls = [
|
||||||
|
]
|
||||||
|
fail_urls = [
|
||||||
|
self.new_url,
|
||||||
|
self.edit_url,
|
||||||
|
self.remove_url,
|
||||||
|
]
|
||||||
|
|
||||||
|
self.assert_url_success(client, success_urls)
|
||||||
|
self.assert_url_fail(client, fail_urls)
|
||||||
|
|
||||||
|
def test_logged_in_no_groups_shared(self):
|
||||||
|
""" Check correct status code for all requests
|
||||||
|
|
||||||
|
Assumption: User logged in and has no groups and data is shared
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
|
||||||
|
"""
|
||||||
|
client = Client()
|
||||||
|
client.login(username=self.superuser.username, password=self.superuser_pw)
|
||||||
|
self.superuser.groups.set([])
|
||||||
|
self.intervention.share_with_user_list([self.superuser])
|
||||||
|
|
||||||
|
# Since the user has no groups, it does not matter that data has been shared. There SHOULD not be any difference
|
||||||
|
# to a user without access, since the important permissions are missing
|
||||||
|
success_urls = [
|
||||||
|
]
|
||||||
|
fail_urls = [
|
||||||
|
self.new_url,
|
||||||
|
self.edit_url,
|
||||||
|
self.remove_url,
|
||||||
|
]
|
||||||
|
|
||||||
|
self.assert_url_success(client, success_urls)
|
||||||
|
self.assert_url_fail(client, fail_urls)
|
||||||
|
|
||||||
|
def test_logged_in_no_groups_unshared(self):
|
||||||
|
""" Check correct status code for all requests
|
||||||
|
|
||||||
|
Assumption: User logged in and has no groups and data is not shared
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
|
||||||
|
"""
|
||||||
|
client = Client()
|
||||||
|
client.login(username=self.superuser.username, password=self.superuser_pw)
|
||||||
|
self.superuser.groups.set([])
|
||||||
|
# Sharing is inherited by base intervention for compensation. Therefore configure the interventions share state
|
||||||
|
self.intervention.share_with_user_list([])
|
||||||
|
|
||||||
|
# Since the user has no groups, it does not matter that data is unshared. There SHOULD not be any difference
|
||||||
|
# to a user having shared access, since all important permissions are missing
|
||||||
|
success_urls = [
|
||||||
|
]
|
||||||
|
fail_urls = [
|
||||||
|
self.new_url,
|
||||||
|
self.edit_url,
|
||||||
|
self.remove_url,
|
||||||
|
]
|
||||||
|
|
||||||
|
self.assert_url_success(client, success_urls)
|
||||||
|
self.assert_url_fail(client, fail_urls)
|
||||||
|
|
||||||
|
def test_logged_in_default_group_shared(self):
|
||||||
|
""" Check correct status code for all requests
|
||||||
|
|
||||||
|
Assumption: User logged in, is default group member and data is shared
|
||||||
|
--> Default group necessary since all base functionalities depend on this group membership
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
|
||||||
|
"""
|
||||||
|
client = Client()
|
||||||
|
client.login(username=self.superuser.username, password=self.superuser_pw)
|
||||||
|
group = self.groups.get(name=DEFAULT_GROUP)
|
||||||
|
self.superuser.groups.set([group])
|
||||||
|
# Sharing is inherited by base intervention for compensation. Therefore configure the interventions share state
|
||||||
|
self.intervention.share_with_user_list([self.superuser])
|
||||||
|
|
||||||
|
success_urls = [
|
||||||
|
self.new_url,
|
||||||
|
self.edit_url,
|
||||||
|
self.remove_url,
|
||||||
|
]
|
||||||
|
self.assert_url_success(client, success_urls)
|
||||||
|
|
||||||
|
def test_logged_in_default_group_unshared(self):
|
||||||
|
""" Check correct status code for all requests
|
||||||
|
|
||||||
|
Assumption: User logged in, is default group member and data is NOT shared
|
||||||
|
--> Default group necessary since all base functionalities depend on this group membership
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
|
||||||
|
"""
|
||||||
|
client = Client()
|
||||||
|
client.login(username=self.superuser.username, password=self.superuser_pw)
|
||||||
|
group = self.groups.get(name=DEFAULT_GROUP)
|
||||||
|
self.superuser.groups.set([group])
|
||||||
|
# Sharing is inherited by base intervention for compensation. Therefore configure the interventions share state
|
||||||
|
self.intervention.share_with_user_list([])
|
||||||
|
|
||||||
|
success_urls = [
|
||||||
|
]
|
||||||
|
fail_urls = [
|
||||||
|
self.new_url,
|
||||||
|
self.edit_url,
|
||||||
|
self.remove_url,
|
||||||
|
]
|
||||||
|
self.assert_url_fail(client, fail_urls)
|
||||||
|
self.assert_url_success(client, success_urls)
|
||||||
127
compensation/tests/payment/test_workflow.py
Normal file
127
compensation/tests/payment/test_workflow.py
Normal file
@@ -0,0 +1,127 @@
|
|||||||
|
"""
|
||||||
|
Author: Michel Peltriaux
|
||||||
|
Organization: Struktur- und Genehmigungsdirektion Nord, Rhineland-Palatinate, Germany
|
||||||
|
Contact: michel.peltriaux@sgdnord.rlp.de
|
||||||
|
Created on: 09.02.22
|
||||||
|
|
||||||
|
"""
|
||||||
|
from django.core.exceptions import ObjectDoesNotExist
|
||||||
|
from django.urls import reverse
|
||||||
|
|
||||||
|
from compensation.models import Payment
|
||||||
|
from konova.tests.test_views import BaseWorkflowTestCase
|
||||||
|
from user.models import UserAction
|
||||||
|
|
||||||
|
|
||||||
|
class PaymentWorkflowTestCase(BaseWorkflowTestCase):
|
||||||
|
@classmethod
|
||||||
|
def setUpTestData(cls):
|
||||||
|
super().setUpTestData()
|
||||||
|
|
||||||
|
def setUp(self) -> None:
|
||||||
|
super().setUp()
|
||||||
|
# Give the user shared access to the dummy intervention
|
||||||
|
self.intervention.share_with_user(self.superuser)
|
||||||
|
|
||||||
|
self.payment = Payment.objects.get_or_create(
|
||||||
|
intervention=self.intervention,
|
||||||
|
amount=1,
|
||||||
|
due_on="2020-01-01",
|
||||||
|
comment="Testcomment"
|
||||||
|
)[0]
|
||||||
|
|
||||||
|
def test_new(self):
|
||||||
|
""" Test the creation of a payment
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
|
||||||
|
"""
|
||||||
|
# Prepare url and form data to be posted
|
||||||
|
new_url = reverse("compensation:pay:new", args=(self.intervention.id,))
|
||||||
|
test_amount = 12345
|
||||||
|
test_due_on = "1970-01-01"
|
||||||
|
test_comment = self.create_dummy_string()
|
||||||
|
post_data = {
|
||||||
|
"amount": test_amount,
|
||||||
|
"due": test_due_on,
|
||||||
|
"comment": test_comment,
|
||||||
|
}
|
||||||
|
pre_creation_intervention_log_count = self.intervention.log.count()
|
||||||
|
num_payments = self.intervention.payments.count()
|
||||||
|
|
||||||
|
self.client_user.post(new_url, post_data)
|
||||||
|
|
||||||
|
self.intervention.refresh_from_db()
|
||||||
|
|
||||||
|
self.assertEqual(num_payments + 1, self.intervention.payments.count())
|
||||||
|
new_payment = self.intervention.payments.get(amount=test_amount)
|
||||||
|
self.assertEqual(new_payment.amount, test_amount)
|
||||||
|
self.assertEqual(str(new_payment.due_on), test_due_on)
|
||||||
|
self.assertEqual(new_payment.comment, test_comment)
|
||||||
|
|
||||||
|
# Expect logs to be set
|
||||||
|
self.assertEqual(pre_creation_intervention_log_count + 1, self.intervention.log.count())
|
||||||
|
self.assertEqual(self.intervention.log.first().action, UserAction.EDITED)
|
||||||
|
|
||||||
|
def test_edit(self):
|
||||||
|
""" Test edit of a payment
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
|
||||||
|
"""
|
||||||
|
# Prepare url and form data to be posted
|
||||||
|
new_url = reverse("compensation:pay:edit", args=(self.intervention.id, self.payment.id))
|
||||||
|
test_amount = self.payment.amount * 2
|
||||||
|
test_due_on = "1970-01-01"
|
||||||
|
test_comment = self.create_dummy_string()
|
||||||
|
post_data = {
|
||||||
|
"amount": test_amount,
|
||||||
|
"due": test_due_on,
|
||||||
|
"comment": test_comment,
|
||||||
|
}
|
||||||
|
pre_edit_intervention_log_count = self.intervention.log.count()
|
||||||
|
num_payments = self.intervention.payments.count()
|
||||||
|
|
||||||
|
self.client_user.post(new_url, post_data)
|
||||||
|
|
||||||
|
self.intervention.refresh_from_db()
|
||||||
|
self.payment.refresh_from_db()
|
||||||
|
|
||||||
|
self.assertEqual(num_payments, self.intervention.payments.count())
|
||||||
|
self.assertEqual(self.payment.amount, test_amount)
|
||||||
|
self.assertEqual(str(self.payment.due_on), test_due_on)
|
||||||
|
self.assertEqual(self.payment.comment, test_comment)
|
||||||
|
|
||||||
|
# Expect logs to be set
|
||||||
|
self.assertEqual(pre_edit_intervention_log_count + 1, self.intervention.log.count())
|
||||||
|
self.assertEqual(self.intervention.log.first().action, UserAction.EDITED)
|
||||||
|
|
||||||
|
def test_remove(self):
|
||||||
|
""" Test remove of a payment
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
|
||||||
|
"""
|
||||||
|
# Prepare url and form data to be posted
|
||||||
|
new_url = reverse("compensation:pay:remove", args=(self.intervention.id, self.payment.id))
|
||||||
|
post_data = {
|
||||||
|
"confirm": True,
|
||||||
|
}
|
||||||
|
pre_remove_intervention_log_count = self.intervention.log.count()
|
||||||
|
num_payments = self.intervention.payments.count()
|
||||||
|
|
||||||
|
self.client_user.post(new_url, post_data)
|
||||||
|
|
||||||
|
self.intervention.refresh_from_db()
|
||||||
|
try:
|
||||||
|
self.payment.refresh_from_db()
|
||||||
|
self.fail(msg="Payment still exists after delete")
|
||||||
|
except ObjectDoesNotExist:
|
||||||
|
pass
|
||||||
|
|
||||||
|
self.assertEqual(num_payments - 1, self.intervention.payments.count())
|
||||||
|
|
||||||
|
# Expect logs to be set
|
||||||
|
self.assertEqual(pre_remove_intervention_log_count + 1, self.intervention.log.count())
|
||||||
|
self.assertEqual(self.intervention.log.first().action, UserAction.EDITED)
|
||||||
|
|
||||||
@@ -1,406 +0,0 @@
|
|||||||
"""
|
|
||||||
Author: Michel Peltriaux
|
|
||||||
Organization: Struktur- und Genehmigungsdirektion Nord, Rhineland-Palatinate, Germany
|
|
||||||
Contact: michel.peltriaux@sgdnord.rlp.de
|
|
||||||
Created on: 27.10.21
|
|
||||||
|
|
||||||
"""
|
|
||||||
from django.urls import reverse
|
|
||||||
from django.test import Client
|
|
||||||
|
|
||||||
from konova.settings import DEFAULT_GROUP
|
|
||||||
from konova.tests.test_views import BaseViewTestCase
|
|
||||||
|
|
||||||
|
|
||||||
class CompensationViewTestCase(BaseViewTestCase):
|
|
||||||
"""
|
|
||||||
These tests focus on proper returned views depending on the user's groups privileges and login status
|
|
||||||
|
|
||||||
"""
|
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def setUpTestData(cls) -> None:
|
|
||||||
super().setUpTestData()
|
|
||||||
state = cls.create_dummy_states()
|
|
||||||
cls.compensation.before_states.set([state])
|
|
||||||
cls.compensation.after_states.set([state])
|
|
||||||
|
|
||||||
action = cls.create_dummy_action()
|
|
||||||
cls.compensation.actions.set([action])
|
|
||||||
|
|
||||||
# Prepare urls
|
|
||||||
cls.index_url = reverse("compensation:index", args=())
|
|
||||||
cls.new_url = reverse("compensation:new", args=(cls.intervention.id,))
|
|
||||||
cls.new_id_url = reverse("compensation:new-id", args=())
|
|
||||||
cls.detail_url = reverse("compensation:detail", args=(cls.compensation.id,))
|
|
||||||
cls.log_url = reverse("compensation:log", args=(cls.compensation.id,))
|
|
||||||
cls.edit_url = reverse("compensation:edit", args=(cls.compensation.id,))
|
|
||||||
cls.remove_url = reverse("compensation:remove", args=(cls.compensation.id,))
|
|
||||||
cls.report_url = reverse("compensation:report", args=(cls.compensation.id,))
|
|
||||||
cls.state_new_url = reverse("compensation:new-state", args=(cls.compensation.id,))
|
|
||||||
cls.action_new_url = reverse("compensation:new-action", args=(cls.compensation.id,))
|
|
||||||
cls.deadline_new_url = reverse("compensation:new-deadline", args=(cls.compensation.id,))
|
|
||||||
cls.new_doc_url = reverse("compensation:new-doc", args=(cls.compensation.id,))
|
|
||||||
|
|
||||||
cls.state_remove_url = reverse("compensation:state-remove", args=(cls.compensation.id, cls.comp_state.id,))
|
|
||||||
cls.action_remove_url = reverse("compensation:action-remove", args=(cls.compensation.id, cls.comp_action.id,))
|
|
||||||
|
|
||||||
def test_anonymous_user(self):
|
|
||||||
""" Check correct status code for all requests
|
|
||||||
|
|
||||||
Assumption: User not logged in
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
|
|
||||||
"""
|
|
||||||
client = Client()
|
|
||||||
|
|
||||||
success_urls = [
|
|
||||||
self.report_url,
|
|
||||||
]
|
|
||||||
fail_urls = [
|
|
||||||
self.index_url,
|
|
||||||
self.detail_url,
|
|
||||||
self.new_url,
|
|
||||||
self.new_id_url,
|
|
||||||
self.log_url,
|
|
||||||
self.edit_url,
|
|
||||||
self.remove_url,
|
|
||||||
self.state_new_url,
|
|
||||||
self.action_new_url,
|
|
||||||
self.deadline_new_url,
|
|
||||||
self.state_remove_url,
|
|
||||||
self.action_remove_url,
|
|
||||||
self.new_doc_url,
|
|
||||||
]
|
|
||||||
|
|
||||||
self.assert_url_success(client, success_urls)
|
|
||||||
self.assert_url_fail(client, fail_urls)
|
|
||||||
|
|
||||||
def test_logged_in_no_groups_shared(self):
|
|
||||||
""" Check correct status code for all requests
|
|
||||||
|
|
||||||
Assumption: User logged in and has no groups and data is shared
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
|
|
||||||
"""
|
|
||||||
client = Client()
|
|
||||||
client.login(username=self.superuser.username, password=self.superuser_pw)
|
|
||||||
self.superuser.groups.set([])
|
|
||||||
self.intervention.share_with_list([self.superuser])
|
|
||||||
|
|
||||||
# Since the user has no groups, it does not matter that data has been shared. There SHOULD not be any difference
|
|
||||||
# to a user without access, since the important permissions are missing
|
|
||||||
success_urls = [
|
|
||||||
self.index_url,
|
|
||||||
self.detail_url,
|
|
||||||
self.report_url,
|
|
||||||
]
|
|
||||||
fail_urls = [
|
|
||||||
self.new_url,
|
|
||||||
self.new_id_url,
|
|
||||||
self.log_url,
|
|
||||||
self.edit_url,
|
|
||||||
self.remove_url,
|
|
||||||
self.state_new_url,
|
|
||||||
self.action_new_url,
|
|
||||||
self.deadline_new_url,
|
|
||||||
self.state_remove_url,
|
|
||||||
self.action_remove_url,
|
|
||||||
self.new_doc_url,
|
|
||||||
]
|
|
||||||
|
|
||||||
self.assert_url_success(client, success_urls)
|
|
||||||
self.assert_url_fail(client, fail_urls)
|
|
||||||
|
|
||||||
def test_logged_in_no_groups_unshared(self):
|
|
||||||
""" Check correct status code for all requests
|
|
||||||
|
|
||||||
Assumption: User logged in and has no groups and data is shared
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
|
|
||||||
"""
|
|
||||||
client = Client()
|
|
||||||
client.login(username=self.superuser.username, password=self.superuser_pw)
|
|
||||||
self.superuser.groups.set([])
|
|
||||||
# Sharing is inherited by base intervention for compensation. Therefore configure the interventions share state
|
|
||||||
self.intervention.share_with_list([])
|
|
||||||
|
|
||||||
# Since the user has no groups, it does not matter that data is unshared. There SHOULD not be any difference
|
|
||||||
# to a user having shared access, since all important permissions are missing
|
|
||||||
success_urls = [
|
|
||||||
self.index_url,
|
|
||||||
self.detail_url,
|
|
||||||
self.report_url,
|
|
||||||
]
|
|
||||||
fail_urls = [
|
|
||||||
self.new_url,
|
|
||||||
self.new_id_url,
|
|
||||||
self.log_url,
|
|
||||||
self.edit_url,
|
|
||||||
self.remove_url,
|
|
||||||
self.state_new_url,
|
|
||||||
self.action_new_url,
|
|
||||||
self.deadline_new_url,
|
|
||||||
self.state_remove_url,
|
|
||||||
self.action_remove_url,
|
|
||||||
self.new_doc_url,
|
|
||||||
]
|
|
||||||
|
|
||||||
self.assert_url_success(client, success_urls)
|
|
||||||
self.assert_url_fail(client, fail_urls)
|
|
||||||
|
|
||||||
def test_logged_in_default_group_shared(self):
|
|
||||||
""" Check correct status code for all requests
|
|
||||||
|
|
||||||
Assumption: User logged in, is default group member and data is shared
|
|
||||||
--> Default group necessary since all base functionalities depend on this group membership
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
|
|
||||||
"""
|
|
||||||
client = Client()
|
|
||||||
client.login(username=self.superuser.username, password=self.superuser_pw)
|
|
||||||
group = self.groups.get(name=DEFAULT_GROUP)
|
|
||||||
self.superuser.groups.set([group])
|
|
||||||
# Sharing is inherited by base intervention for compensation. Therefore configure the interventions share state
|
|
||||||
self.intervention.share_with_list([self.superuser])
|
|
||||||
|
|
||||||
success_urls = [
|
|
||||||
self.index_url,
|
|
||||||
self.detail_url,
|
|
||||||
self.report_url,
|
|
||||||
self.new_url,
|
|
||||||
self.new_id_url,
|
|
||||||
self.edit_url,
|
|
||||||
self.state_new_url,
|
|
||||||
self.action_new_url,
|
|
||||||
self.deadline_new_url,
|
|
||||||
self.state_remove_url,
|
|
||||||
self.action_remove_url,
|
|
||||||
self.new_doc_url,
|
|
||||||
self.log_url,
|
|
||||||
self.remove_url,
|
|
||||||
]
|
|
||||||
self.assert_url_success(client, success_urls)
|
|
||||||
|
|
||||||
def test_logged_in_default_group_unshared(self):
|
|
||||||
""" Check correct status code for all requests
|
|
||||||
|
|
||||||
Assumption: User logged in, is default group member and data is NOT shared
|
|
||||||
--> Default group necessary since all base functionalities depend on this group membership
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
|
|
||||||
"""
|
|
||||||
client = Client()
|
|
||||||
client.login(username=self.superuser.username, password=self.superuser_pw)
|
|
||||||
group = self.groups.get(name=DEFAULT_GROUP)
|
|
||||||
self.superuser.groups.set([group])
|
|
||||||
# Sharing is inherited by base intervention for compensation. Therefore configure the interventions share state
|
|
||||||
self.intervention.share_with_list([])
|
|
||||||
|
|
||||||
success_urls = [
|
|
||||||
self.index_url,
|
|
||||||
self.detail_url,
|
|
||||||
self.report_url,
|
|
||||||
self.new_id_url,
|
|
||||||
]
|
|
||||||
fail_urls = [
|
|
||||||
self.new_url,
|
|
||||||
self.edit_url,
|
|
||||||
self.state_new_url,
|
|
||||||
self.action_new_url,
|
|
||||||
self.deadline_new_url,
|
|
||||||
self.state_remove_url,
|
|
||||||
self.action_remove_url,
|
|
||||||
self.new_doc_url,
|
|
||||||
self.log_url,
|
|
||||||
self.remove_url,
|
|
||||||
]
|
|
||||||
self.assert_url_fail(client, fail_urls)
|
|
||||||
self.assert_url_success(client, success_urls)
|
|
||||||
|
|
||||||
|
|
||||||
class EcoAccountViewTestCase(CompensationViewTestCase):
|
|
||||||
"""
|
|
||||||
These tests focus on proper returned views depending on the user's groups privileges and login status
|
|
||||||
|
|
||||||
EcoAccounts can inherit the same tests used for compensations.
|
|
||||||
|
|
||||||
"""
|
|
||||||
comp_state = None
|
|
||||||
comp_action = None
|
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def setUpTestData(cls) -> None:
|
|
||||||
super().setUpTestData()
|
|
||||||
state = cls.create_dummy_states()
|
|
||||||
cls.eco_account.before_states.set([state])
|
|
||||||
cls.eco_account.after_states.set([state])
|
|
||||||
|
|
||||||
action = cls.create_dummy_action()
|
|
||||||
cls.eco_account.actions.set([action])
|
|
||||||
|
|
||||||
# Prepare urls
|
|
||||||
cls.index_url = reverse("compensation:acc-index", args=())
|
|
||||||
cls.new_url = reverse("compensation:acc-new", args=())
|
|
||||||
cls.new_id_url = reverse("compensation:acc-new-id", args=())
|
|
||||||
cls.detail_url = reverse("compensation:acc-detail", args=(cls.eco_account.id,))
|
|
||||||
cls.log_url = reverse("compensation:acc-log", args=(cls.eco_account.id,))
|
|
||||||
cls.edit_url = reverse("compensation:acc-edit", args=(cls.eco_account.id,))
|
|
||||||
cls.remove_url = reverse("compensation:acc-remove", args=(cls.eco_account.id,))
|
|
||||||
cls.report_url = reverse("compensation:acc-report", args=(cls.eco_account.id,))
|
|
||||||
cls.state_new_url = reverse("compensation:acc-new-state", args=(cls.eco_account.id,))
|
|
||||||
cls.action_new_url = reverse("compensation:acc-new-action", args=(cls.eco_account.id,))
|
|
||||||
cls.deadline_new_url = reverse("compensation:acc-new-deadline", args=(cls.eco_account.id,))
|
|
||||||
cls.new_doc_url = reverse("compensation:acc-new-doc", args=(cls.eco_account.id,))
|
|
||||||
cls.state_remove_url = reverse("compensation:acc-state-remove", args=(cls.eco_account.id, cls.comp_state.id,))
|
|
||||||
cls.action_remove_url = reverse("compensation:acc-action-remove", args=(cls.eco_account.id, cls.comp_action.id,))
|
|
||||||
|
|
||||||
def test_logged_in_no_groups_shared(self):
|
|
||||||
""" Check correct status code for all requests
|
|
||||||
|
|
||||||
Assumption: User logged in and has no groups and data is shared
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
|
|
||||||
"""
|
|
||||||
client = Client()
|
|
||||||
client.login(username=self.superuser.username, password=self.superuser_pw)
|
|
||||||
self.superuser.groups.set([])
|
|
||||||
self.eco_account.share_with_list([self.superuser])
|
|
||||||
|
|
||||||
# Since the user has no groups, it does not matter that data has been shared. There SHOULD not be any difference
|
|
||||||
# to a user without access, since the important permissions are missing
|
|
||||||
success_urls = [
|
|
||||||
self.index_url,
|
|
||||||
self.detail_url,
|
|
||||||
self.report_url,
|
|
||||||
]
|
|
||||||
fail_urls = [
|
|
||||||
self.new_url,
|
|
||||||
self.new_id_url,
|
|
||||||
self.log_url,
|
|
||||||
self.edit_url,
|
|
||||||
self.remove_url,
|
|
||||||
self.state_new_url,
|
|
||||||
self.action_new_url,
|
|
||||||
self.deadline_new_url,
|
|
||||||
self.state_remove_url,
|
|
||||||
self.action_remove_url,
|
|
||||||
self.new_doc_url,
|
|
||||||
]
|
|
||||||
|
|
||||||
self.assert_url_success(client, success_urls)
|
|
||||||
self.assert_url_fail(client, fail_urls)
|
|
||||||
|
|
||||||
def test_logged_in_no_groups_unshared(self):
|
|
||||||
""" Check correct status code for all requests
|
|
||||||
|
|
||||||
Assumption: User logged in and has no groups and data is shared
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
|
|
||||||
"""
|
|
||||||
client = Client()
|
|
||||||
client.login(username=self.superuser.username, password=self.superuser_pw)
|
|
||||||
self.superuser.groups.set([])
|
|
||||||
self.eco_account.share_with_list([])
|
|
||||||
|
|
||||||
# Since the user has no groups, it does not matter that data is unshared. There SHOULD not be any difference
|
|
||||||
# to a user having shared access, since all important permissions are missing
|
|
||||||
success_urls = [
|
|
||||||
self.index_url,
|
|
||||||
self.detail_url,
|
|
||||||
self.report_url,
|
|
||||||
]
|
|
||||||
fail_urls = [
|
|
||||||
self.new_url,
|
|
||||||
self.new_id_url,
|
|
||||||
self.log_url,
|
|
||||||
self.edit_url,
|
|
||||||
self.remove_url,
|
|
||||||
self.state_new_url,
|
|
||||||
self.action_new_url,
|
|
||||||
self.deadline_new_url,
|
|
||||||
self.state_remove_url,
|
|
||||||
self.action_remove_url,
|
|
||||||
self.new_doc_url,
|
|
||||||
]
|
|
||||||
|
|
||||||
self.assert_url_success(client, success_urls)
|
|
||||||
self.assert_url_fail(client, fail_urls)
|
|
||||||
|
|
||||||
def test_logged_in_default_group_shared(self):
|
|
||||||
""" Check correct status code for all requests
|
|
||||||
|
|
||||||
Assumption: User logged in, is default group member and data is shared
|
|
||||||
--> Default group necessary since all base functionalities depend on this group membership
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
|
|
||||||
"""
|
|
||||||
client = Client()
|
|
||||||
client.login(username=self.superuser.username, password=self.superuser_pw)
|
|
||||||
group = self.groups.get(name=DEFAULT_GROUP)
|
|
||||||
self.superuser.groups.set([group])
|
|
||||||
# Sharing is inherited by base intervention for compensation. Therefore configure the interventions share state
|
|
||||||
self.eco_account.share_with_list([self.superuser])
|
|
||||||
|
|
||||||
success_urls = [
|
|
||||||
self.index_url,
|
|
||||||
self.detail_url,
|
|
||||||
self.report_url,
|
|
||||||
self.new_url,
|
|
||||||
self.new_id_url,
|
|
||||||
self.edit_url,
|
|
||||||
self.state_new_url,
|
|
||||||
self.action_new_url,
|
|
||||||
self.deadline_new_url,
|
|
||||||
self.state_remove_url,
|
|
||||||
self.action_remove_url,
|
|
||||||
self.new_doc_url,
|
|
||||||
self.log_url,
|
|
||||||
self.remove_url,
|
|
||||||
]
|
|
||||||
self.assert_url_success(client, success_urls)
|
|
||||||
|
|
||||||
def test_logged_in_default_group_unshared(self):
|
|
||||||
""" Check correct status code for all requests
|
|
||||||
|
|
||||||
Assumption: User logged in, is default group member and data is NOT shared
|
|
||||||
--> Default group necessary since all base functionalities depend on this group membership
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
|
|
||||||
"""
|
|
||||||
client = Client()
|
|
||||||
client.login(username=self.superuser.username, password=self.superuser_pw)
|
|
||||||
group = self.groups.get(name=DEFAULT_GROUP)
|
|
||||||
self.superuser.groups.set([group])
|
|
||||||
self.eco_account.share_with_list([])
|
|
||||||
|
|
||||||
success_urls = [
|
|
||||||
self.index_url,
|
|
||||||
self.detail_url,
|
|
||||||
self.report_url,
|
|
||||||
self.new_id_url,
|
|
||||||
self.new_url,
|
|
||||||
]
|
|
||||||
fail_urls = [
|
|
||||||
self.edit_url,
|
|
||||||
self.state_new_url,
|
|
||||||
self.action_new_url,
|
|
||||||
self.deadline_new_url,
|
|
||||||
self.state_remove_url,
|
|
||||||
self.action_remove_url,
|
|
||||||
self.new_doc_url,
|
|
||||||
self.log_url,
|
|
||||||
self.remove_url,
|
|
||||||
]
|
|
||||||
self.assert_url_fail(client, fail_urls)
|
|
||||||
self.assert_url_success(client, success_urls)
|
|
||||||
|
|
||||||
@@ -18,16 +18,25 @@ urlpatterns = [
|
|||||||
path('<id>/log', log_view, name='log'),
|
path('<id>/log', log_view, name='log'),
|
||||||
path('<id>/edit', edit_view, name='edit'),
|
path('<id>/edit', edit_view, name='edit'),
|
||||||
path('<id>/remove', remove_view, name='remove'),
|
path('<id>/remove', remove_view, name='remove'),
|
||||||
|
|
||||||
path('<id>/state/new', state_new_view, name='new-state'),
|
path('<id>/state/new', state_new_view, name='new-state'),
|
||||||
path('<id>/action/new', action_new_view, name='new-action'),
|
path('<id>/state/<state_id>/edit', state_edit_view, name='state-edit'),
|
||||||
path('<id>/state/<state_id>/remove', state_remove_view, name='state-remove'),
|
path('<id>/state/<state_id>/remove', state_remove_view, name='state-remove'),
|
||||||
|
|
||||||
|
path('<id>/action/new', action_new_view, name='new-action'),
|
||||||
|
path('<id>/action/<action_id>/edit', action_edit_view, name='action-edit'),
|
||||||
path('<id>/action/<action_id>/remove', action_remove_view, name='action-remove'),
|
path('<id>/action/<action_id>/remove', action_remove_view, name='action-remove'),
|
||||||
|
|
||||||
path('<id>/deadline/new', deadline_new_view, name="new-deadline"),
|
path('<id>/deadline/new', deadline_new_view, name="new-deadline"),
|
||||||
|
path('<id>/deadline/<deadline_id>/edit', deadline_edit_view, name='deadline-edit'),
|
||||||
|
path('<id>/deadline/<deadline_id>/remove', deadline_remove_view, name='deadline-remove'),
|
||||||
path('<id>/report', report_view, name='report'),
|
path('<id>/report', report_view, name='report'),
|
||||||
|
path('<id>/resub', create_resubmission_view, name='resubmission-create'),
|
||||||
|
|
||||||
# Documents
|
# Documents
|
||||||
path('<id>/document/new/', new_document_view, name='new-doc'),
|
path('<id>/document/new/', new_document_view, name='new-doc'),
|
||||||
path('document/<doc_id>', get_document_view, name='get-doc'),
|
path('<id>/document/<doc_id>', get_document_view, name='get-doc'),
|
||||||
path('document/<doc_id>/remove/', remove_document_view, name='remove-doc'),
|
path('<id>/document/<doc_id>/remove/', remove_document_view, name='remove-doc'),
|
||||||
|
path('<id>/document/<doc_id>/edit/', edit_document_view, name='edit-doc'),
|
||||||
|
|
||||||
]
|
]
|
||||||
@@ -8,31 +8,43 @@ Created on: 24.08.21
|
|||||||
from django.urls import path
|
from django.urls import path
|
||||||
from compensation.views.eco_account import *
|
from compensation.views.eco_account import *
|
||||||
|
|
||||||
|
app_name = "acc"
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path("", index_view, name="acc-index"),
|
path("", index_view, name="index"),
|
||||||
path('new/', new_view, name='acc-new'),
|
path('new/', new_view, name='new'),
|
||||||
path('new/id', new_id_view, name='acc-new-id'),
|
path('new/id', new_id_view, name='new-id'),
|
||||||
path('<id>', detail_view, name='acc-detail'),
|
path('<id>', detail_view, name='detail'),
|
||||||
path('<id>/log', log_view, name='acc-log'),
|
path('<id>/log', log_view, name='log'),
|
||||||
path('<id>/record', record_view, name='acc-record'),
|
path('<id>/record', record_view, name='record'),
|
||||||
path('<id>/report', report_view, name='acc-report'),
|
path('<id>/report', report_view, name='report'),
|
||||||
path('<id>/edit', edit_view, name='acc-edit'),
|
path('<id>/edit', edit_view, name='edit'),
|
||||||
path('<id>/remove', remove_view, name='acc-remove'),
|
path('<id>/remove', remove_view, name='remove'),
|
||||||
path('<id>/state/new', state_new_view, name='acc-new-state'),
|
path('<id>/resub', create_resubmission_view, name='resubmission-create'),
|
||||||
path('<id>/action/new', action_new_view, name='acc-new-action'),
|
|
||||||
path('<id>/state/<state_id>/remove', state_remove_view, name='acc-state-remove'),
|
path('<id>/state/new', state_new_view, name='new-state'),
|
||||||
path('<id>/action/<action_id>/remove', action_remove_view, name='acc-action-remove'),
|
path('<id>/state/<state_id>/edit', state_edit_view, name='state-edit'),
|
||||||
path('<id>/deadline/new', deadline_new_view, name="acc-new-deadline"),
|
path('<id>/state/<state_id>/remove', state_remove_view, name='state-remove'),
|
||||||
|
|
||||||
|
path('<id>/action/new', action_new_view, name='new-action'),
|
||||||
|
path('<id>/action/<action_id>/edit', action_edit_view, name='action-edit'),
|
||||||
|
path('<id>/action/<action_id>/remove', action_remove_view, name='action-remove'),
|
||||||
|
|
||||||
|
path('<id>/deadline/new', deadline_new_view, name="new-deadline"),
|
||||||
|
path('<id>/deadline/<deadline_id>/edit', deadline_edit_view, name='deadline-edit'),
|
||||||
|
path('<id>/deadline/<deadline_id>/remove', deadline_remove_view, name='deadline-remove'),
|
||||||
|
|
||||||
path('<id>/share/<token>', share_view, name='share'),
|
path('<id>/share/<token>', share_view, name='share'),
|
||||||
path('<id>/share', create_share_view, name='share-create'),
|
path('<id>/share', create_share_view, name='share-create'),
|
||||||
|
|
||||||
# Documents
|
# Documents
|
||||||
path('<id>/document/new/', new_document_view, name='acc-new-doc'),
|
path('<id>/document/new/', new_document_view, name='new-doc'),
|
||||||
path('document/<doc_id>', get_document_view, name='acc-get-doc'),
|
path('<id>/document/<doc_id>', get_document_view, name='get-doc'),
|
||||||
path('document/<doc_id>/remove/', remove_document_view, name='acc-remove-doc'),
|
path('<id>/document/<doc_id>/edit', edit_document_view, name='edit-doc'),
|
||||||
|
path('<id>/document/<doc_id>/remove/', remove_document_view, name='remove-doc'),
|
||||||
|
|
||||||
# Eco-account deductions
|
# Eco-account deductions
|
||||||
path('<id>/remove/<deduction_id>', deduction_remove_view, name='acc-remove-deduction'),
|
path('<id>/deduction/<deduction_id>/remove', deduction_remove_view, name='remove-deduction'),
|
||||||
path('<id>/deduct/new', new_deduction_view, name='acc-new-deduction'),
|
path('<id>/deduction/<deduction_id>/edit', deduction_edit_view, name='edit-deduction'),
|
||||||
|
path('<id>/deduct/new', new_deduction_view, name='new-deduction'),
|
||||||
|
|
||||||
]
|
]
|
||||||
@@ -8,7 +8,9 @@ Created on: 24.08.21
|
|||||||
from django.urls import path
|
from django.urls import path
|
||||||
from compensation.views.payment import *
|
from compensation.views.payment import *
|
||||||
|
|
||||||
|
app_name = "pay"
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path('<intervention_id>/new', new_payment_view, name='pay-new'),
|
path('<id>/new', new_payment_view, name='new'),
|
||||||
path('<id>/remove', payment_remove_view, name='pay-remove'),
|
path('<id>/remove/<payment_id>', payment_remove_view, name='remove'),
|
||||||
|
path('<id>/edit/<payment_id>', payment_edit_view, name='edit'),
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -10,6 +10,6 @@ from django.urls import path, include
|
|||||||
app_name = "compensation"
|
app_name = "compensation"
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path("", include("compensation.urls.compensation")),
|
path("", include("compensation.urls.compensation")),
|
||||||
path("acc/", include("compensation.urls.eco_account")),
|
path("acc/", include("compensation.urls.eco_account", namespace="acc")),
|
||||||
path("pay/", include("compensation.urls.payment")),
|
path("pay/", include("compensation.urls.payment", namespace="pay")),
|
||||||
]
|
]
|
||||||
@@ -19,6 +19,7 @@ class CompensationQualityChecker(AbstractQualityChecker):
|
|||||||
self._check_states()
|
self._check_states()
|
||||||
self._check_actions()
|
self._check_actions()
|
||||||
self._check_geometry()
|
self._check_geometry()
|
||||||
|
self._check_deadlines()
|
||||||
self.valid = len(self.messages) == 0
|
self.valid = len(self.messages) == 0
|
||||||
|
|
||||||
def _check_states(self):
|
def _check_states(self):
|
||||||
@@ -47,6 +48,16 @@ class CompensationQualityChecker(AbstractQualityChecker):
|
|||||||
if not self.obj.actions.all():
|
if not self.obj.actions.all():
|
||||||
self._add_missing_attr_name(_con("Compensation", "Actions"))
|
self._add_missing_attr_name(_con("Compensation", "Actions"))
|
||||||
|
|
||||||
|
def _check_deadlines(self):
|
||||||
|
""" Checks data quality for related Deadline objects
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
|
||||||
|
"""
|
||||||
|
finished_deadlines = self.obj.get_finished_deadlines()
|
||||||
|
if not finished_deadlines.exists():
|
||||||
|
self._add_missing_attr_name(_("Finished deadlines"))
|
||||||
|
|
||||||
|
|
||||||
class EcoAccountQualityChecker(CompensationQualityChecker):
|
class EcoAccountQualityChecker(CompensationQualityChecker):
|
||||||
def run_check(self):
|
def run_check(self):
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
from django.contrib.auth.decorators import login_required
|
from django.contrib.auth.decorators import login_required
|
||||||
|
from django.core.exceptions import ObjectDoesNotExist
|
||||||
from django.db.models import Sum
|
from django.db.models import Sum
|
||||||
from django.http import HttpRequest, JsonResponse
|
from django.http import HttpRequest, JsonResponse
|
||||||
from django.shortcuts import render
|
from django.shortcuts import render
|
||||||
@@ -6,18 +7,25 @@ from django.utils.translation import gettext_lazy as _
|
|||||||
|
|
||||||
from compensation.forms.forms import NewCompensationForm, EditCompensationForm
|
from compensation.forms.forms import NewCompensationForm, EditCompensationForm
|
||||||
from compensation.forms.modalForms import NewStateModalForm, NewDeadlineModalForm, NewActionModalForm, \
|
from compensation.forms.modalForms import NewStateModalForm, NewDeadlineModalForm, NewActionModalForm, \
|
||||||
NewCompensationDocumentForm
|
NewCompensationDocumentModalForm, RemoveCompensationActionModalForm, RemoveCompensationStateModalForm, \
|
||||||
|
EditCompensationStateModalForm, EditCompensationActionModalForm, EditDeadlineModalForm
|
||||||
from compensation.models import Compensation, CompensationState, CompensationAction, CompensationDocument
|
from compensation.models import Compensation, CompensationState, CompensationAction, CompensationDocument
|
||||||
from compensation.tables import CompensationTable
|
from compensation.tables import CompensationTable
|
||||||
from intervention.models import Intervention
|
from intervention.models import Intervention
|
||||||
from konova.contexts import BaseContext
|
from konova.contexts import BaseContext
|
||||||
from konova.decorators import *
|
from konova.decorators import *
|
||||||
from konova.forms import RemoveModalForm, SimpleGeomForm
|
from konova.forms.modals import RemoveModalForm,RemoveDeadlineModalForm, EditDocumentModalForm, \
|
||||||
|
ResubmissionModalForm
|
||||||
|
from konova.forms import SimpleGeomForm
|
||||||
|
from konova.models import Deadline
|
||||||
from konova.sub_settings.context_settings import TAB_TITLE_IDENTIFIER
|
from konova.sub_settings.context_settings import TAB_TITLE_IDENTIFIER
|
||||||
from konova.utils.documents import get_document, remove_document
|
from konova.utils.documents import get_document, remove_document
|
||||||
from konova.utils.generators import generate_qr_code
|
from konova.utils.generators import generate_qr_code
|
||||||
from konova.utils.message_templates import FORM_INVALID, IDENTIFIER_REPLACED, DATA_UNSHARED_EXPLANATION, \
|
from konova.utils.message_templates import FORM_INVALID, IDENTIFIER_REPLACED, DATA_UNSHARED_EXPLANATION, \
|
||||||
CHECKED_RECORDED_RESET
|
CHECKED_RECORDED_RESET, COMPENSATION_ADDED_TEMPLATE, COMPENSATION_REMOVED_TEMPLATE, DOCUMENT_ADDED, \
|
||||||
|
COMPENSATION_STATE_REMOVED, COMPENSATION_STATE_ADDED, COMPENSATION_ACTION_REMOVED, COMPENSATION_ACTION_ADDED, \
|
||||||
|
DEADLINE_ADDED, DEADLINE_REMOVED, DOCUMENT_EDITED, COMPENSATION_STATE_EDITED, COMPENSATION_ACTION_EDITED, \
|
||||||
|
DEADLINE_EDITED, RECORDED_BLOCKS_EDIT, PARAMS_INVALID, DATA_CHECKED_PREVIOUSLY_TEMPLATE
|
||||||
from konova.utils.user_checks import in_group
|
from konova.utils.user_checks import in_group
|
||||||
|
|
||||||
|
|
||||||
@@ -64,6 +72,19 @@ def new_view(request: HttpRequest, intervention_id: str = None):
|
|||||||
|
|
||||||
"""
|
"""
|
||||||
template = "compensation/form/view.html"
|
template = "compensation/form/view.html"
|
||||||
|
if intervention_id is not None:
|
||||||
|
try:
|
||||||
|
intervention = Intervention.objects.get(id=intervention_id)
|
||||||
|
except ObjectDoesNotExist:
|
||||||
|
messages.error(request, PARAMS_INVALID)
|
||||||
|
return redirect("home")
|
||||||
|
if intervention.is_recorded:
|
||||||
|
messages.info(
|
||||||
|
request,
|
||||||
|
RECORDED_BLOCKS_EDIT
|
||||||
|
)
|
||||||
|
return redirect("intervention:detail", id=intervention_id)
|
||||||
|
|
||||||
data_form = NewCompensationForm(request.POST or None, intervention_id=intervention_id)
|
data_form = NewCompensationForm(request.POST or None, intervention_id=intervention_id)
|
||||||
geom_form = SimpleGeomForm(request.POST or None, read_only=False)
|
geom_form = SimpleGeomForm(request.POST or None, read_only=False)
|
||||||
if request.method == "POST":
|
if request.method == "POST":
|
||||||
@@ -78,7 +99,7 @@ def new_view(request: HttpRequest, intervention_id: str = None):
|
|||||||
comp.identifier
|
comp.identifier
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
messages.success(request, _("Compensation {} added").format(comp.identifier))
|
messages.success(request, COMPENSATION_ADDED_TEMPLATE.format(comp.identifier))
|
||||||
return redirect("compensation:detail", id=comp.id)
|
return redirect("compensation:detail", id=comp.id)
|
||||||
else:
|
else:
|
||||||
messages.error(request, FORM_INVALID, extra_tags="danger",)
|
messages.error(request, FORM_INVALID, extra_tags="danger",)
|
||||||
@@ -129,6 +150,13 @@ def edit_view(request: HttpRequest, id: str):
|
|||||||
template = "compensation/form/view.html"
|
template = "compensation/form/view.html"
|
||||||
# Get object from db
|
# Get object from db
|
||||||
comp = get_object_or_404(Compensation, id=id)
|
comp = get_object_or_404(Compensation, id=id)
|
||||||
|
if comp.is_recorded:
|
||||||
|
messages.info(
|
||||||
|
request,
|
||||||
|
RECORDED_BLOCKS_EDIT
|
||||||
|
)
|
||||||
|
return redirect("compensation:detail", id=id)
|
||||||
|
|
||||||
# Create forms, initialize with values from db/from POST request
|
# Create forms, initialize with values from db/from POST request
|
||||||
data_form = EditCompensationForm(request.POST or None, instance=comp)
|
data_form = EditCompensationForm(request.POST or None, instance=comp)
|
||||||
geom_form = SimpleGeomForm(request.POST or None, read_only=False, instance=comp)
|
geom_form = SimpleGeomForm(request.POST or None, read_only=False, instance=comp)
|
||||||
@@ -191,8 +219,15 @@ def detail_view(request: HttpRequest, id: str):
|
|||||||
|
|
||||||
request = comp.set_status_messages(request)
|
request = comp.set_status_messages(request)
|
||||||
|
|
||||||
|
last_checked = comp.intervention.get_last_checked_action()
|
||||||
|
last_checked_tooltip = ""
|
||||||
|
if last_checked:
|
||||||
|
last_checked_tooltip = DATA_CHECKED_PREVIOUSLY_TEMPLATE.format(last_checked.get_timestamp_str_formatted(), last_checked.user)
|
||||||
|
|
||||||
context = {
|
context = {
|
||||||
"obj": comp,
|
"obj": comp,
|
||||||
|
"last_checked": last_checked,
|
||||||
|
"last_checked_tooltip": last_checked_tooltip,
|
||||||
"geom_form": geom_form,
|
"geom_form": geom_form,
|
||||||
"parcels": parcels,
|
"parcels": parcels,
|
||||||
"has_access": is_data_shared,
|
"has_access": is_data_shared,
|
||||||
@@ -207,6 +242,7 @@ def detail_view(request: HttpRequest, id: str):
|
|||||||
"is_ets_member": in_group(_user, ETS_GROUP),
|
"is_ets_member": in_group(_user, ETS_GROUP),
|
||||||
"LANIS_LINK": comp.get_LANIS_link(),
|
"LANIS_LINK": comp.get_LANIS_link(),
|
||||||
TAB_TITLE_IDENTIFIER: f"{comp.identifier} - {comp.title}",
|
TAB_TITLE_IDENTIFIER: f"{comp.identifier} - {comp.title}",
|
||||||
|
"has_finished_deadlines": comp.get_finished_deadlines().exists(),
|
||||||
}
|
}
|
||||||
context = BaseContext(request, context).context
|
context = BaseContext(request, context).context
|
||||||
return render(request, template, context)
|
return render(request, template, context)
|
||||||
@@ -255,7 +291,7 @@ def remove_view(request: HttpRequest, id: str):
|
|||||||
form = RemoveModalForm(request.POST or None, instance=comp, request=request)
|
form = RemoveModalForm(request.POST or None, instance=comp, request=request)
|
||||||
return form.process_request(
|
return form.process_request(
|
||||||
request=request,
|
request=request,
|
||||||
msg_success=_("Compensation removed"),
|
msg_success=COMPENSATION_REMOVED_TEMPLATE.format(comp.identifier),
|
||||||
redirect_url=reverse("compensation:index"),
|
redirect_url=reverse("compensation:index"),
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -273,54 +309,52 @@ def new_document_view(request: HttpRequest, id: str):
|
|||||||
|
|
||||||
"""
|
"""
|
||||||
comp = get_object_or_404(Compensation, id=id)
|
comp = get_object_or_404(Compensation, id=id)
|
||||||
form = NewCompensationDocumentForm(request.POST or None, request.FILES or None, instance=comp, request=request)
|
form = NewCompensationDocumentModalForm(request.POST or None, request.FILES or None, instance=comp, request=request)
|
||||||
return form.process_request(
|
return form.process_request(
|
||||||
request,
|
request,
|
||||||
msg_success=_("Document added")
|
msg_success=DOCUMENT_ADDED,
|
||||||
|
redirect_url=reverse("compensation:detail", args=(id,)) + "#related_data"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
@default_group_required
|
@default_group_required
|
||||||
def get_document_view(request: HttpRequest, doc_id: str):
|
@shared_access_required(Compensation, "id")
|
||||||
|
def get_document_view(request: HttpRequest, id: str, doc_id: str):
|
||||||
""" Returns the document as downloadable file
|
""" Returns the document as downloadable file
|
||||||
|
|
||||||
Wraps the generic document fetcher function from konova.utils.
|
Wraps the generic document fetcher function from konova.utils.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
request (HttpRequest): The incoming request
|
request (HttpRequest): The incoming request
|
||||||
|
id (str): The compensation id
|
||||||
doc_id (str): The document id
|
doc_id (str): The document id
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
comp = get_object_or_404(Compensation, id=id)
|
||||||
doc = get_object_or_404(CompensationDocument, id=doc_id)
|
doc = get_object_or_404(CompensationDocument, id=doc_id)
|
||||||
user = request.user
|
|
||||||
instance = doc.instance
|
|
||||||
# File download only possible if related instance is shared with user
|
|
||||||
if not instance.users.filter(id=user.id):
|
|
||||||
messages.info(
|
|
||||||
request,
|
|
||||||
DATA_UNSHARED
|
|
||||||
)
|
|
||||||
return redirect("compensation:detail", id=instance.id)
|
|
||||||
return get_document(doc)
|
return get_document(doc)
|
||||||
|
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
@default_group_required
|
@default_group_required
|
||||||
def remove_document_view(request: HttpRequest, doc_id: str):
|
@shared_access_required(Compensation, "id")
|
||||||
|
def remove_document_view(request: HttpRequest, id: str, doc_id: str):
|
||||||
""" Removes the document from the database and file system
|
""" Removes the document from the database and file system
|
||||||
|
|
||||||
Wraps the generic functionality from konova.utils.
|
Wraps the generic functionality from konova.utils.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
request (HttpRequest): The incoming request
|
request (HttpRequest): The incoming request
|
||||||
|
id (str): The compensation id
|
||||||
doc_id (str): The document id
|
doc_id (str): The document id
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
comp = get_object_or_404(Compensation, id=id)
|
||||||
doc = get_object_or_404(CompensationDocument, id=doc_id)
|
doc = get_object_or_404(CompensationDocument, id=doc_id)
|
||||||
return remove_document(
|
return remove_document(
|
||||||
request,
|
request,
|
||||||
@@ -328,6 +362,32 @@ def remove_document_view(request: HttpRequest, doc_id: str):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@login_required
|
||||||
|
@default_group_required
|
||||||
|
@shared_access_required(Compensation, "id")
|
||||||
|
def edit_document_view(request: HttpRequest, id: str, doc_id: str):
|
||||||
|
""" Removes the document from the database and file system
|
||||||
|
|
||||||
|
Wraps the generic functionality from konova.utils.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
request (HttpRequest): The incoming request
|
||||||
|
id (str): The compensation id
|
||||||
|
doc_id (str): The document id
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
|
||||||
|
"""
|
||||||
|
comp = get_object_or_404(Compensation, id=id)
|
||||||
|
doc = get_object_or_404(CompensationDocument, id=doc_id)
|
||||||
|
form = EditDocumentModalForm(request.POST or None, request.FILES or None, instance=comp, document=doc, request=request)
|
||||||
|
return form.process_request(
|
||||||
|
request,
|
||||||
|
DOCUMENT_EDITED,
|
||||||
|
reverse("compensation:detail", args=(id,)) + "#related_data"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
@default_group_required
|
@default_group_required
|
||||||
@shared_access_required(Compensation, "id")
|
@shared_access_required(Compensation, "id")
|
||||||
@@ -345,7 +405,8 @@ def state_new_view(request: HttpRequest, id: str):
|
|||||||
form = NewStateModalForm(request.POST or None, instance=comp, request=request)
|
form = NewStateModalForm(request.POST or None, instance=comp, request=request)
|
||||||
return form.process_request(
|
return form.process_request(
|
||||||
request,
|
request,
|
||||||
msg_success=_("State added")
|
msg_success=COMPENSATION_STATE_ADDED,
|
||||||
|
redirect_url=reverse("compensation:detail", args=(id,)) + "#related_data"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@@ -366,7 +427,32 @@ def action_new_view(request: HttpRequest, id: str):
|
|||||||
form = NewActionModalForm(request.POST or None, instance=comp, request=request)
|
form = NewActionModalForm(request.POST or None, instance=comp, request=request)
|
||||||
return form.process_request(
|
return form.process_request(
|
||||||
request,
|
request,
|
||||||
msg_success=_("Action added")
|
msg_success=COMPENSATION_ACTION_ADDED,
|
||||||
|
redirect_url=reverse("compensation:detail", args=(id,)) + "#related_data"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@login_required
|
||||||
|
@default_group_required
|
||||||
|
@shared_access_required(Compensation, "id")
|
||||||
|
def action_edit_view(request: HttpRequest, id: str, action_id: str):
|
||||||
|
""" Renders a form for editing actions for a compensation
|
||||||
|
|
||||||
|
Args:
|
||||||
|
request (HttpRequest): The incoming request
|
||||||
|
id (str): The compensation's id
|
||||||
|
action_id (str): The action's id
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
|
||||||
|
"""
|
||||||
|
comp = get_object_or_404(Compensation, id=id)
|
||||||
|
action = get_object_or_404(CompensationAction, id=action_id)
|
||||||
|
form = EditCompensationActionModalForm(request.POST or None, instance=comp, action=action, request=request)
|
||||||
|
return form.process_request(
|
||||||
|
request,
|
||||||
|
msg_success=COMPENSATION_ACTION_EDITED,
|
||||||
|
redirect_url=reverse("compensation:detail", args=(id,)) + "#related_data"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@@ -387,7 +473,56 @@ def deadline_new_view(request: HttpRequest, id: str):
|
|||||||
form = NewDeadlineModalForm(request.POST or None, instance=comp, request=request)
|
form = NewDeadlineModalForm(request.POST or None, instance=comp, request=request)
|
||||||
return form.process_request(
|
return form.process_request(
|
||||||
request,
|
request,
|
||||||
msg_success=_("Deadline added")
|
msg_success=DEADLINE_ADDED,
|
||||||
|
redirect_url=reverse("compensation:detail", args=(id,)) + "#related_data"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@login_required
|
||||||
|
@default_group_required
|
||||||
|
@shared_access_required(Compensation, "id")
|
||||||
|
def deadline_edit_view(request: HttpRequest, id: str, deadline_id: str):
|
||||||
|
""" Renders a form for editing deadlines from a compensation
|
||||||
|
|
||||||
|
Args:
|
||||||
|
request (HttpRequest): The incoming request
|
||||||
|
id (str): The compensation's id
|
||||||
|
deadline_id (str): The deadline's id
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
|
||||||
|
"""
|
||||||
|
comp = get_object_or_404(Compensation, id=id)
|
||||||
|
deadline = get_object_or_404(Deadline, id=deadline_id)
|
||||||
|
form = EditDeadlineModalForm(request.POST or None, instance=comp, deadline=deadline, request=request)
|
||||||
|
return form.process_request(
|
||||||
|
request,
|
||||||
|
msg_success=DEADLINE_EDITED,
|
||||||
|
redirect_url=reverse("compensation:detail", args=(id,)) + "#related_data"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@login_required
|
||||||
|
@default_group_required
|
||||||
|
@shared_access_required(Compensation, "id")
|
||||||
|
def deadline_remove_view(request: HttpRequest, id: str, deadline_id: str):
|
||||||
|
""" Renders a form for removing deadlines from a compensation
|
||||||
|
|
||||||
|
Args:
|
||||||
|
request (HttpRequest): The incoming request
|
||||||
|
id (str): The compensation's id
|
||||||
|
deadline_id (str): The deadline's id
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
|
||||||
|
"""
|
||||||
|
comp = get_object_or_404(Compensation, id=id)
|
||||||
|
deadline = get_object_or_404(Deadline, id=deadline_id)
|
||||||
|
form = RemoveDeadlineModalForm(request.POST or None, instance=comp, deadline=deadline, request=request)
|
||||||
|
return form.process_request(
|
||||||
|
request,
|
||||||
|
msg_success=DEADLINE_REMOVED,
|
||||||
|
redirect_url=reverse("compensation:detail", args=(id,)) + "#related_data"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@@ -405,11 +540,37 @@ def state_remove_view(request: HttpRequest, id: str, state_id: str):
|
|||||||
Returns:
|
Returns:
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
comp = get_object_or_404(Compensation, id=id)
|
||||||
state = get_object_or_404(CompensationState, id=state_id)
|
state = get_object_or_404(CompensationState, id=state_id)
|
||||||
form = RemoveModalForm(request.POST or None, instance=state, request=request)
|
form = RemoveCompensationStateModalForm(request.POST or None, instance=comp, state=state, request=request)
|
||||||
return form.process_request(
|
return form.process_request(
|
||||||
request,
|
request,
|
||||||
msg_success=_("State removed")
|
msg_success=COMPENSATION_STATE_REMOVED,
|
||||||
|
redirect_url=reverse("compensation:detail", args=(id,)) + "#related_data"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@login_required
|
||||||
|
@default_group_required
|
||||||
|
@shared_access_required(Compensation, "id")
|
||||||
|
def state_edit_view(request: HttpRequest, id: str, state_id: str):
|
||||||
|
""" Renders a form for editing a compensation state
|
||||||
|
|
||||||
|
Args:
|
||||||
|
request (HttpRequest): The incoming request
|
||||||
|
id (str): The compensation's id
|
||||||
|
state_id (str): The state's id
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
|
||||||
|
"""
|
||||||
|
comp = get_object_or_404(Compensation, id=id)
|
||||||
|
state = get_object_or_404(CompensationState, id=state_id)
|
||||||
|
form = EditCompensationStateModalForm(request.POST or None, instance=comp, state=state, request=request)
|
||||||
|
return form.process_request(
|
||||||
|
request,
|
||||||
|
msg_success=COMPENSATION_STATE_EDITED,
|
||||||
|
redirect_url=reverse("compensation:detail", args=(id,)) + "#related_data"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@@ -427,11 +588,13 @@ def action_remove_view(request: HttpRequest, id: str, action_id: str):
|
|||||||
Returns:
|
Returns:
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
comp = get_object_or_404(Compensation, id=id)
|
||||||
action = get_object_or_404(CompensationAction, id=action_id)
|
action = get_object_or_404(CompensationAction, id=action_id)
|
||||||
form = RemoveModalForm(request.POST or None, instance=action, request=request)
|
form = RemoveCompensationActionModalForm(request.POST or None, instance=comp, action=action, request=request)
|
||||||
return form.process_request(
|
return form.process_request(
|
||||||
request,
|
request,
|
||||||
msg_success=_("Action removed")
|
msg_success=COMPENSATION_ACTION_REMOVED,
|
||||||
|
redirect_url=reverse("compensation:detail", args=(id,)) + "#related_data"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@@ -464,14 +627,12 @@ def report_view(request: HttpRequest, id: str):
|
|||||||
instance=comp
|
instance=comp
|
||||||
)
|
)
|
||||||
parcels = comp.get_underlying_parcels()
|
parcels = comp.get_underlying_parcels()
|
||||||
qrcode_img = generate_qr_code(
|
|
||||||
request.build_absolute_uri(reverse("compensation:report", args=(id,))),
|
qrcode_url = request.build_absolute_uri(reverse("compensation:report", args=(id,)))
|
||||||
10
|
qrcode_img = generate_qr_code(qrcode_url, 10)
|
||||||
)
|
qrcode_lanis_url = comp.get_LANIS_link()
|
||||||
qrcode_img_lanis = generate_qr_code(
|
qrcode_img_lanis = generate_qr_code(qrcode_lanis_url, 7)
|
||||||
comp.get_LANIS_link(),
|
|
||||||
7
|
|
||||||
)
|
|
||||||
# Order states by surface
|
# Order states by surface
|
||||||
before_states = comp.before_states.all().order_by("-surface").prefetch_related("biotope_type")
|
before_states = comp.before_states.all().order_by("-surface").prefetch_related("biotope_type")
|
||||||
after_states = comp.after_states.all().order_by("-surface").prefetch_related("biotope_type")
|
after_states = comp.after_states.all().order_by("-surface").prefetch_related("biotope_type")
|
||||||
@@ -479,8 +640,14 @@ def report_view(request: HttpRequest, id: str):
|
|||||||
|
|
||||||
context = {
|
context = {
|
||||||
"obj": comp,
|
"obj": comp,
|
||||||
"qrcode": qrcode_img,
|
"qrcode": {
|
||||||
"qrcode_lanis": qrcode_img_lanis,
|
"img": qrcode_img,
|
||||||
|
"url": qrcode_url,
|
||||||
|
},
|
||||||
|
"qrcode_lanis": {
|
||||||
|
"img": qrcode_img_lanis,
|
||||||
|
"url": qrcode_lanis_url,
|
||||||
|
},
|
||||||
"has_access": False, # disables action buttons during rendering
|
"has_access": False, # disables action buttons during rendering
|
||||||
"before_states": before_states,
|
"before_states": before_states,
|
||||||
"after_states": after_states,
|
"after_states": after_states,
|
||||||
@@ -491,3 +658,26 @@ def report_view(request: HttpRequest, id: str):
|
|||||||
}
|
}
|
||||||
context = BaseContext(request, context).context
|
context = BaseContext(request, context).context
|
||||||
return render(request, template, context)
|
return render(request, template, context)
|
||||||
|
|
||||||
|
|
||||||
|
@login_required
|
||||||
|
@default_group_required
|
||||||
|
@shared_access_required(Compensation, "id")
|
||||||
|
def create_resubmission_view(request: HttpRequest, id: str):
|
||||||
|
""" Renders resubmission form for a compensation
|
||||||
|
|
||||||
|
Args:
|
||||||
|
request (HttpRequest): The incoming request
|
||||||
|
id (str): Compensation's id
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
|
||||||
|
"""
|
||||||
|
com = get_object_or_404(Compensation, id=id)
|
||||||
|
form = ResubmissionModalForm(request.POST or None, instance=com, request=request)
|
||||||
|
form.action_url = reverse("compensation:resubmission-create", args=(id,))
|
||||||
|
return form.process_request(
|
||||||
|
request,
|
||||||
|
msg_success=_("Resubmission set"),
|
||||||
|
redirect_url=reverse("compensation:detail", args=(id,))
|
||||||
|
)
|
||||||
|
|||||||
@@ -16,20 +16,28 @@ from django.shortcuts import render, get_object_or_404, redirect
|
|||||||
|
|
||||||
from compensation.forms.forms import NewEcoAccountForm, EditEcoAccountForm
|
from compensation.forms.forms import NewEcoAccountForm, EditEcoAccountForm
|
||||||
from compensation.forms.modalForms import NewStateModalForm, NewActionModalForm, NewDeadlineModalForm, \
|
from compensation.forms.modalForms import NewStateModalForm, NewActionModalForm, NewDeadlineModalForm, \
|
||||||
NewEcoAccountDocumentForm
|
NewEcoAccountDocumentModalForm, RemoveCompensationActionModalForm, RemoveCompensationStateModalForm, \
|
||||||
|
EditCompensationStateModalForm, EditCompensationActionModalForm, EditDeadlineModalForm
|
||||||
from compensation.models import EcoAccount, EcoAccountDocument, CompensationState, CompensationAction
|
from compensation.models import EcoAccount, EcoAccountDocument, CompensationState, CompensationAction
|
||||||
from compensation.tables import EcoAccountTable
|
from compensation.tables import EcoAccountTable
|
||||||
from intervention.forms.modalForms import NewDeductionModalForm, ShareModalForm
|
from intervention.forms.modalForms import NewDeductionModalForm, ShareModalForm, RemoveEcoAccountDeductionModalForm, \
|
||||||
|
EditEcoAccountDeductionModalForm
|
||||||
from konova.contexts import BaseContext
|
from konova.contexts import BaseContext
|
||||||
from konova.decorators import any_group_check, default_group_required, conservation_office_group_required, \
|
from konova.decorators import any_group_check, default_group_required, conservation_office_group_required, \
|
||||||
shared_access_required
|
shared_access_required
|
||||||
from konova.forms import RemoveModalForm, SimpleGeomForm, NewDocumentForm, RecordModalForm
|
from konova.forms.modals import RemoveModalForm, RecordModalForm, \
|
||||||
|
RemoveDeadlineModalForm, EditDocumentModalForm, ResubmissionModalForm
|
||||||
|
from konova.forms import SimpleGeomForm
|
||||||
|
from konova.models import Deadline
|
||||||
from konova.settings import DEFAULT_GROUP, ZB_GROUP, ETS_GROUP
|
from konova.settings import DEFAULT_GROUP, ZB_GROUP, ETS_GROUP
|
||||||
from konova.sub_settings.context_settings import TAB_TITLE_IDENTIFIER
|
from konova.sub_settings.context_settings import TAB_TITLE_IDENTIFIER
|
||||||
from konova.utils.documents import get_document, remove_document
|
from konova.utils.documents import get_document, remove_document
|
||||||
from konova.utils.generators import generate_qr_code
|
from konova.utils.generators import generate_qr_code
|
||||||
from konova.utils.message_templates import IDENTIFIER_REPLACED, FORM_INVALID, DATA_UNSHARED, DATA_UNSHARED_EXPLANATION, \
|
from konova.utils.message_templates import IDENTIFIER_REPLACED, FORM_INVALID, \
|
||||||
CANCEL_ACC_RECORDED_OR_DEDUCTED
|
CANCEL_ACC_RECORDED_OR_DEDUCTED, DEDUCTION_REMOVED, DEDUCTION_ADDED, DOCUMENT_ADDED, COMPENSATION_STATE_REMOVED, \
|
||||||
|
COMPENSATION_STATE_ADDED, COMPENSATION_ACTION_REMOVED, COMPENSATION_ACTION_ADDED, DEADLINE_ADDED, DEADLINE_REMOVED, \
|
||||||
|
DEDUCTION_EDITED, DOCUMENT_EDITED, COMPENSATION_STATE_EDITED, COMPENSATION_ACTION_EDITED, DEADLINE_EDITED, \
|
||||||
|
RECORDED_BLOCKS_EDIT
|
||||||
from konova.utils.user_checks import in_group
|
from konova.utils.user_checks import in_group
|
||||||
|
|
||||||
|
|
||||||
@@ -89,7 +97,7 @@ def new_view(request: HttpRequest):
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
messages.success(request, _("Eco-Account {} added").format(acc.identifier))
|
messages.success(request, _("Eco-Account {} added").format(acc.identifier))
|
||||||
return redirect("compensation:acc-detail", id=acc.id)
|
return redirect("compensation:acc:detail", id=acc.id)
|
||||||
else:
|
else:
|
||||||
messages.error(request, FORM_INVALID, extra_tags="danger",)
|
messages.error(request, FORM_INVALID, extra_tags="danger",)
|
||||||
else:
|
else:
|
||||||
@@ -139,6 +147,13 @@ def edit_view(request: HttpRequest, id: str):
|
|||||||
template = "compensation/form/view.html"
|
template = "compensation/form/view.html"
|
||||||
# Get object from db
|
# Get object from db
|
||||||
acc = get_object_or_404(EcoAccount, id=id)
|
acc = get_object_or_404(EcoAccount, id=id)
|
||||||
|
if acc.is_recorded:
|
||||||
|
messages.info(
|
||||||
|
request,
|
||||||
|
RECORDED_BLOCKS_EDIT
|
||||||
|
)
|
||||||
|
return redirect("compensation:acc:detail", id=id)
|
||||||
|
|
||||||
# Create forms, initialize with values from db/from POST request
|
# Create forms, initialize with values from db/from POST request
|
||||||
data_form = EditEcoAccountForm(request.POST or None, instance=acc)
|
data_form = EditEcoAccountForm(request.POST or None, instance=acc)
|
||||||
geom_form = SimpleGeomForm(request.POST or None, read_only=False, instance=acc)
|
geom_form = SimpleGeomForm(request.POST or None, read_only=False, instance=acc)
|
||||||
@@ -147,7 +162,7 @@ def edit_view(request: HttpRequest, id: str):
|
|||||||
# The data form takes the geom form for processing, as well as the performing user
|
# The data form takes the geom form for processing, as well as the performing user
|
||||||
acc = data_form.save(request.user, geom_form)
|
acc = data_form.save(request.user, geom_form)
|
||||||
messages.success(request, _("Eco-Account {} edited").format(acc.identifier))
|
messages.success(request, _("Eco-Account {} edited").format(acc.identifier))
|
||||||
return redirect("compensation:acc-detail", id=acc.id)
|
return redirect("compensation:acc:detail", id=acc.id)
|
||||||
else:
|
else:
|
||||||
messages.error(request, FORM_INVALID, extra_tags="danger",)
|
messages.error(request, FORM_INVALID, extra_tags="danger",)
|
||||||
else:
|
else:
|
||||||
@@ -228,6 +243,7 @@ def detail_view(request: HttpRequest, id: str):
|
|||||||
"deductions": deductions,
|
"deductions": deductions,
|
||||||
"actions": actions,
|
"actions": actions,
|
||||||
TAB_TITLE_IDENTIFIER: f"{acc.identifier} - {acc.title}",
|
TAB_TITLE_IDENTIFIER: f"{acc.identifier} - {acc.title}",
|
||||||
|
"has_finished_deadlines": acc.get_finished_deadlines().exists(),
|
||||||
}
|
}
|
||||||
context = BaseContext(request, context).context
|
context = BaseContext(request, context).context
|
||||||
return render(request, template, context)
|
return render(request, template, context)
|
||||||
@@ -254,19 +270,18 @@ def remove_view(request: HttpRequest, id: str):
|
|||||||
user = request.user
|
user = request.user
|
||||||
if not in_group(user, ETS_GROUP):
|
if not in_group(user, ETS_GROUP):
|
||||||
messages.info(request, CANCEL_ACC_RECORDED_OR_DEDUCTED)
|
messages.info(request, CANCEL_ACC_RECORDED_OR_DEDUCTED)
|
||||||
return redirect("compensation:acc-detail", id=id)
|
return redirect("compensation:acc:detail", id=id)
|
||||||
|
|
||||||
form = RemoveModalForm(request.POST or None, instance=acc, request=request)
|
form = RemoveModalForm(request.POST or None, instance=acc, request=request)
|
||||||
return form.process_request(
|
return form.process_request(
|
||||||
request=request,
|
request=request,
|
||||||
msg_success=_("Eco-account removed"),
|
msg_success=_("Eco-account removed"),
|
||||||
redirect_url=reverse("compensation:acc-index"),
|
redirect_url=reverse("compensation:acc:index"),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
@default_group_required
|
@default_group_required
|
||||||
@shared_access_required(EcoAccount, "id")
|
|
||||||
def deduction_remove_view(request: HttpRequest, id: str, deduction_id: str):
|
def deduction_remove_view(request: HttpRequest, id: str, deduction_id: str):
|
||||||
""" Renders a modal view for removing deductions
|
""" Renders a modal view for removing deductions
|
||||||
|
|
||||||
@@ -281,13 +296,45 @@ def deduction_remove_view(request: HttpRequest, id: str, deduction_id: str):
|
|||||||
acc = get_object_or_404(EcoAccount, id=id)
|
acc = get_object_or_404(EcoAccount, id=id)
|
||||||
try:
|
try:
|
||||||
eco_deduction = acc.deductions.get(id=deduction_id)
|
eco_deduction = acc.deductions.get(id=deduction_id)
|
||||||
|
if not eco_deduction.intervention.is_shared_with(request.user):
|
||||||
|
raise ObjectDoesNotExist()
|
||||||
except ObjectDoesNotExist:
|
except ObjectDoesNotExist:
|
||||||
raise Http404("Unknown deduction")
|
raise Http404("Unknown deduction")
|
||||||
|
|
||||||
form = RemoveModalForm(request.POST or None, instance=eco_deduction, request=request)
|
form = RemoveEcoAccountDeductionModalForm(request.POST or None, instance=acc, deduction=eco_deduction, request=request)
|
||||||
return form.process_request(
|
return form.process_request(
|
||||||
request=request,
|
request=request,
|
||||||
msg_success=_("Deduction removed")
|
msg_success=DEDUCTION_REMOVED,
|
||||||
|
redirect_url=reverse("compensation:acc:detail", args=(id,)) + "#related_data"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@login_required
|
||||||
|
@default_group_required
|
||||||
|
def deduction_edit_view(request: HttpRequest, id: str, deduction_id: str):
|
||||||
|
""" Renders a modal view for editing deductions
|
||||||
|
|
||||||
|
Args:
|
||||||
|
request (HttpRequest): The incoming request
|
||||||
|
id (str): The eco account's id
|
||||||
|
deduction_id (str): The deduction's id
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
|
||||||
|
"""
|
||||||
|
acc = get_object_or_404(EcoAccount, id=id)
|
||||||
|
try:
|
||||||
|
eco_deduction = acc.deductions.get(id=deduction_id)
|
||||||
|
if not eco_deduction.intervention.is_shared_with(request.user):
|
||||||
|
raise ObjectDoesNotExist
|
||||||
|
except ObjectDoesNotExist:
|
||||||
|
raise Http404("Unknown deduction")
|
||||||
|
|
||||||
|
form = EditEcoAccountDeductionModalForm(request.POST or None, instance=acc, deduction=eco_deduction, request=request)
|
||||||
|
return form.process_request(
|
||||||
|
request=request,
|
||||||
|
msg_success=DEDUCTION_EDITED,
|
||||||
|
redirect_url=reverse("compensation:acc:detail", args=(id,)) + "#related_data"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@@ -357,7 +404,8 @@ def state_new_view(request: HttpRequest, id: str):
|
|||||||
form = NewStateModalForm(request.POST or None, instance=acc, request=request)
|
form = NewStateModalForm(request.POST or None, instance=acc, request=request)
|
||||||
return form.process_request(
|
return form.process_request(
|
||||||
request,
|
request,
|
||||||
msg_success=_("State added")
|
msg_success=COMPENSATION_STATE_ADDED,
|
||||||
|
redirect_url=reverse("compensation:acc:detail", args=(id,)) + "#related_data"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@@ -378,7 +426,8 @@ def action_new_view(request: HttpRequest, id: str):
|
|||||||
form = NewActionModalForm(request.POST or None, instance=acc, request=request)
|
form = NewActionModalForm(request.POST or None, instance=acc, request=request)
|
||||||
return form.process_request(
|
return form.process_request(
|
||||||
request,
|
request,
|
||||||
msg_success=_("Action added")
|
msg_success=COMPENSATION_ACTION_ADDED,
|
||||||
|
redirect_url=reverse("compensation:acc:detail", args=(id,)) + "#related_data"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@@ -396,11 +445,37 @@ def state_remove_view(request: HttpRequest, id: str, state_id: str):
|
|||||||
Returns:
|
Returns:
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
acc = get_object_or_404(EcoAccount, id=id)
|
||||||
state = get_object_or_404(CompensationState, id=state_id)
|
state = get_object_or_404(CompensationState, id=state_id)
|
||||||
form = RemoveModalForm(request.POST or None, instance=state, request=request)
|
form = RemoveCompensationStateModalForm(request.POST or None, instance=acc, state=state, request=request)
|
||||||
return form.process_request(
|
return form.process_request(
|
||||||
request,
|
request,
|
||||||
msg_success=_("State removed")
|
msg_success=COMPENSATION_STATE_REMOVED,
|
||||||
|
redirect_url=reverse("compensation:acc:detail", args=(id,)) + "#related_data"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@login_required
|
||||||
|
@default_group_required
|
||||||
|
@shared_access_required(EcoAccount, "id")
|
||||||
|
def state_edit_view(request: HttpRequest, id: str, state_id: str):
|
||||||
|
""" Renders a form for editing a compensation state
|
||||||
|
|
||||||
|
Args:
|
||||||
|
request (HttpRequest): The incoming request
|
||||||
|
id (str): The compensation's id
|
||||||
|
state_id (str): The state's id
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
|
||||||
|
"""
|
||||||
|
acc = get_object_or_404(EcoAccount, id=id)
|
||||||
|
state = get_object_or_404(CompensationState, id=state_id)
|
||||||
|
form = EditCompensationStateModalForm(request.POST or None, instance=acc, state=state, request=request)
|
||||||
|
return form.process_request(
|
||||||
|
request,
|
||||||
|
msg_success=COMPENSATION_STATE_EDITED,
|
||||||
|
redirect_url=reverse("compensation:acc:detail", args=(id,)) + "#related_data"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@@ -418,11 +493,85 @@ def action_remove_view(request: HttpRequest, id: str, action_id: str):
|
|||||||
Returns:
|
Returns:
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
acc = get_object_or_404(EcoAccount, id=id)
|
||||||
action = get_object_or_404(CompensationAction, id=action_id)
|
action = get_object_or_404(CompensationAction, id=action_id)
|
||||||
form = RemoveModalForm(request.POST or None, instance=action, request=request)
|
form = RemoveCompensationActionModalForm(request.POST or None, instance=acc, action=action, request=request)
|
||||||
return form.process_request(
|
return form.process_request(
|
||||||
request,
|
request,
|
||||||
msg_success=_("Action removed")
|
msg_success=COMPENSATION_ACTION_REMOVED,
|
||||||
|
redirect_url=reverse("compensation:acc:detail", args=(id,)) + "#related_data"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@login_required
|
||||||
|
@default_group_required
|
||||||
|
@shared_access_required(EcoAccount, "id")
|
||||||
|
def action_edit_view(request: HttpRequest, id: str, action_id: str):
|
||||||
|
""" Renders a form for editing a compensation action
|
||||||
|
|
||||||
|
Args:
|
||||||
|
request (HttpRequest): The incoming request
|
||||||
|
id (str): The compensation's id
|
||||||
|
id (str): The action's id
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
|
||||||
|
"""
|
||||||
|
acc = get_object_or_404(EcoAccount, id=id)
|
||||||
|
action = get_object_or_404(CompensationAction, id=action_id)
|
||||||
|
form = EditCompensationActionModalForm(request.POST or None, instance=acc, action=action, request=request)
|
||||||
|
return form.process_request(
|
||||||
|
request,
|
||||||
|
msg_success=COMPENSATION_ACTION_EDITED,
|
||||||
|
redirect_url=reverse("compensation:acc:detail", args=(id,)) + "#related_data"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@login_required
|
||||||
|
@default_group_required
|
||||||
|
@shared_access_required(EcoAccount, "id")
|
||||||
|
def deadline_edit_view(request: HttpRequest, id: str, deadline_id: str):
|
||||||
|
""" Renders a form for editing deadlines from a compensation
|
||||||
|
|
||||||
|
Args:
|
||||||
|
request (HttpRequest): The incoming request
|
||||||
|
id (str): The compensation's id
|
||||||
|
deadline_id (str): The deadline's id
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
|
||||||
|
"""
|
||||||
|
comp = get_object_or_404(EcoAccount, id=id)
|
||||||
|
deadline = get_object_or_404(Deadline, id=deadline_id)
|
||||||
|
form = EditDeadlineModalForm(request.POST or None, instance=comp, deadline=deadline, request=request)
|
||||||
|
return form.process_request(
|
||||||
|
request,
|
||||||
|
msg_success=DEADLINE_EDITED,
|
||||||
|
redirect_url=reverse("compensation:acc:detail", args=(id,)) + "#related_data"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@login_required
|
||||||
|
@default_group_required
|
||||||
|
@shared_access_required(EcoAccount, "id")
|
||||||
|
def deadline_remove_view(request: HttpRequest, id: str, deadline_id: str):
|
||||||
|
""" Renders a form for removing deadlines from a compensation
|
||||||
|
|
||||||
|
Args:
|
||||||
|
request (HttpRequest): The incoming request
|
||||||
|
id (str): The compensation's id
|
||||||
|
deadline_id (str): The deadline's id
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
|
||||||
|
"""
|
||||||
|
comp = get_object_or_404(EcoAccount, id=id)
|
||||||
|
deadline = get_object_or_404(Deadline, id=deadline_id)
|
||||||
|
form = RemoveDeadlineModalForm(request.POST or None, instance=comp, deadline=deadline, request=request)
|
||||||
|
return form.process_request(
|
||||||
|
request,
|
||||||
|
msg_success=DEADLINE_REMOVED,
|
||||||
|
redirect_url=reverse("compensation:acc:detail", args=(id,)) + "#related_data"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@@ -443,7 +592,8 @@ def deadline_new_view(request: HttpRequest, id: str):
|
|||||||
form = NewDeadlineModalForm(request.POST or None, instance=acc, request=request)
|
form = NewDeadlineModalForm(request.POST or None, instance=acc, request=request)
|
||||||
return form.process_request(
|
return form.process_request(
|
||||||
request,
|
request,
|
||||||
msg_success=_("Deadline added")
|
msg_success=DEADLINE_ADDED,
|
||||||
|
redirect_url=reverse("compensation:acc:detail", args=(id,)) + "#related_data"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@@ -460,55 +610,78 @@ def new_document_view(request: HttpRequest, id: str):
|
|||||||
|
|
||||||
"""
|
"""
|
||||||
acc = get_object_or_404(EcoAccount, id=id)
|
acc = get_object_or_404(EcoAccount, id=id)
|
||||||
form = NewEcoAccountDocumentForm(request.POST or None, request.FILES or None, instance=acc, request=request)
|
form = NewEcoAccountDocumentModalForm(request.POST or None, request.FILES or None, instance=acc, request=request)
|
||||||
return form.process_request(
|
return form.process_request(
|
||||||
request,
|
request,
|
||||||
msg_success=_("Document added")
|
msg_success=DOCUMENT_ADDED,
|
||||||
|
redirect_url=reverse("compensation:acc:detail", args=(id,)) + "#related_data",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
@default_group_required
|
@default_group_required
|
||||||
def get_document_view(request: HttpRequest, doc_id: str):
|
@shared_access_required(EcoAccount, "id")
|
||||||
|
def get_document_view(request: HttpRequest, id:str, doc_id: str):
|
||||||
""" Returns the document as downloadable file
|
""" Returns the document as downloadable file
|
||||||
|
|
||||||
Wraps the generic document fetcher function from konova.utils.
|
Wraps the generic document fetcher function from konova.utils.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
request (HttpRequest): The incoming request
|
request (HttpRequest): The incoming request
|
||||||
|
id (str): The account id
|
||||||
doc_id (str): The document id
|
doc_id (str): The document id
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
acc = get_object_or_404(EcoAccount, id=id)
|
||||||
doc = get_object_or_404(EcoAccountDocument, id=doc_id)
|
doc = get_object_or_404(EcoAccountDocument, id=doc_id)
|
||||||
user = request.user
|
|
||||||
instance = doc.instance
|
|
||||||
# File download only possible if related instance is shared with user
|
|
||||||
if not instance.users.filter(id=user.id):
|
|
||||||
messages.info(
|
|
||||||
request,
|
|
||||||
DATA_UNSHARED
|
|
||||||
)
|
|
||||||
return redirect("compensation:acc-detail", id=instance.id)
|
|
||||||
return get_document(doc)
|
return get_document(doc)
|
||||||
|
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
@default_group_required
|
@default_group_required
|
||||||
@shared_access_required(EcoAccount, "id")
|
@shared_access_required(EcoAccount, "id")
|
||||||
def remove_document_view(request: HttpRequest, doc_id: str):
|
def edit_document_view(request: HttpRequest, id: str, doc_id: str):
|
||||||
""" Removes the document from the database and file system
|
""" Removes the document from the database and file system
|
||||||
|
|
||||||
Wraps the generic functionality from konova.utils.
|
Wraps the generic functionality from konova.utils.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
request (HttpRequest): The incoming request
|
request (HttpRequest): The incoming request
|
||||||
|
id (str): The account id
|
||||||
doc_id (str): The document id
|
doc_id (str): The document id
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
acc = get_object_or_404(EcoAccount, id=id)
|
||||||
|
doc = get_object_or_404(EcoAccountDocument, id=doc_id)
|
||||||
|
form = EditDocumentModalForm(request.POST or None, request.FILES or None, instance=acc, document=doc, request=request)
|
||||||
|
return form.process_request(
|
||||||
|
request,
|
||||||
|
DOCUMENT_EDITED,
|
||||||
|
reverse("compensation:acc:detail", args=(id,)) + "#related_data"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@login_required
|
||||||
|
@default_group_required
|
||||||
|
@shared_access_required(EcoAccount, "id")
|
||||||
|
def remove_document_view(request: HttpRequest, id: str, doc_id: str):
|
||||||
|
""" Removes the document from the database and file system
|
||||||
|
|
||||||
|
Wraps the generic functionality from konova.utils.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
request (HttpRequest): The incoming request
|
||||||
|
id (str): The account id
|
||||||
|
doc_id (str): The document id
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
|
||||||
|
"""
|
||||||
|
acc = get_object_or_404(EcoAccount, id=id)
|
||||||
doc = get_object_or_404(EcoAccountDocument, id=doc_id)
|
doc = get_object_or_404(EcoAccountDocument, id=doc_id)
|
||||||
return remove_document(
|
return remove_document(
|
||||||
request,
|
request,
|
||||||
@@ -518,7 +691,6 @@ def remove_document_view(request: HttpRequest, doc_id: str):
|
|||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
@default_group_required
|
@default_group_required
|
||||||
@shared_access_required(EcoAccount, "id")
|
|
||||||
def new_deduction_view(request: HttpRequest, id: str):
|
def new_deduction_view(request: HttpRequest, id: str):
|
||||||
""" Renders a modal form view for creating deductions
|
""" Renders a modal form view for creating deductions
|
||||||
|
|
||||||
@@ -530,10 +702,13 @@ def new_deduction_view(request: HttpRequest, id: str):
|
|||||||
|
|
||||||
"""
|
"""
|
||||||
acc = get_object_or_404(EcoAccount, id=id)
|
acc = get_object_or_404(EcoAccount, id=id)
|
||||||
|
if not acc.recorded:
|
||||||
|
raise Http404()
|
||||||
form = NewDeductionModalForm(request.POST or None, instance=acc, request=request)
|
form = NewDeductionModalForm(request.POST or None, instance=acc, request=request)
|
||||||
return form.process_request(
|
return form.process_request(
|
||||||
request,
|
request,
|
||||||
msg_success=_("Deduction added")
|
msg_success=DEDUCTION_ADDED,
|
||||||
|
redirect_url=reverse("compensation:acc:detail", args=(id,)) + "#related_data"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@@ -566,18 +741,16 @@ def report_view(request:HttpRequest, id: str):
|
|||||||
instance=acc
|
instance=acc
|
||||||
)
|
)
|
||||||
parcels = acc.get_underlying_parcels()
|
parcels = acc.get_underlying_parcels()
|
||||||
qrcode_img = generate_qr_code(
|
|
||||||
request.build_absolute_uri(reverse("ema:report", args=(id,))),
|
qrcode_url = request.build_absolute_uri(reverse("ema:report", args=(id,)))
|
||||||
10
|
qrcode_img = generate_qr_code(qrcode_url, 10)
|
||||||
)
|
qrcode_lanis_url = acc.get_LANIS_link()
|
||||||
qrcode_img_lanis = generate_qr_code(
|
qrcode_img_lanis = generate_qr_code(qrcode_lanis_url, 7)
|
||||||
acc.get_LANIS_link(),
|
|
||||||
7
|
|
||||||
)
|
|
||||||
# Order states by surface
|
# Order states by surface
|
||||||
before_states = acc.before_states.all().order_by("-surface").select_related("biotope_type__parent")
|
before_states = acc.before_states.all().order_by("-surface").select_related("biotope_type__parent")
|
||||||
after_states = acc.after_states.all().order_by("-surface").select_related("biotope_type__parent")
|
after_states = acc.after_states.all().order_by("-surface").select_related("biotope_type__parent")
|
||||||
actions = acc.actions.all().select_related("action_type__parent")
|
actions = acc.actions.all().prefetch_related("action_type__parent")
|
||||||
|
|
||||||
# Reduce amount of db fetched data to the bare minimum we need in the template (deduction's intervention id and identifier)
|
# Reduce amount of db fetched data to the bare minimum we need in the template (deduction's intervention id and identifier)
|
||||||
deductions = acc.deductions.all()\
|
deductions = acc.deductions.all()\
|
||||||
@@ -587,8 +760,14 @@ def report_view(request:HttpRequest, id: str):
|
|||||||
|
|
||||||
context = {
|
context = {
|
||||||
"obj": acc,
|
"obj": acc,
|
||||||
"qrcode": qrcode_img,
|
"qrcode": {
|
||||||
"qrcode_lanis": qrcode_img_lanis,
|
"img": qrcode_img,
|
||||||
|
"url": qrcode_url,
|
||||||
|
},
|
||||||
|
"qrcode_lanis": {
|
||||||
|
"img": qrcode_img_lanis,
|
||||||
|
"url": qrcode_lanis_url,
|
||||||
|
},
|
||||||
"has_access": False, # disables action buttons during rendering
|
"has_access": False, # disables action buttons during rendering
|
||||||
"before_states": before_states,
|
"before_states": before_states,
|
||||||
"after_states": after_states,
|
"after_states": after_states,
|
||||||
@@ -631,8 +810,8 @@ def share_view(request: HttpRequest, id: str, token: str):
|
|||||||
request,
|
request,
|
||||||
_("{} has been shared with you").format(obj.identifier)
|
_("{} has been shared with you").format(obj.identifier)
|
||||||
)
|
)
|
||||||
obj.share_with(user)
|
obj.share_with_user(user)
|
||||||
return redirect("compensation:acc-detail", id=id)
|
return redirect("compensation:acc:detail", id=id)
|
||||||
else:
|
else:
|
||||||
messages.error(
|
messages.error(
|
||||||
request,
|
request,
|
||||||
@@ -660,4 +839,27 @@ def create_share_view(request: HttpRequest, id: str):
|
|||||||
return form.process_request(
|
return form.process_request(
|
||||||
request,
|
request,
|
||||||
msg_success=_("Share settings updated")
|
msg_success=_("Share settings updated")
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@login_required
|
||||||
|
@default_group_required
|
||||||
|
@shared_access_required(EcoAccount, "id")
|
||||||
|
def create_resubmission_view(request: HttpRequest, id: str):
|
||||||
|
""" Renders resubmission form for an eco account
|
||||||
|
|
||||||
|
Args:
|
||||||
|
request (HttpRequest): The incoming request
|
||||||
|
id (str): EcoAccount's id
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
|
||||||
|
"""
|
||||||
|
acc = get_object_or_404(EcoAccount, id=id)
|
||||||
|
form = ResubmissionModalForm(request.POST or None, instance=acc, request=request)
|
||||||
|
form.action_url = reverse("compensation:acc:resubmission-create", args=(id,))
|
||||||
|
return form.process_request(
|
||||||
|
request,
|
||||||
|
msg_success=_("Resubmission set"),
|
||||||
|
redirect_url=reverse("compensation:acc:detail", args=(id,))
|
||||||
)
|
)
|
||||||
@@ -5,54 +5,85 @@ Contact: michel.peltriaux@sgdnord.rlp.de
|
|||||||
Created on: 09.08.21
|
Created on: 09.08.21
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
from django.urls import reverse
|
||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
from django.contrib.auth.decorators import login_required
|
from django.contrib.auth.decorators import login_required
|
||||||
from django.http import HttpRequest
|
from django.http import HttpRequest
|
||||||
from django.shortcuts import get_object_or_404
|
from django.shortcuts import get_object_or_404
|
||||||
|
|
||||||
from compensation.forms.modalForms import NewPaymentForm
|
from compensation.forms.modalForms import NewPaymentForm, RemovePaymentModalForm, EditPaymentModalForm
|
||||||
from compensation.models import Payment
|
from compensation.models import Payment
|
||||||
from intervention.models import Intervention
|
from intervention.models import Intervention
|
||||||
from konova.decorators import default_group_required
|
from konova.decorators import default_group_required, shared_access_required
|
||||||
from konova.forms import RemoveModalForm
|
from konova.utils.message_templates import PAYMENT_ADDED, PAYMENT_REMOVED, PAYMENT_EDITED
|
||||||
|
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
@default_group_required
|
@default_group_required
|
||||||
def new_payment_view(request: HttpRequest, intervention_id: str):
|
@shared_access_required(Intervention, "id")
|
||||||
|
def new_payment_view(request: HttpRequest, id: str):
|
||||||
""" Renders a modal view for adding new payments
|
""" Renders a modal view for adding new payments
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
request (HttpRequest): The incoming request
|
request (HttpRequest): The incoming request
|
||||||
intervention_id (str): The intervention's id for which a new payment shall be added
|
id (str): The intervention's id for which a new payment shall be added
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
|
|
||||||
"""
|
"""
|
||||||
intervention = get_object_or_404(Intervention, id=intervention_id)
|
intervention = get_object_or_404(Intervention, id=id)
|
||||||
form = NewPaymentForm(request.POST or None, instance=intervention, request=request)
|
form = NewPaymentForm(request.POST or None, instance=intervention, request=request)
|
||||||
return form.process_request(
|
return form.process_request(
|
||||||
request,
|
request,
|
||||||
msg_success=_("Payment added")
|
msg_success=PAYMENT_ADDED,
|
||||||
|
redirect_url=reverse("intervention:detail", args=(id,)) + "#related_data"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
@default_group_required
|
@default_group_required
|
||||||
def payment_remove_view(request: HttpRequest, id: str):
|
@shared_access_required(Intervention, "id")
|
||||||
|
def payment_remove_view(request: HttpRequest, id: str, payment_id: str):
|
||||||
""" Renders a modal view for removing payments
|
""" Renders a modal view for removing payments
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
request (HttpRequest): The incoming request
|
request (HttpRequest): The incoming request
|
||||||
id (str): The payment's id
|
id (str): The intervention's id
|
||||||
|
payment_id (str): The payment's id
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
|
|
||||||
"""
|
"""
|
||||||
payment = get_object_or_404(Payment, id=id)
|
intervention = get_object_or_404(Intervention, id=id)
|
||||||
form = RemoveModalForm(request.POST or None, instance=payment, request=request)
|
payment = get_object_or_404(Payment, id=payment_id)
|
||||||
|
form = RemovePaymentModalForm(request.POST or None, instance=intervention, payment=payment, request=request)
|
||||||
return form.process_request(
|
return form.process_request(
|
||||||
request=request,
|
request=request,
|
||||||
msg_success=_("Payment removed"),
|
msg_success=PAYMENT_REMOVED,
|
||||||
|
redirect_url=reverse("intervention:detail", args=(payment.intervention_id,)) + "#related_data"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@login_required
|
||||||
|
@default_group_required
|
||||||
|
@shared_access_required(Intervention, "id")
|
||||||
|
def payment_edit_view(request: HttpRequest, id: str, payment_id: str):
|
||||||
|
""" Renders a modal view for editing payments
|
||||||
|
|
||||||
|
Args:
|
||||||
|
request (HttpRequest): The incoming request
|
||||||
|
id (str): The intervention's id
|
||||||
|
payment_id (str): The payment's id
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
|
||||||
|
"""
|
||||||
|
intervention = get_object_or_404(Intervention, id=id)
|
||||||
|
payment = get_object_or_404(Payment, id=payment_id)
|
||||||
|
form = EditPaymentModalForm(request.POST or None, instance=intervention, payment=payment, request=request)
|
||||||
|
return form.process_request(
|
||||||
|
request=request,
|
||||||
|
msg_success=PAYMENT_EDITED,
|
||||||
|
redirect_url=reverse("intervention:detail", args=(payment.intervention_id,)) + "#related_data"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
42
ema/forms.py
42
ema/forms.py
@@ -5,21 +5,21 @@ Contact: michel.peltriaux@sgdnord.rlp.de
|
|||||||
Created on: 06.10.21
|
Created on: 06.10.21
|
||||||
|
|
||||||
"""
|
"""
|
||||||
from dal import autocomplete
|
|
||||||
from django import forms
|
|
||||||
from user.models import User
|
from user.models import User
|
||||||
from django.db import transaction
|
from django.db import transaction
|
||||||
from django.urls import reverse, reverse_lazy
|
from django.urls import reverse, reverse_lazy
|
||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
|
|
||||||
from compensation.forms.forms import AbstractCompensationForm, CompensationResponsibleFormMixin
|
from compensation.forms.forms import AbstractCompensationForm, CompensationResponsibleFormMixin, \
|
||||||
|
PikCompensationFormMixin
|
||||||
from ema.models import Ema, EmaDocument
|
from ema.models import Ema, EmaDocument
|
||||||
from intervention.models import Responsibility
|
from intervention.models import Responsibility, Handler
|
||||||
from konova.forms import SimpleGeomForm, NewDocumentForm
|
from konova.forms import SimpleGeomForm
|
||||||
|
from konova.forms.modals import NewDocumentModalForm
|
||||||
from user.models import UserActionLogEntry
|
from user.models import UserActionLogEntry
|
||||||
|
|
||||||
|
|
||||||
class NewEmaForm(AbstractCompensationForm, CompensationResponsibleFormMixin):
|
class NewEmaForm(AbstractCompensationForm, CompensationResponsibleFormMixin, PikCompensationFormMixin):
|
||||||
""" Form for creating new EMA objects.
|
""" Form for creating new EMA objects.
|
||||||
|
|
||||||
Inherits basic form fields from AbstractCompensationForm and additional from CompensationResponsibleFormMixin.
|
Inherits basic form fields from AbstractCompensationForm and additional from CompensationResponsibleFormMixin.
|
||||||
@@ -31,7 +31,9 @@ class NewEmaForm(AbstractCompensationForm, CompensationResponsibleFormMixin):
|
|||||||
"title",
|
"title",
|
||||||
"conservation_office",
|
"conservation_office",
|
||||||
"conservation_file_number",
|
"conservation_file_number",
|
||||||
"handler",
|
"is_pik",
|
||||||
|
"handler_type",
|
||||||
|
"handler_detail",
|
||||||
"comment",
|
"comment",
|
||||||
]
|
]
|
||||||
|
|
||||||
@@ -53,9 +55,11 @@ class NewEmaForm(AbstractCompensationForm, CompensationResponsibleFormMixin):
|
|||||||
# Fetch data from cleaned POST values
|
# Fetch data from cleaned POST values
|
||||||
identifier = self.cleaned_data.get("identifier", None)
|
identifier = self.cleaned_data.get("identifier", None)
|
||||||
title = self.cleaned_data.get("title", None)
|
title = self.cleaned_data.get("title", None)
|
||||||
handler = self.cleaned_data.get("handler", None)
|
handler_type = self.cleaned_data.get("handler_type", None)
|
||||||
|
handler_detail = self.cleaned_data.get("handler_detail", None)
|
||||||
conservation_office = self.cleaned_data.get("conservation_office", None)
|
conservation_office = self.cleaned_data.get("conservation_office", None)
|
||||||
conservation_file_number = self.cleaned_data.get("conservation_file_number", None)
|
conservation_file_number = self.cleaned_data.get("conservation_file_number", None)
|
||||||
|
is_pik = self.cleaned_data.get("is_pik", None)
|
||||||
comment = self.cleaned_data.get("comment", None)
|
comment = self.cleaned_data.get("comment", None)
|
||||||
|
|
||||||
# Create log entry
|
# Create log entry
|
||||||
@@ -63,6 +67,10 @@ class NewEmaForm(AbstractCompensationForm, CompensationResponsibleFormMixin):
|
|||||||
# Process the geometry form
|
# Process the geometry form
|
||||||
geometry = geom_form.save(action)
|
geometry = geom_form.save(action)
|
||||||
|
|
||||||
|
handler = Handler.objects.create(
|
||||||
|
type=handler_type,
|
||||||
|
detail=handler_detail
|
||||||
|
)
|
||||||
responsible = Responsibility.objects.create(
|
responsible = Responsibility.objects.create(
|
||||||
handler=handler,
|
handler=handler,
|
||||||
conservation_file_number=conservation_file_number,
|
conservation_file_number=conservation_file_number,
|
||||||
@@ -77,10 +85,11 @@ class NewEmaForm(AbstractCompensationForm, CompensationResponsibleFormMixin):
|
|||||||
created=action,
|
created=action,
|
||||||
geometry=geometry,
|
geometry=geometry,
|
||||||
comment=comment,
|
comment=comment,
|
||||||
|
is_pik=is_pik,
|
||||||
)
|
)
|
||||||
|
|
||||||
# Add the creating user to the list of shared users
|
# Add the creating user to the list of shared users
|
||||||
acc.share_with(user)
|
acc.share_with_user(user)
|
||||||
|
|
||||||
# Add the log entry to the main objects log list
|
# Add the log entry to the main objects log list
|
||||||
acc.log.add(action)
|
acc.log.add(action)
|
||||||
@@ -105,10 +114,12 @@ class EditEmaForm(NewEmaForm):
|
|||||||
form_data = {
|
form_data = {
|
||||||
"identifier": self.instance.identifier,
|
"identifier": self.instance.identifier,
|
||||||
"title": self.instance.title,
|
"title": self.instance.title,
|
||||||
"handler": self.instance.responsible.handler,
|
"handler_type": self.instance.responsible.handler.type,
|
||||||
|
"handler_detail": self.instance.responsible.handler.detail,
|
||||||
"conservation_office": self.instance.responsible.conservation_office,
|
"conservation_office": self.instance.responsible.conservation_office,
|
||||||
"conservation_file_number": self.instance.responsible.conservation_file_number,
|
"conservation_file_number": self.instance.responsible.conservation_file_number,
|
||||||
"comment": self.instance.comment,
|
"comment": self.instance.comment,
|
||||||
|
"is_pik": self.instance.is_pik,
|
||||||
}
|
}
|
||||||
disabled_fields = []
|
disabled_fields = []
|
||||||
self.load_initial_data(
|
self.load_initial_data(
|
||||||
@@ -121,10 +132,12 @@ class EditEmaForm(NewEmaForm):
|
|||||||
# Fetch data from cleaned POST values
|
# Fetch data from cleaned POST values
|
||||||
identifier = self.cleaned_data.get("identifier", None)
|
identifier = self.cleaned_data.get("identifier", None)
|
||||||
title = self.cleaned_data.get("title", None)
|
title = self.cleaned_data.get("title", None)
|
||||||
handler = self.cleaned_data.get("handler", None)
|
handler_type = self.cleaned_data.get("handler_type", None)
|
||||||
|
handler_detail = self.cleaned_data.get("handler_detail", None)
|
||||||
conservation_office = self.cleaned_data.get("conservation_office", None)
|
conservation_office = self.cleaned_data.get("conservation_office", None)
|
||||||
conservation_file_number = self.cleaned_data.get("conservation_file_number", None)
|
conservation_file_number = self.cleaned_data.get("conservation_file_number", None)
|
||||||
comment = self.cleaned_data.get("comment", None)
|
comment = self.cleaned_data.get("comment", None)
|
||||||
|
is_pik = self.cleaned_data.get("is_pik", None)
|
||||||
|
|
||||||
# Create log entry
|
# Create log entry
|
||||||
action = UserActionLogEntry.get_edited_action(user)
|
action = UserActionLogEntry.get_edited_action(user)
|
||||||
@@ -132,7 +145,9 @@ class EditEmaForm(NewEmaForm):
|
|||||||
geometry = geom_form.save(action)
|
geometry = geom_form.save(action)
|
||||||
|
|
||||||
# Update responsible data
|
# Update responsible data
|
||||||
self.instance.responsible.handler = handler
|
self.instance.responsible.handler.type = handler_type
|
||||||
|
self.instance.responsible.handler.detail = handler_detail
|
||||||
|
self.instance.responsible.handler.save()
|
||||||
self.instance.responsible.conservation_office = conservation_office
|
self.instance.responsible.conservation_office = conservation_office
|
||||||
self.instance.responsible.conservation_file_number = conservation_file_number
|
self.instance.responsible.conservation_file_number = conservation_file_number
|
||||||
self.instance.responsible.save()
|
self.instance.responsible.save()
|
||||||
@@ -142,6 +157,7 @@ class EditEmaForm(NewEmaForm):
|
|||||||
self.instance.title = title
|
self.instance.title = title
|
||||||
self.instance.geometry = geometry
|
self.instance.geometry = geometry
|
||||||
self.instance.comment = comment
|
self.instance.comment = comment
|
||||||
|
self.instance.is_pik = is_pik
|
||||||
self.instance.modified = action
|
self.instance.modified = action
|
||||||
self.instance.save()
|
self.instance.save()
|
||||||
|
|
||||||
@@ -150,5 +166,5 @@ class EditEmaForm(NewEmaForm):
|
|||||||
return self.instance
|
return self.instance
|
||||||
|
|
||||||
|
|
||||||
class NewEmaDocumentForm(NewDocumentForm):
|
class NewEmaDocumentModalForm(NewDocumentModalForm):
|
||||||
document_model = EmaDocument
|
document_model = EmaDocument
|
||||||
19
ema/migrations/0003_ema_teams.py
Normal file
19
ema/migrations/0003_ema_teams.py
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
# Generated by Django 3.1.3 on 2022-02-18 09:13
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('user', '0003_team'),
|
||||||
|
('ema', '0002_auto_20220114_0936'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='ema',
|
||||||
|
name='teams',
|
||||||
|
field=models.ManyToManyField(help_text='Teams having access (data shared with)', to='user.Team'),
|
||||||
|
),
|
||||||
|
]
|
||||||
18
ema/migrations/0004_ema_is_pik.py
Normal file
18
ema/migrations/0004_ema_is_pik.py
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
# Generated by Django 3.1.3 on 2022-05-31 10:45
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('ema', '0003_ema_teams'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='ema',
|
||||||
|
name='is_pik',
|
||||||
|
field=models.BooleanField(blank=True, default=False, help_text="Flag if compensation is a 'Produktonsintegrierte Kompensation'", null=True),
|
||||||
|
),
|
||||||
|
]
|
||||||
19
ema/migrations/0005_ema_resubmission.py
Normal file
19
ema/migrations/0005_ema_resubmission.py
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
# Generated by Django 3.1.3 on 2022-08-15 06:03
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('konova', '0014_resubmission'),
|
||||||
|
('ema', '0004_ema_is_pik'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='ema',
|
||||||
|
name='resubmission',
|
||||||
|
field=models.ManyToManyField(blank=True, null=True, related_name='_ema_resubmission_+', to='konova.Resubmission'),
|
||||||
|
),
|
||||||
|
]
|
||||||
23
ema/migrations/0006_auto_20220815_0803.py
Normal file
23
ema/migrations/0006_auto_20220815_0803.py
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
# Generated by Django 3.1.3 on 2022-08-15 06:03
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('konova', '0014_resubmission'),
|
||||||
|
('ema', '0005_ema_resubmission'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.RemoveField(
|
||||||
|
model_name='ema',
|
||||||
|
name='resubmission',
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='ema',
|
||||||
|
name='resubmissions',
|
||||||
|
field=models.ManyToManyField(blank=True, null=True, related_name='_ema_resubmissions_+', to='konova.Resubmission'),
|
||||||
|
),
|
||||||
|
]
|
||||||
19
ema/migrations/0007_auto_20220815_1030.py
Normal file
19
ema/migrations/0007_auto_20220815_1030.py
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
# Generated by Django 3.1.3 on 2022-08-15 08:30
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('konova', '0014_resubmission'),
|
||||||
|
('ema', '0006_auto_20220815_0803'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='ema',
|
||||||
|
name='resubmissions',
|
||||||
|
field=models.ManyToManyField(blank=True, related_name='_ema_resubmissions_+', to='konova.Resubmission'),
|
||||||
|
),
|
||||||
|
]
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user