Recording data
* adds dynamic icon for recording and unrecording of data * adds record view to intervention and eco accounts * adds quality_check() method for Intervention and EcoAccount class which holds logic for data quality checking * adds UserAction "unrecorded"
This commit is contained in:
@@ -408,9 +408,13 @@ class RunCheckForm(BaseModalForm):
|
||||
def is_valid(self):
|
||||
super_result = super().is_valid()
|
||||
# Perform check
|
||||
result, msgs = self.instance.check_validity()
|
||||
self.errors.update(msgs)
|
||||
return result & super_result
|
||||
msgs = self.instance.quality_check()
|
||||
for msg in msgs:
|
||||
self.add_error(
|
||||
"checked_intervention",
|
||||
msg
|
||||
)
|
||||
return super_result and (len(msgs) == 0)
|
||||
|
||||
def save(self):
|
||||
with transaction.atomic():
|
||||
|
||||
@@ -194,39 +194,62 @@ class Intervention(BaseObject):
|
||||
self.identifier = new_id
|
||||
super().save(*args, **kwargs)
|
||||
|
||||
def check_validity(self) -> (bool, dict):
|
||||
""" Validity check
|
||||
def quality_check(self) -> list:
|
||||
""" Quality check
|
||||
|
||||
Returns:
|
||||
ret_msgs (list): True if quality acceptable, False otherwise
|
||||
"""
|
||||
ret_msgs = []
|
||||
|
||||
self._check_quality_responsible_data(ret_msgs)
|
||||
self._check_quality_legal_data(ret_msgs)
|
||||
|
||||
# ToDo: Extend for more!
|
||||
|
||||
return ret_msgs
|
||||
|
||||
def _check_quality_responsible_data(self, ret_msgs: list):
|
||||
""" Checks data quality of related ResponsibilityData
|
||||
|
||||
Args:
|
||||
ret_msgs (dict): Holds error messages
|
||||
|
||||
Returns:
|
||||
|
||||
"""
|
||||
ret_msgs = {}
|
||||
missing_str = _("Missing")
|
||||
not_missing_str = _("Exists")
|
||||
try:
|
||||
# Check for file numbers
|
||||
if not self.responsible.registration_file_number or len(self.responsible.registration_file_number) == 0:
|
||||
ret_msgs.append(_("Registration office file number missing"))
|
||||
|
||||
# Check responsible data
|
||||
if self.responsible:
|
||||
if self.responsible.registration_file_number is None or len(self.responsible.registration_file_number) == 0:
|
||||
ret_msgs["Registration office file number"] = missing_str
|
||||
if self.responsible.conservation_file_number is None or len(self.responsible.conservation_file_number) == 0:
|
||||
ret_msgs["Conversation office file number"] = missing_str
|
||||
else:
|
||||
ret_msgs["responsible"] = missing_str
|
||||
if not self.responsible.conservation_file_number or len(self.responsible.conservation_file_number) == 0:
|
||||
ret_msgs.append(_("Conversation office file number missing"))
|
||||
except AttributeError:
|
||||
# responsible data not found
|
||||
ret_msgs.append(_("Responsible data missing"))
|
||||
|
||||
# Check revocation
|
||||
if self.legal.revocation:
|
||||
ret_msgs["Revocation"] = not_missing_str
|
||||
def _check_quality_legal_data(self, ret_msgs: list):
|
||||
""" Checks data quality of related LegalData
|
||||
|
||||
Args:
|
||||
ret_msgs (dict): Holds error messages
|
||||
|
||||
Returns:
|
||||
|
||||
"""
|
||||
try:
|
||||
# Check for a revocation
|
||||
if self.legal.revocation:
|
||||
ret_msgs.append(_("Revocation exists"))
|
||||
|
||||
if self.legal:
|
||||
if self.legal.registration_date is None:
|
||||
ret_msgs["Registration date"] = missing_str
|
||||
if self.legal.binding_date is None:
|
||||
ret_msgs["Binding on"] = missing_str
|
||||
else:
|
||||
ret_msgs["legal"] = missing_str
|
||||
ret_msgs.append(_("Registration date missing"))
|
||||
|
||||
ret_result = len(ret_msgs) == 0
|
||||
return ret_result, ret_msgs
|
||||
if self.legal.binding_date is None:
|
||||
ret_msgs.append(_("Binding on missing"))
|
||||
except AttributeError:
|
||||
ret_msgs.append(_("Legal data missing"))
|
||||
|
||||
def get_LANIS_link(self) -> str:
|
||||
""" Generates a link for LANIS depending on the geometry
|
||||
@@ -248,4 +271,4 @@ class Intervention(BaseObject):
|
||||
zoom_lvl,
|
||||
x,
|
||||
y,
|
||||
)
|
||||
)
|
||||
|
||||
@@ -12,33 +12,37 @@
|
||||
</button>
|
||||
</a>
|
||||
{% if has_access %}
|
||||
<button class="btn btn-default btn-modal mr-2" title="{% trans 'Share' %}" data-form-url="{% url 'intervention:share-create' intervention.id %}">
|
||||
{% fa5_icon 'share-alt' %}
|
||||
</button>
|
||||
{% if is_zb_member %}
|
||||
<button class="btn btn-default btn-modal mr-2" title="{% trans 'Run check' %}" data-form-url="{% url 'intervention:run-check' intervention.id %}">
|
||||
{% fa5_icon 'star' %}
|
||||
</button>
|
||||
{% endif %}
|
||||
{% if is_ets_member %}
|
||||
<a href="{% url 'home' %}" class="mr-2">
|
||||
<button class="btn btn-default" title="{% trans 'Record' %}">
|
||||
{% fa5_icon 'bookmark' %}
|
||||
<button class="btn btn-default btn-modal mr-2" title="{% trans 'Share' %}" data-form-url="{% url 'intervention:share-create' intervention.id %}">
|
||||
{% fa5_icon 'share-alt' %}
|
||||
</button>
|
||||
</a>
|
||||
{% endif %}
|
||||
{% if is_default_member %}
|
||||
<a href="{% url 'home' %}" class="mr-2">
|
||||
<button class="btn btn-default" title="{% trans 'Edit' %}">
|
||||
{% fa5_icon 'edit' %}
|
||||
{% if is_zb_member %}
|
||||
<button class="btn btn-default btn-modal mr-2" title="{% trans 'Run check' %}" data-form-url="{% url 'intervention:run-check' intervention.id %}">
|
||||
{% fa5_icon 'star' %}
|
||||
</button>
|
||||
{% endif %}
|
||||
{% if is_ets_member %}
|
||||
{% if intervention.recorded %}
|
||||
<button class="btn btn-default btn-modal mr-2" title="{% trans 'Unrecord' %}" data-form-url="{% url 'intervention:record' intervention.id %}">
|
||||
{% fa5_icon 'bookmark' 'far' %}
|
||||
</button>
|
||||
{% else %}
|
||||
<button class="btn btn-default btn-modal mr-2" title="{% trans 'Record' %}" data-form-url="{% url 'intervention:record' intervention.id %}">
|
||||
{% fa5_icon 'bookmark' %}
|
||||
</button>
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
{% if is_default_member %}
|
||||
<a href="{% url 'home' %}" class="mr-2">
|
||||
<button class="btn btn-default" title="{% trans 'Edit' %}">
|
||||
{% fa5_icon 'edit' %}
|
||||
</button>
|
||||
</a>
|
||||
<button class="btn btn-default btn-modal mr-2" data-form-url="{% url 'intervention:log' intervention.id %}" title="{% trans 'Show log' %}">
|
||||
{% fa5_icon 'history' %}
|
||||
</button>
|
||||
<button class="btn btn-default btn-modal" data-form-url="{% url 'intervention:remove' intervention.id %}" title="{% trans 'Delete' %}">
|
||||
{% fa5_icon 'trash' %}
|
||||
</button>
|
||||
</a>
|
||||
<button class="btn btn-default btn-modal mr-2" data-form-url="{% url 'intervention:log' intervention.id %}" title="{% trans 'Show log' %}">
|
||||
{% fa5_icon 'history' %}
|
||||
</button>
|
||||
<button class="btn btn-default btn-modal" data-form-url="{% url 'intervention:remove' intervention.id %}" title="{% trans 'Delete' %}">
|
||||
{% fa5_icon 'trash' %}
|
||||
</button>
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
</div>
|
||||
@@ -8,7 +8,8 @@ Created on: 30.11.20
|
||||
from django.urls import path
|
||||
|
||||
from intervention.views import index_view, new_view, open_view, edit_view, remove_view, new_document_view, share_view, \
|
||||
create_share_view, remove_revocation_view, new_revocation_view, run_check_view, log_view, new_withdraw_view
|
||||
create_share_view, remove_revocation_view, new_revocation_view, run_check_view, log_view, new_withdraw_view, \
|
||||
record_view
|
||||
|
||||
app_name = "intervention"
|
||||
urlpatterns = [
|
||||
@@ -22,6 +23,7 @@ urlpatterns = [
|
||||
path('<id>/share/<token>', share_view, name='share'),
|
||||
path('<id>/share', create_share_view, name='share-create'),
|
||||
path('<id>/check', run_check_view, name='run-check'),
|
||||
path('<id>/record', record_view, name='record'),
|
||||
|
||||
# Withdraws
|
||||
path('<id>/withdraw/new', new_withdraw_view, name='acc-new-withdraw'),
|
||||
|
||||
@@ -10,9 +10,9 @@ from intervention.models import Intervention, Revocation
|
||||
from intervention.tables import InterventionTable
|
||||
from konova.contexts import BaseContext
|
||||
from konova.decorators import *
|
||||
from konova.forms import SimpleGeomForm, NewDocumentForm, RemoveModalForm
|
||||
from konova.forms import SimpleGeomForm, NewDocumentForm, RemoveModalForm, RecordForm
|
||||
from konova.sub_settings.django_settings import DEFAULT_DATE_FORMAT
|
||||
from konova.utils.message_templates import FORM_INVALID
|
||||
from konova.utils.message_templates import FORM_INVALID, INTERVENTION_INVALID
|
||||
from konova.utils.user_checks import in_group
|
||||
|
||||
|
||||
@@ -304,34 +304,11 @@ def run_check_view(request: HttpRequest, id: str):
|
||||
"""
|
||||
intervention = get_object_or_404(Intervention, id=id)
|
||||
form = RunCheckForm(request.POST or None, instance=intervention, user=request.user)
|
||||
if request.method == "POST":
|
||||
if form.is_valid():
|
||||
form.save()
|
||||
messages.info(
|
||||
request,
|
||||
_("Check performed")
|
||||
)
|
||||
else:
|
||||
messages.error(
|
||||
request,
|
||||
_("There has been errors on this intervention:"),
|
||||
extra_tags="danger"
|
||||
)
|
||||
for error_name, error_val in form.errors.items():
|
||||
messages.error(
|
||||
request,
|
||||
_("{}: {}").format(_(error_name), _(error_val)),
|
||||
extra_tags="danger"
|
||||
)
|
||||
return redirect(request.META.get("HTTP_REFERER", "home"))
|
||||
elif request.method == "GET":
|
||||
context = {
|
||||
"form": form,
|
||||
}
|
||||
context = BaseContext(request, context).context
|
||||
return render(request, form.template, context)
|
||||
else:
|
||||
raise NotImplementedError
|
||||
return form.process_request(
|
||||
request,
|
||||
msg_success=_("Check performed"),
|
||||
msg_error=INTERVENTION_INVALID
|
||||
)
|
||||
|
||||
|
||||
@login_required
|
||||
@@ -413,3 +390,26 @@ def new_withdraw_view(request: HttpRequest, id: str):
|
||||
request,
|
||||
msg_success=_("Withdraw added")
|
||||
)
|
||||
|
||||
|
||||
@login_required
|
||||
@conservation_office_group_required
|
||||
def record_view(request: HttpRequest, id: str):
|
||||
""" Renders a modal form for recording an intervention
|
||||
|
||||
Args:
|
||||
request (HttpRequest): The incoming request
|
||||
id (str): The intervention's id
|
||||
|
||||
Returns:
|
||||
|
||||
"""
|
||||
intervention = get_object_or_404(Intervention, id=id)
|
||||
form = RecordForm(request.POST or None, instance=intervention, user=request.user)
|
||||
msg_succ = _("{} unrecorded") if intervention.recorded else _("{} recorded")
|
||||
msg_succ = msg_succ.format(intervention.identifier)
|
||||
return form.process_request(
|
||||
request,
|
||||
msg_succ,
|
||||
msg_error=_("There are errors on this intervention:")
|
||||
)
|
||||
Reference in New Issue
Block a user