Minor enhancements

* refactors eco account rest surface calculation into designated method get_available_rest()
* refactors placeholder setter for BaseForm
* adds automatic eco account identifier generating on saving
* fixes ServerMessageImportance template tag
This commit is contained in:
mipel
2021-08-11 14:17:43 +02:00
parent 5f85f49636
commit c8b6d001ef
8 changed files with 77 additions and 15 deletions

View File

@@ -71,6 +71,19 @@ class BaseForm(forms.Form):
"""
self.fields[field].initial = val
def add_placeholder_for_field(self, field: str, val):
"""
Adds a placeholder to a field after initialization
Args:
field (str): Field name
val (str): Placeholder
Returns:
"""
self.fields[field].widget.attrs["placeholder"] = val
def load_initial_data(self, form_data: dict, disabled_fields: list):
""" Initializes form data from instance
@@ -369,7 +382,7 @@ class RecordForm(BaseModalForm):
"""
super_val = super().is_valid()
msgs = self.instance.quality_check()
msgs = self.instance.quality_check() or []
for msg in msgs:
self.add_error(
"confirm",

View File

@@ -14,9 +14,9 @@ register = template.Library()
# ServerMessageImportance bootstrap resolver
SVI_BOOTSTRAP_CLS_MAP = {
ServerMessageImportance.DEFAULT.name: "",
ServerMessageImportance.WARNING.name: "alert-danger",
ServerMessageImportance.INFO.name: "alert-info",
ServerMessageImportance.DEFAULT: "",
ServerMessageImportance.WARNING: "alert-danger",
ServerMessageImportance.INFO: "alert-info",
}