Fixes and improvements
* fixes group check on detail views * adds check for required fields in BaseForm for showing required field hint or not in template
This commit is contained in:
parent
cd5b2e264b
commit
d773c3b3d4
@ -95,9 +95,9 @@ def open_view(request: HttpRequest, id: str):
|
|||||||
"sum_before_states": sum_before_states,
|
"sum_before_states": sum_before_states,
|
||||||
"sum_after_states": sum_after_states,
|
"sum_after_states": sum_after_states,
|
||||||
"diff_states": diff_states,
|
"diff_states": diff_states,
|
||||||
"is_default_member": in_group(_user, _(DEFAULT_GROUP)),
|
"is_default_member": in_group(_user, DEFAULT_GROUP),
|
||||||
"is_zb_member": in_group(_user, _(ZB_GROUP)),
|
"is_zb_member": in_group(_user, ZB_GROUP),
|
||||||
"is_ets_member": in_group(_user, _(ETS_GROUP)),
|
"is_ets_member": in_group(_user, ETS_GROUP),
|
||||||
}
|
}
|
||||||
context = BaseContext(request, context).context
|
context = BaseContext(request, context).context
|
||||||
return render(request, template, context)
|
return render(request, template, context)
|
||||||
|
@ -122,9 +122,9 @@ def open_view(request: HttpRequest, id: str):
|
|||||||
"compensations": compensations,
|
"compensations": compensations,
|
||||||
"has_access": is_data_shared,
|
"has_access": is_data_shared,
|
||||||
"geom_form": geom_form,
|
"geom_form": geom_form,
|
||||||
"is_default_member": in_group(_user, _(DEFAULT_GROUP)),
|
"is_default_member": in_group(_user, DEFAULT_GROUP),
|
||||||
"is_zb_member": in_group(_user, _(ZB_GROUP)),
|
"is_zb_member": in_group(_user, ZB_GROUP),
|
||||||
"is_ets_member": in_group(_user, _(ETS_GROUP)),
|
"is_ets_member": in_group(_user, ETS_GROUP),
|
||||||
}
|
}
|
||||||
|
|
||||||
if not is_data_shared:
|
if not is_data_shared:
|
||||||
|
@ -37,12 +37,19 @@ class BaseForm(forms.Form):
|
|||||||
form_caption = None
|
form_caption = None
|
||||||
instance = None # The data holding model object
|
instance = None # The data holding model object
|
||||||
form_attrs = {} # Holds additional attributes, that can be used in the template
|
form_attrs = {} # Holds additional attributes, that can be used in the template
|
||||||
|
has_required_fields = False # Automatically set. Triggers hint rendering in templates
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
self.instance = kwargs.pop("instance", None)
|
self.instance = kwargs.pop("instance", None)
|
||||||
self.user = kwargs.pop("user", None)
|
self.user = kwargs.pop("user", None)
|
||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
|
|
||||||
|
# Check for required fields
|
||||||
|
for _field_name, _field_val in self.fields.items():
|
||||||
|
if _field_val.required:
|
||||||
|
self.has_required_fields = True
|
||||||
|
break
|
||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
def save(self):
|
def save(self):
|
||||||
# To be implemented in subclasses!
|
# To be implemented in subclasses!
|
||||||
|
@ -17,4 +17,6 @@
|
|||||||
{% endfor %}
|
{% endfor %}
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
<small>{% trans 'Fields with * are required.' %}</small>
|
{% if form.has_required_fields %}
|
||||||
|
<small>{% trans 'Fields with * are required.' %}</small>
|
||||||
|
{% endif %}
|
Loading…
Reference in New Issue
Block a user