#7 New forms
* introduces bootstrap class form-control for proper html form input rendering * fixes bug where missing shared users for an entry resulted in a None exception * adds GenerateInput with template in generate-content-input.html, which provides a generate button for fetching server-side content * adds/updates translations
This commit is contained in:
@@ -9,13 +9,14 @@ from dal import autocomplete
|
||||
from django import forms
|
||||
from django.contrib.auth.models import User
|
||||
from django.db import transaction
|
||||
from django.urls import reverse
|
||||
from django.urls import reverse, reverse_lazy
|
||||
from django.utils import timezone
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
from codelist.models import KonovaCode
|
||||
from codelist.settings import CODELIST_PROCESS_TYPE_ID, CODELIST_LAW_ID, \
|
||||
CODELIST_REGISTRATION_OFFICE_ID, CODELIST_CONSERVATION_OFFICE_ID
|
||||
from intervention.inputs import GenerateInput
|
||||
from intervention.models import Intervention, LegalData, ResponsibilityData
|
||||
from konova.forms import BaseForm, SimpleGeomForm
|
||||
from user.models import UserActionLogEntry, UserAction
|
||||
@@ -27,6 +28,12 @@ class NewInterventionForm(BaseForm):
|
||||
label_suffix="",
|
||||
max_length=255,
|
||||
help_text=_("Generated automatically"),
|
||||
widget=GenerateInput(
|
||||
attrs={
|
||||
"class": "form-control",
|
||||
"url": reverse_lazy("intervention:new-id"),
|
||||
}
|
||||
)
|
||||
)
|
||||
title = forms.CharField(
|
||||
label=_("Title"),
|
||||
@@ -35,7 +42,8 @@ class NewInterventionForm(BaseForm):
|
||||
max_length=255,
|
||||
widget=forms.TextInput(
|
||||
attrs={
|
||||
"placeholder": _("Construction XY; Location ABC")
|
||||
"placeholder": _("Construction XY; Location ABC"),
|
||||
"class": "form-control",
|
||||
}
|
||||
)
|
||||
)
|
||||
@@ -108,7 +116,8 @@ class NewInterventionForm(BaseForm):
|
||||
required=False,
|
||||
widget=forms.TextInput(
|
||||
attrs={
|
||||
"placeholder": _("ZB-123/ABC.456")
|
||||
"placeholder": _("ZB-123/ABC.456"),
|
||||
"class": "form-control",
|
||||
}
|
||||
)
|
||||
)
|
||||
@@ -119,7 +128,8 @@ class NewInterventionForm(BaseForm):
|
||||
required=False,
|
||||
widget=forms.TextInput(
|
||||
attrs={
|
||||
"placeholder": _("ETS-123/ABC.456")
|
||||
"placeholder": _("ETS-123/ABC.456"),
|
||||
"class": "form-control",
|
||||
}
|
||||
)
|
||||
)
|
||||
@@ -131,7 +141,8 @@ class NewInterventionForm(BaseForm):
|
||||
help_text=_("Who performs the intervention"),
|
||||
widget=forms.TextInput(
|
||||
attrs={
|
||||
"placeholder": _("Company Mustermann")
|
||||
"placeholder": _("Company Mustermann"),
|
||||
"class": "form-control",
|
||||
}
|
||||
)
|
||||
)
|
||||
@@ -142,6 +153,7 @@ class NewInterventionForm(BaseForm):
|
||||
widget=forms.DateInput(
|
||||
attrs={
|
||||
"type": "date",
|
||||
"class": "form-control",
|
||||
},
|
||||
format="%d.%m.%Y"
|
||||
)
|
||||
@@ -153,6 +165,7 @@ class NewInterventionForm(BaseForm):
|
||||
widget=forms.DateInput(
|
||||
attrs={
|
||||
"type": "date",
|
||||
"class": "form-control",
|
||||
},
|
||||
format="%d.%m.%Y"
|
||||
)
|
||||
@@ -165,14 +178,11 @@ class NewInterventionForm(BaseForm):
|
||||
widget=forms.Textarea(
|
||||
attrs={
|
||||
"rows": 5,
|
||||
"class": "w-100"
|
||||
"class": "form-control"
|
||||
}
|
||||
)
|
||||
)
|
||||
|
||||
# Define w-100 for all form fields
|
||||
full_width_fields = True
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
self.form_title = _("New intervention")
|
||||
@@ -281,12 +291,10 @@ class EditInterventionForm(NewInterventionForm):
|
||||
"binding_date": bind_date,
|
||||
"comment": self.instance.comment,
|
||||
}
|
||||
disabled_fields = [
|
||||
"identifier",
|
||||
]
|
||||
disabled_fields = []
|
||||
self.load_initial_data(
|
||||
form_data,
|
||||
disabled_fields,
|
||||
disabled_fields
|
||||
)
|
||||
|
||||
def save(self, user: User, geom_form: SimpleGeomForm):
|
||||
|
||||
@@ -31,7 +31,8 @@ class ShareInterventionModalForm(BaseModalForm):
|
||||
required=False,
|
||||
widget=TextToClipboardInput(
|
||||
attrs={
|
||||
"readonly": True
|
||||
"readonly": True,
|
||||
"class": "form-control",
|
||||
}
|
||||
)
|
||||
)
|
||||
@@ -109,6 +110,7 @@ class NewRevocationModalForm(BaseModalForm):
|
||||
attrs={
|
||||
"type": "date",
|
||||
"data-provide": "datepicker",
|
||||
"class": "form-control",
|
||||
},
|
||||
format="%d.%m.%Y"
|
||||
)
|
||||
@@ -120,7 +122,7 @@ class NewRevocationModalForm(BaseModalForm):
|
||||
help_text=_("Must be smaller than 15 Mb"),
|
||||
widget=forms.FileInput(
|
||||
attrs={
|
||||
"class": "w-75"
|
||||
"class": "form-control-file"
|
||||
}
|
||||
)
|
||||
)
|
||||
@@ -134,13 +136,11 @@ class NewRevocationModalForm(BaseModalForm):
|
||||
attrs={
|
||||
"cols": 30,
|
||||
"rows": 5,
|
||||
"class": "form-control",
|
||||
}
|
||||
)
|
||||
)
|
||||
|
||||
# Define w-100 for all form fields
|
||||
full_width_fields = True
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
self.form_title = _("Add revocation")
|
||||
@@ -274,6 +274,11 @@ class NewDeductionModalForm(BaseModalForm):
|
||||
label=_("Surface"),
|
||||
label_suffix="",
|
||||
help_text=_("in m²"),
|
||||
widget=forms.NumberInput(
|
||||
attrs={
|
||||
"class": "form-control",
|
||||
}
|
||||
)
|
||||
)
|
||||
intervention = forms.ModelChoiceField(
|
||||
label=_("Intervention"),
|
||||
@@ -289,9 +294,6 @@ class NewDeductionModalForm(BaseModalForm):
|
||||
),
|
||||
)
|
||||
|
||||
# Define w-100 for all form fields
|
||||
full_width_fields = True
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
self.form_title = _("New Deduction")
|
||||
|
||||
@@ -12,4 +12,21 @@ class DummyFilterInput(forms.HiddenInput):
|
||||
|
||||
|
||||
class TextToClipboardInput(forms.TextInput):
|
||||
template_name = "konova/custom_widgets/text-to-clipboard-input.html"
|
||||
template_name = "konova/custom_widgets/text-to-clipboard-input.html"
|
||||
|
||||
|
||||
class GenerateInput(forms.TextInput):
|
||||
"""
|
||||
|
||||
Provides a form group with a button at the end, which generates new content for the input.
|
||||
The url used to fetch new content can be added using the attrs like
|
||||
|
||||
widget=GenerateInput(
|
||||
attrs={
|
||||
"url": reverse_lazy("app_name:view_name")
|
||||
...
|
||||
}
|
||||
)
|
||||
|
||||
"""
|
||||
template_name = "konova/custom_widgets/generate-content-input.html"
|
||||
|
||||
@@ -9,12 +9,13 @@ 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_deduction_view, \
|
||||
record_view, remove_document_view, get_document_view, get_revocation_view
|
||||
record_view, remove_document_view, get_document_view, get_revocation_view, new_id_view
|
||||
|
||||
app_name = "intervention"
|
||||
urlpatterns = [
|
||||
path("", index_view, name="index"),
|
||||
path('new/', new_view, name='new'),
|
||||
path('new/id', new_id_view, name='new-id'),
|
||||
path('<id>', open_view, name='open'),
|
||||
path('<id>/log', log_view, name='log'),
|
||||
path('<id>/edit', edit_view, name='edit'),
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
from django.contrib.auth.decorators import login_required
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
from django.http import HttpRequest
|
||||
from django.http import HttpRequest, JsonResponse
|
||||
from django.shortcuts import render, get_object_or_404
|
||||
|
||||
from intervention.forms.forms import NewInterventionForm, EditInterventionForm
|
||||
@@ -83,11 +83,30 @@ def new_view(request: HttpRequest):
|
||||
context = {
|
||||
"data_form": data_form,
|
||||
"geom_form": geom_form,
|
||||
"url": reverse("intervention:new-id")
|
||||
}
|
||||
context = BaseContext(request, context).context
|
||||
return render(request, template, context)
|
||||
|
||||
|
||||
@login_required
|
||||
def new_id_view(request: HttpRequest):
|
||||
""" JSON endpoint
|
||||
|
||||
Provides fetching of free identifiers for e.g. AJAX calls
|
||||
|
||||
"""
|
||||
tmp_intervention = Intervention()
|
||||
identifier = tmp_intervention._generate_new_identifier()
|
||||
while Intervention.objects.filter(identifier=identifier).exists():
|
||||
identifier = tmp_intervention._generate_new_identifier()
|
||||
return JsonResponse(
|
||||
data={
|
||||
"identifier": identifier
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
@login_required
|
||||
def new_document_view(request: HttpRequest, id: str):
|
||||
""" Renders a form for uploading new documents
|
||||
|
||||
Reference in New Issue
Block a user