Merge branch 'master' into 138_New_map_client
This commit is contained in:
@@ -21,16 +21,30 @@ class AbstractCompensationAdmin(BaseObjectAdmin):
|
||||
"identifier",
|
||||
"title",
|
||||
"comment",
|
||||
"after_states",
|
||||
"before_states",
|
||||
"list_after_states",
|
||||
"list_before_states",
|
||||
"geometry",
|
||||
]
|
||||
|
||||
def get_readonly_fields(self, request, obj=None):
|
||||
return super().get_readonly_fields(request, obj) + [
|
||||
"after_states",
|
||||
"before_states",
|
||||
"list_after_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):
|
||||
autocomplete_fields = [
|
||||
|
||||
@@ -418,6 +418,18 @@ class Compensation(AbstractCompensation, CEFMixin, CoherenceMixin):
|
||||
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):
|
||||
"""
|
||||
|
||||
@@ -134,7 +134,7 @@ class CompensationTable(BaseTable, TableRenderMixin):
|
||||
|
||||
"""
|
||||
parcels = value.get_underlying_parcels().values_list(
|
||||
"gmrkng",
|
||||
"parcel_group__name",
|
||||
flat=True
|
||||
).distinct()
|
||||
html = render_to_string(
|
||||
@@ -181,9 +181,7 @@ class CompensationTable(BaseTable, TableRenderMixin):
|
||||
"""
|
||||
if value is None:
|
||||
value = User.objects.none()
|
||||
has_access = value.filter(
|
||||
id=self.user.id
|
||||
).exists()
|
||||
has_access = record.is_shared_with(self.user)
|
||||
|
||||
html = self.render_icn(
|
||||
tooltip=_("Full access granted") if has_access else _("Access not granted"),
|
||||
@@ -295,7 +293,7 @@ class EcoAccountTable(BaseTable, TableRenderMixin):
|
||||
|
||||
"""
|
||||
parcels = value.get_underlying_parcels().values_list(
|
||||
"gmrkng",
|
||||
"parcel_group__name",
|
||||
flat=True
|
||||
).distinct()
|
||||
html = render_to_string(
|
||||
@@ -343,7 +341,7 @@ class EcoAccountTable(BaseTable, TableRenderMixin):
|
||||
html = ""
|
||||
# Do not use value in here, since value does use unprefetched 'users' manager, where record has already
|
||||
# prefetched users data
|
||||
has_access = self.user in record.users.all()
|
||||
has_access = record.is_shared_with(self.user)
|
||||
html += self.render_icn(
|
||||
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",
|
||||
|
||||
@@ -90,9 +90,15 @@
|
||||
<tr>
|
||||
<th scope="row">{% trans 'Last modified' %}</th>
|
||||
<td class="align-middle">
|
||||
{{obj.modified.timestamp|default_if_none:""|naturalday}}
|
||||
<br>
|
||||
{{obj.modified.user.username}}
|
||||
{% if obj.modified %}
|
||||
{{obj.modified.timestamp|default_if_none:""}}
|
||||
<br>
|
||||
{{obj.modified.user.username}}
|
||||
{% else %}
|
||||
{{obj.created.timestamp|default_if_none:""}}
|
||||
<br>
|
||||
{{obj.created.user.username}}
|
||||
{% endif %}
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
|
||||
@@ -73,9 +73,15 @@
|
||||
<tr>
|
||||
<th scope="row">{% trans 'Last modified' %}</th>
|
||||
<td class="align-middle">
|
||||
{{obj.modified.timestamp|default_if_none:""|naturalday}}
|
||||
<br>
|
||||
{{obj.modified.user.username}}
|
||||
{% if obj.modified %}
|
||||
{{obj.modified.timestamp|default_if_none:""}}
|
||||
<br>
|
||||
{{obj.modified.user.username}}
|
||||
{% else %}
|
||||
{{obj.created.timestamp|default_if_none:""}}
|
||||
<br>
|
||||
{{obj.created.user.username}}
|
||||
{% endif %}
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
|
||||
@@ -43,14 +43,7 @@
|
||||
{% include 'konova/includes/parcels.html' %}
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-sm-6 col-md-6 col-lg-6">
|
||||
<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>
|
||||
{% include 'konova/includes/report/qrcodes.html' %}
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
@@ -56,14 +56,7 @@
|
||||
{% include 'konova/includes/parcels.html' %}
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-sm-6 col-md-6 col-lg-6">
|
||||
<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>
|
||||
{% include 'konova/includes/report/qrcodes.html' %}
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
@@ -60,8 +60,9 @@ class CompensationWorkflowTestCase(BaseWorkflowTestCase):
|
||||
|
||||
# Preserve the current number of intervention's compensations
|
||||
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.assertEqual(num_compensations + 1, self.intervention.compensations.count())
|
||||
new_compensation = self.intervention.compensations.get(identifier=test_id)
|
||||
@@ -261,3 +262,26 @@ class CompensationWorkflowTestCase(BaseWorkflowTestCase):
|
||||
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
|
||||
|
||||
User must be redirected to another page
|
||||
|
||||
Returns:
|
||||
|
||||
"""
|
||||
self.assertIsNotNone(self.compensation)
|
||||
self.assertFalse(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.assertFalse(has_redirect)
|
||||
|
||||
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)
|
||||
|
||||
@@ -302,3 +302,27 @@ class EcoAccountWorkflowTestCase(BaseWorkflowTestCase):
|
||||
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)
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
from django.contrib.auth.decorators import login_required
|
||||
from django.core.exceptions import ObjectDoesNotExist
|
||||
from django.db.models import Sum
|
||||
from django.http import HttpRequest, JsonResponse
|
||||
from django.shortcuts import render
|
||||
@@ -22,7 +23,7 @@ from konova.utils.message_templates import FORM_INVALID, IDENTIFIER_REPLACED, DA
|
||||
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
|
||||
DEADLINE_EDITED, RECORDED_BLOCKS_EDIT, PARAMS_INVALID
|
||||
from konova.utils.user_checks import in_group
|
||||
|
||||
|
||||
@@ -69,6 +70,19 @@ def new_view(request: HttpRequest, intervention_id: str = None):
|
||||
|
||||
"""
|
||||
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)
|
||||
geom_form = SimpleGeomForm(request.POST or None, read_only=False)
|
||||
if request.method == "POST":
|
||||
@@ -134,6 +148,13 @@ def edit_view(request: HttpRequest, id: str):
|
||||
template = "compensation/form/view.html"
|
||||
# Get object from db
|
||||
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
|
||||
data_form = EditCompensationForm(request.POST or None, instance=comp)
|
||||
geom_form = SimpleGeomForm(request.POST or None, read_only=False, instance=comp)
|
||||
@@ -596,14 +617,12 @@ def report_view(request: HttpRequest, id: str):
|
||||
instance=comp
|
||||
)
|
||||
parcels = comp.get_underlying_parcels()
|
||||
qrcode_img = generate_qr_code(
|
||||
request.build_absolute_uri(reverse("compensation:report", args=(id,))),
|
||||
10
|
||||
)
|
||||
qrcode_img_lanis = generate_qr_code(
|
||||
comp.get_LANIS_link(),
|
||||
7
|
||||
)
|
||||
|
||||
qrcode_url = request.build_absolute_uri(reverse("compensation:report", args=(id,)))
|
||||
qrcode_img = generate_qr_code(qrcode_url, 10)
|
||||
qrcode_lanis_url = comp.get_LANIS_link()
|
||||
qrcode_img_lanis = generate_qr_code(qrcode_lanis_url, 7)
|
||||
|
||||
# Order states by surface
|
||||
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")
|
||||
@@ -611,8 +630,14 @@ def report_view(request: HttpRequest, id: str):
|
||||
|
||||
context = {
|
||||
"obj": comp,
|
||||
"qrcode": qrcode_img,
|
||||
"qrcode_lanis": qrcode_img_lanis,
|
||||
"qrcode": {
|
||||
"img": qrcode_img,
|
||||
"url": qrcode_url,
|
||||
},
|
||||
"qrcode_lanis": {
|
||||
"img": qrcode_img_lanis,
|
||||
"url": qrcode_lanis_url,
|
||||
},
|
||||
"has_access": False, # disables action buttons during rendering
|
||||
"before_states": before_states,
|
||||
"after_states": after_states,
|
||||
|
||||
@@ -35,7 +35,8 @@ from konova.utils.generators import generate_qr_code
|
||||
from konova.utils.message_templates import IDENTIFIER_REPLACED, FORM_INVALID, DATA_UNSHARED, DATA_UNSHARED_EXPLANATION, \
|
||||
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
|
||||
DEDUCTION_EDITED, DOCUMENT_EDITED, COMPENSATION_STATE_EDITED, COMPENSATION_ACTION_EDITED, DEADLINE_EDITED, \
|
||||
RECORDED_BLOCKS_EDIT
|
||||
from konova.utils.user_checks import in_group
|
||||
|
||||
|
||||
@@ -145,6 +146,13 @@ def edit_view(request: HttpRequest, id: str):
|
||||
template = "compensation/form/view.html"
|
||||
# Get object from db
|
||||
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
|
||||
data_form = EditEcoAccountForm(request.POST or None, instance=acc)
|
||||
geom_form = SimpleGeomForm(request.POST or None, read_only=False, instance=acc)
|
||||
@@ -731,18 +739,16 @@ def report_view(request:HttpRequest, id: str):
|
||||
instance=acc
|
||||
)
|
||||
parcels = acc.get_underlying_parcels()
|
||||
qrcode_img = generate_qr_code(
|
||||
request.build_absolute_uri(reverse("ema:report", args=(id,))),
|
||||
10
|
||||
)
|
||||
qrcode_img_lanis = generate_qr_code(
|
||||
acc.get_LANIS_link(),
|
||||
7
|
||||
)
|
||||
|
||||
qrcode_url = request.build_absolute_uri(reverse("ema:report", args=(id,)))
|
||||
qrcode_img = generate_qr_code(qrcode_url, 10)
|
||||
qrcode_lanis_url = acc.get_LANIS_link()
|
||||
qrcode_img_lanis = generate_qr_code(qrcode_lanis_url, 7)
|
||||
|
||||
# Order states by surface
|
||||
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")
|
||||
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)
|
||||
deductions = acc.deductions.all()\
|
||||
@@ -752,8 +758,14 @@ def report_view(request:HttpRequest, id: str):
|
||||
|
||||
context = {
|
||||
"obj": acc,
|
||||
"qrcode": qrcode_img,
|
||||
"qrcode_lanis": qrcode_img_lanis,
|
||||
"qrcode": {
|
||||
"img": qrcode_img,
|
||||
"url": qrcode_url,
|
||||
},
|
||||
"qrcode_lanis": {
|
||||
"img": qrcode_img_lanis,
|
||||
"url": qrcode_lanis_url,
|
||||
},
|
||||
"has_access": False, # disables action buttons during rendering
|
||||
"before_states": before_states,
|
||||
"after_states": after_states,
|
||||
|
||||
Reference in New Issue
Block a user