Intervention check
* adds functionality for check button * adds highlighting of important data on detail view for intervention * adds deleting logic to BaseObject model and BaseResource model * adds RunCheckForm * adds check_validity() method to Intervention class * fixes wrong success msg for adding documents * adds/updates translations
This commit is contained in:
@@ -6,6 +6,7 @@ from intervention.models import Intervention, ResponsibilityData, LegalData, Rev
|
||||
class InterventionAdmin(admin.ModelAdmin):
|
||||
list_display = [
|
||||
"id",
|
||||
"identifier",
|
||||
"title",
|
||||
"created",
|
||||
"deleted",
|
||||
|
||||
@@ -383,3 +383,42 @@ class NewRevocationForm(BaseModalForm):
|
||||
self.instance.legal.revocation = revocation
|
||||
self.instance.legal.save()
|
||||
return revocation
|
||||
|
||||
|
||||
class RunCheckForm(BaseModalForm):
|
||||
checked_intervention = forms.BooleanField(
|
||||
label=_("Checked intervention data"),
|
||||
label_suffix="",
|
||||
widget=forms.CheckboxInput(),
|
||||
required=True,
|
||||
)
|
||||
checked_comps = forms.BooleanField(
|
||||
label=_("Checked compensations data and payments"),
|
||||
label_suffix="",
|
||||
widget=forms.CheckboxInput(),
|
||||
required=True
|
||||
)
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
self.form_title = _("Run check")
|
||||
self.form_caption = _("I, {} {}, confirm that all necessary control steps have been performed by myself.").format(self.user.first_name, self.user.last_name)
|
||||
|
||||
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
|
||||
|
||||
def save(self):
|
||||
with transaction.atomic():
|
||||
user_action = UserActionLogEntry.objects.create(
|
||||
user=self.user,
|
||||
action=UserAction.CHECKED
|
||||
)
|
||||
# Replace old checked
|
||||
if self.instance.checked:
|
||||
self.instance.checked.delete()
|
||||
self.instance.checked = user_action
|
||||
self.instance.save()
|
||||
@@ -9,6 +9,7 @@ from django.contrib.auth.models import User
|
||||
from django.contrib.gis.db import models
|
||||
from django.db import transaction
|
||||
from django.utils import timezone
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
from django.utils.timezone import now
|
||||
|
||||
from intervention.settings import INTERVENTION_IDENTIFIER_LENGTH, INTERVENTION_IDENTIFIER_TEMPLATE
|
||||
@@ -133,36 +134,6 @@ class Intervention(BaseObject):
|
||||
def __str__(self):
|
||||
return "{} ({})".format(self.identifier, self.title)
|
||||
|
||||
def delete(self, *args, **kwargs):
|
||||
""" Custom delete functionality
|
||||
|
||||
Does not delete from database but sets a timestamp for being deleted on and which user deleted the object
|
||||
|
||||
Args:
|
||||
*args ():
|
||||
**kwargs ():
|
||||
|
||||
Returns:
|
||||
|
||||
"""
|
||||
_now = timezone.now()
|
||||
_user = kwargs.get("user", None)
|
||||
|
||||
with transaction.atomic():
|
||||
# "Delete" related compensations as well
|
||||
coms = self.compensations.all()
|
||||
action = UserActionLogEntry.objects.create(
|
||||
user=_user,
|
||||
timestamp=_now,
|
||||
action=UserAction.DELETED
|
||||
)
|
||||
for com in coms:
|
||||
com.deleted = action
|
||||
com.save()
|
||||
|
||||
self.deleted = action
|
||||
self.save()
|
||||
|
||||
@staticmethod
|
||||
def _generate_new_identifier() -> str:
|
||||
""" Generates a new identifier for the intervention object
|
||||
@@ -234,3 +205,37 @@ class Intervention(BaseObject):
|
||||
|
||||
"""
|
||||
return self.users.filter(username=user.username).exists()
|
||||
|
||||
def check_validity(self) -> (bool, dict):
|
||||
""" Validity check
|
||||
|
||||
Returns:
|
||||
|
||||
"""
|
||||
ret_msgs = {}
|
||||
missing_str = _("Missing")
|
||||
not_missing_str = _("Exists")
|
||||
|
||||
# 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
|
||||
|
||||
# Check revocation
|
||||
if self.legal.revocation:
|
||||
ret_msgs["Revocation"] = not_missing_str
|
||||
|
||||
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_result = len(ret_msgs) == 0
|
||||
return ret_result, ret_msgs
|
||||
@@ -16,11 +16,9 @@
|
||||
{% fa5_icon 'share-alt' %}
|
||||
</button>
|
||||
{% if is_zb_member %}
|
||||
<a href="{% url 'home' %}" class="mr-2">
|
||||
<button class="btn btn-default" title="{% trans 'Run check' %}">
|
||||
{% fa5_icon 'star' %}
|
||||
</button>
|
||||
</a>
|
||||
<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">
|
||||
|
||||
@@ -20,15 +20,15 @@
|
||||
<div class="col-sm-12 col-md-12 col-lg-6">
|
||||
<div class="table-container">
|
||||
<table class="table table-hover">
|
||||
<tr>
|
||||
<tr {% if not intervention.title %}class="alert alert-danger"{% endif %}>
|
||||
<th class="w-25" scope="row">{% trans 'Title' %}</th>
|
||||
<td class="align-middle">{{intervention.title}}</td>
|
||||
<td class="align-middle">{{intervention.title|default_if_none:""}}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<tr {% if not intervention.legal.process_type %}class="alert alert-danger"{% endif %}>
|
||||
<th scope="row">{% trans 'Process type' %}</th>
|
||||
<td class="align-middle">{{intervention.legal.process_type|default_if_none:""}}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<tr {% if not intervention.legal.law %}class="alert alert-danger"{% endif %}>
|
||||
<th scope="row">{% trans 'Law' %}</th>
|
||||
<td class="align-middle">{{intervention.legal.law|default_if_none:""}}</td>
|
||||
</tr>
|
||||
@@ -36,7 +36,7 @@
|
||||
<th scope="row">{% trans 'Registration office' %}</th>
|
||||
<td class="align-middle">{{intervention.responsible.registration_office|default_if_none:""}}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<tr {% if not intervention.responsible.registration_file_number %}class="alert alert-danger"{% endif %}>
|
||||
<th scope="row">{% trans 'Registration office file number' %}</th>
|
||||
<td class="align-middle">{{intervention.responsible.registration_file_number|default_if_none:""}}</td>
|
||||
</tr>
|
||||
@@ -44,11 +44,11 @@
|
||||
<th scope="row">{% trans 'Conservation office' %}</th>
|
||||
<td class="align-middle">{{intervention.responsible.conservation_office|default_if_none:""}}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<tr{% if not intervention.responsible.conservation_file_number %}class="alert alert-danger"{% endif %}>
|
||||
<th scope="row">{% trans 'Conversation office file number' %}</th>
|
||||
<td class="align-middle">{{intervention.responsible.conservation_file_number|default_if_none:""}}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<tr {% if not intervention.responsible.handler %}class="alert alert-danger"{% endif %}>
|
||||
<th scope="row">{% trans 'Intervention handler' %}</th>
|
||||
<td class="align-middle">{{intervention.responsible.handler|default_if_none:""}}</td>
|
||||
</tr>
|
||||
@@ -80,11 +80,11 @@
|
||||
{% endif %}
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<tr {% if not intervention.legal.registration_date %}class="alert alert-danger"{% endif %}>
|
||||
<th scope="row">{% trans 'Registration date' %}</th>
|
||||
<td class="align-middle">{{intervention.legal.registration_date|default_if_none:""}}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<tr {% if not intervention.legal.binding_date %}class="alert alert-danger"{% endif %}>
|
||||
<th scope="row">{% trans 'Binding on' %}</th>
|
||||
<td class="align-middle">{{intervention.legal.binding_date|default_if_none:""}}</td>
|
||||
</tr>
|
||||
|
||||
@@ -8,7 +8,7 @@ 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
|
||||
create_share_view, remove_revocation_view, new_revocation_view, run_check_view
|
||||
|
||||
app_name = "intervention"
|
||||
urlpatterns = [
|
||||
@@ -20,6 +20,7 @@ urlpatterns = [
|
||||
path('<id>/remove', remove_view, name='remove'),
|
||||
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'),
|
||||
|
||||
# Revocation routes
|
||||
path('<id>/revocation/new', new_revocation_view, name='revocation-new'),
|
||||
|
||||
@@ -4,7 +4,8 @@ from django.utils.translation import gettext_lazy as _
|
||||
from django.http import HttpRequest
|
||||
from django.shortcuts import render, get_object_or_404
|
||||
|
||||
from intervention.forms import NewInterventionForm, EditInterventionForm, ShareInterventionForm, NewRevocationForm
|
||||
from intervention.forms import NewInterventionForm, EditInterventionForm, ShareInterventionForm, NewRevocationForm, \
|
||||
RunCheckForm
|
||||
from intervention.models import Intervention, Revocation
|
||||
from intervention.tables import InterventionTable
|
||||
from konova.contexts import BaseContext
|
||||
@@ -90,7 +91,10 @@ def new_document_view(request: HttpRequest, id: str):
|
||||
"""
|
||||
intervention = get_object_or_404(Intervention, id=id)
|
||||
form = NewDocumentForm(request.POST or None, request.FILES or None, instance=intervention, user=request.user)
|
||||
return form.process_request(request)
|
||||
return form.process_request(
|
||||
request,
|
||||
msg_success=_("Document added")
|
||||
)
|
||||
|
||||
|
||||
@login_required
|
||||
@@ -286,6 +290,49 @@ def create_share_view(request: HttpRequest, id: str):
|
||||
raise NotImplementedError
|
||||
|
||||
|
||||
@login_required
|
||||
def run_check_view(request: HttpRequest, id: str):
|
||||
""" Renders check form for an intervention
|
||||
|
||||
Args:
|
||||
request (HttpRequest): The incoming request
|
||||
id (str): Intervention's id
|
||||
|
||||
Returns:
|
||||
|
||||
"""
|
||||
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
|
||||
|
||||
|
||||
@login_required
|
||||
def new_revocation_view(request: HttpRequest, id: str):
|
||||
""" Renders sharing form for an intervention
|
||||
|
||||
Reference in New Issue
Block a user