* adds EditEcoAccountForm
* adds placeholders for some form fields
* changes comment card in detail view into rlp-grayish
* adds eco account detail view comment box
* removes unnecessary loading of dal scripts in view.html
* refactors generated identifier for data objects (10 digits to 6 uppercase letter-digit combination)
* improves generate_random_string() method by adding more options for generation of strings
* adds/updates translations
This commit is contained in:
mipel
2021-10-06 13:10:10 +02:00
parent ac665c9268
commit 98f8a222dc
20 changed files with 305 additions and 166 deletions

View File

@@ -64,7 +64,7 @@ class AbstractCompensationForm(BaseForm):
widget=autocomplete.ModelSelect2Multiple(
url="codes-compensation-funding-autocomplete",
attrs={
"data-placeholder": _("Funding by..."),
"data-placeholder": _("Click for selection"),
}
),
)
@@ -101,7 +101,7 @@ class NewCompensationForm(AbstractCompensationForm):
widget=autocomplete.ModelSelect2(
url="interventions-autocomplete",
attrs={
"data-placeholder": _("Intervention"),
"data-placeholder": _("Click for selection"),
"data-minimum-input-length": 3,
}
),
@@ -236,6 +236,7 @@ class NewEcoAccountForm(AbstractCompensationForm):
widget=autocomplete.ModelSelect2(
url="codes-conservation-office-autocomplete",
attrs={
"data-placeholder": _("Click for selection")
}
),
)
@@ -264,23 +265,10 @@ class NewEcoAccountForm(AbstractCompensationForm):
}
)
)
surface = forms.DecimalField(
min_value=0.00,
decimal_places=2,
label=_("Available Surface"),
label_suffix="",
help_text=_("The amount that can be used for deductions"),
widget=forms.NumberInput(
attrs={
"class": "form-control",
}
)
)
field_order = [
"identifier",
"title",
"conservation_office",
"surface",
"conservation_file_number",
"handler",
"fundings",
@@ -307,7 +295,6 @@ class NewEcoAccountForm(AbstractCompensationForm):
title = self.cleaned_data.get("title", None)
fundings = self.cleaned_data.get("fundings", None)
handler = self.cleaned_data.get("handler", None)
deductable_surface = self.cleaned_data.get("surface", None)
conservation_office = self.cleaned_data.get("conservation_office", None)
conservation_file_number = self.cleaned_data.get("conservation_file_number", None)
comment = self.cleaned_data.get("comment", None)
@@ -331,7 +318,7 @@ class NewEcoAccountForm(AbstractCompensationForm):
identifier=identifier,
title=title,
responsible=responsible,
deductable_surface=deductable_surface,
deductable_surface=0.00,
created=action,
geometry=geometry,
comment=comment,
@@ -341,4 +328,94 @@ class NewEcoAccountForm(AbstractCompensationForm):
# Add the log entry to the main objects log list
acc.log.add(action)
return acc
return acc
class EditEcoAccountForm(NewEcoAccountForm):
surface = forms.DecimalField(
min_value=0.00,
decimal_places=2,
label=_("Available Surface"),
label_suffix="",
required=False,
help_text=_("The amount that can be used for deductions"),
widget=forms.NumberInput(
attrs={
"class": "form-control",
"placeholder": "0,00"
}
)
)
field_order = [
"identifier",
"title",
"conservation_office",
"surface",
"conservation_file_number",
"handler",
"fundings",
"comment",
]
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.form_title = _("Edit Eco-Account")
self.action_url = reverse("compensation:acc-edit", args=(self.instance.id,))
self.cancel_redirect = reverse("compensation:acc-open", args=(self.instance.id,))
# Initialize form data
form_data = {
"identifier": self.instance.identifier,
"title": self.instance.title,
"surface": self.instance.deductable_surface,
"handler": self.instance.responsible.handler,
"conservation_office": self.instance.responsible.conservation_office,
"conservation_file_number": self.instance.responsible.conservation_file_number,
"fundings": self.instance.fundings.all(),
"comment": self.instance.comment,
}
disabled_fields = []
self.load_initial_data(
form_data,
disabled_fields
)
def save(self, user: User, geom_form: SimpleGeomForm):
with transaction.atomic():
# Fetch data from cleaned POST values
identifier = self.cleaned_data.get("identifier", None)
title = self.cleaned_data.get("title", None)
fundings = self.cleaned_data.get("fundings", None)
handler = self.cleaned_data.get("handler", None)
surface = self.cleaned_data.get("surface", None)
conservation_office = self.cleaned_data.get("conservation_office", None)
conservation_file_number = self.cleaned_data.get("conservation_file_number", None)
comment = self.cleaned_data.get("comment", None)
# Create log entry
action = UserActionLogEntry.objects.create(
user=user,
action=UserAction.EDITED,
)
# Process the geometry form
geometry = geom_form.save(action)
# Update responsible data
self.instance.responsible.handler = handler
self.instance.responsible.conservation_office = conservation_office
self.instance.responsible.conservation_file_number = conservation_file_number
self.instance.responsible.save()
# Update main oject data
self.instance.identifier = identifier
self.instance.title = title
self.instance.deductable_surface = surface
self.instance.geometry = geometry
self.instance.comment = comment
self.instance.save()
self.instance.fundings.set(fundings)
# Add the log entry to the main objects log list
self.instance.log.add(action)
return self.instance

View File

@@ -36,7 +36,8 @@ class NewPaymentForm(BaseModalForm):
help_text=_("in Euro"),
widget=forms.NumberInput(
attrs={
"class": "form-control"
"class": "form-control",
"placeholder": "0,00",
}
)
)
@@ -73,7 +74,6 @@ class NewPaymentForm(BaseModalForm):
self.intervention = self.instance
self.form_title = _("Payment")
self.form_caption = _("Add a payment for intervention '{}'").format(self.intervention.title)
self.add_placeholder_for_field("amount", "0,00")
def is_valid(self):
"""
@@ -156,6 +156,7 @@ class NewStateModalForm(BaseModalForm):
widget=forms.NumberInput(
attrs={
"class": "form-control",
"placeholder": "0,00"
}
)
)
@@ -164,7 +165,6 @@ class NewStateModalForm(BaseModalForm):
super().__init__(*args, **kwargs)
self.form_title = _("New state")
self.form_caption = _("Insert data for the new state")
self.add_placeholder_for_field("surface", "0,00")
def save(self, is_before_state: bool = False):
with transaction.atomic():
@@ -357,6 +357,7 @@ class NewActionModalForm(BaseModalForm):
widget=forms.NumberInput(
attrs={
"class": "form-control",
"placeholder": "0,00",
}
)
)
@@ -378,7 +379,6 @@ class NewActionModalForm(BaseModalForm):
super().__init__(*args, **kwargs)
self.form_title = _("New action")
self.form_caption = _("Insert data for the new action")
self.add_placeholder_for_field("amount", "0,00")
def save(self):
with transaction.atomic():

View File

@@ -5,8 +5,8 @@ Contact: michel.peltriaux@sgdnord.rlp.de
Created on: 18.12.20
"""
COMPENSATION_IDENTIFIER_LENGTH = 10
COMPENSATION_IDENTIFIER_LENGTH = 6
COMPENSATION_IDENTIFIER_TEMPLATE = "KOM-{}"
ECO_ACCOUNT_IDENTIFIER_LENGTH = 10
ECO_ACCOUNT_IDENTIFIER_LENGTH = 6
ECO_ACCOUNT_IDENTIFIER_TEMPLATE = "OEK-{}"

View File

@@ -3,7 +3,7 @@
{% if obj.comment %}
<div class="w-100">
<div class="card mt-3">
<div class="card-header rlp-r">
<div class="card-header rlp-gd">
<div class="row">
<div class="col-sm-12 col-md-12 col-lg-12">
<h5 class="card-title">

View File

@@ -0,0 +1,23 @@
{% load i18n fontawesome_5 %}
{% if obj.comment %}
<div class="w-100">
<div class="card mt-3">
<div class="card-header rlp-gd">
<div class="row">
<div class="col-sm-12 col-md-12 col-lg-12">
<h5 class="card-title">
{% fa5_icon 'info-circle' %}
{% trans 'Comment' %}
</h5>
</div>
</div>
</div>
<div class="card-body">
<div class="card-text font-italic">
{{obj.comment}}
</div>
</div>
</div>
</div>
{% endif %}

View File

@@ -24,7 +24,7 @@
{% endif %}
{% endif %}
{% if is_default_member %}
<a href="{% url 'home' %}" class="mr-2">
<a href="{% url 'compensation:acc-edit' obj.id %}" class="mr-2">
<button class="btn btn-default" title="{% trans 'Edit' %}">
{% fa5_icon 'edit' %}
</button>

View File

@@ -30,10 +30,10 @@
<th class="w-25" scope="row">{% trans 'Title' %}</th>
<td class="align-middle">{{obj.title}}</td>
</tr>
<tr>
<tr {% if not obj.deductable_surface %}class="alert alert-danger" title="{% trans 'No surface deductable' %}" {% endif %}>
<th scope="row">{% trans 'Available' %}</th>
<td class="align-middle">
{{available_total|floatformat:2}} / {{obj.deductable_surface|floatformat:2}} m²
{{available_total|floatformat:2}} / {{obj.deductable_surface|default_if_none:0.00|floatformat:2}} m²
{% with available as value %}
{% include 'konova/custom_widgets/progressbar.html' %}
{% endwith %}
@@ -98,7 +98,12 @@
</div>
</div>
<div class="col-sm-12 col-md-12 col-lg-6">
{% include 'map/geom_form.html' %}
<div class="row">
{% include 'map/geom_form.html' %}
</div>
<div class="row">
{% include 'compensation/detail/compensation/includes/comment.html' %}
</div>
</div>
</div>
<hr>

View File

@@ -1,16 +1,6 @@
{% extends 'base.html' %}
{% load i18n l10n %}
{% block head %}
{% comment %}
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.
Therefore the script linkages from form.media have been extracted and put inside dal/scripts.html to ensure
these scripts are loaded when needed.
{% endcomment %}
{% include 'dal/scripts.html' %}
{% endblock %}
{% block body %}
{% include 'form/main_data_collapse_form.html' %}
{% endblock %}

View File

@@ -14,7 +14,7 @@ from django.core.exceptions import ObjectDoesNotExist
from django.http import HttpRequest, Http404, JsonResponse
from django.shortcuts import render, get_object_or_404, redirect
from compensation.forms.forms import NewEcoAccountForm
from compensation.forms.forms import NewEcoAccountForm, EditEcoAccountForm
from compensation.forms.modalForms import NewStateModalForm, NewActionModalForm, NewDeadlineModalForm
from compensation.models import EcoAccount, EcoAccountDocument
from compensation.tables import EcoAccountTable
@@ -120,8 +120,38 @@ def new_id_view(request: HttpRequest):
@login_required
@default_group_required
def edit_view(request: HttpRequest, id: str):
# ToDo
pass
"""
Renders a view for editing compensations
Args:
request (HttpRequest): The incoming request
Returns:
"""
template = "compensation/new/view.html"
# Get object from db
acc = get_object_or_404(EcoAccount, 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)
if request.method == "POST":
if data_form.is_valid() and geom_form.is_valid():
# The data form takes the geom form for processing, as well as the performing user
acc = data_form.save(request.user, geom_form)
messages.success(request, _("Eco-Account {} edited").format(acc.identifier))
return redirect("compensation:acc-open", id=acc.id)
else:
messages.error(request, FORM_INVALID)
else:
# For clarification: nothing in this case
pass
context = {
"form": data_form,
"geom_form": geom_form,
}
context = BaseContext(request, context).context
return render(request, template, context)
@login_required