def set_up_fields(self, form, is_edition): for field_descriptor in self.fields: if is_actual_model_field(field_descriptor): # by default person fields are required form.fields[ field_descriptor["id"]].required = field_descriptor.get( "required", True) if is_edition: form.fields[field_descriptor[ "id"]].disabled = not field_descriptor.get( "editable", False) if field_descriptor["id"] == "date_of_birth": form.fields[field_descriptor["id"]].help_text = _( "Format JJ/MM/AAAA") else: form.fields[field_descriptor["id"]] = get_form_field( field_descriptor, is_edition, form.instance) form.helper.layout.append( Fieldset( self.title, *(Row(FullCol(field_descriptor["id"])) for field_descriptor in self.fields), ))
def set_up_fields(self, form: forms.Form, is_edition): for row_id, row_label in self.rows: for field_descriptor in self.fields: id = self.get_id(row_id, field_descriptor["id"]) field = get_form_field(field_descriptor, is_edition, form.instance) form.fields[id] = field intro = f"<p>{self.intro}</p>" if self.intro else "" text = ( intro + f""" <table class="table"> <thead> {self.get_header_row()} </thead> <tbody>""" + "".join( self.get_row(form, row_id, row_label) for row_id, row_label in self.rows ) + """ </tbody> </table> """ ) form.helper.layout.append(Fieldset(self.title, HTML(text)))
def set_up_fields(self, form, is_edition): for field_descriptor in self.fields: if is_actual_model_field(field_descriptor): # Allow overriding of default form field by setting type on the field config if field_descriptor.get("type"): if not field_descriptor.get("label"): field_descriptor["label"] = str( form.fields[field_descriptor["id"]].label ) form.fields[field_descriptor["id"]] = get_form_field( field_descriptor, is_edition, form.instance ) # by default person fields are required form.fields[field_descriptor["id"]].required = field_descriptor.get( "required", True ) if is_edition: form.fields[ field_descriptor["id"] ].disabled = not field_descriptor.get("editable", False) if field_descriptor["id"] == "date_of_birth": form.fields[field_descriptor["id"]].help_text = _( "Format JJ/MM/AAAA" ) if field_descriptor["id"] == "newsletters": form.fields[ field_descriptor["id"] ].initial = form.instance.newsletters else: form.fields[field_descriptor["id"]] = get_form_field( field_descriptor, is_edition, form.instance ) fields = ( Row(FullCol(field_descriptor["id"])) for field_descriptor in self.fields ) if self.intro_html is not None: fields = (HTML(self.intro_html), *fields) form.helper.layout.append(Fieldset(self.title, *fields))
def set_up_fields(self, form: forms.Form, is_edition): self.form = form it = self.subset or product(self.rows, self.columns) # ajoute un faux champ pour y mettre les erreurs de table fake_field = forms.Field(required=False) form.fields[self.fake_field_id] = fake_field for (row, col) in it: id = self.get_id(row, col) field_descriptor = {**self.field_descriptor, "id": id} field = get_form_field(field_descriptor, is_edition, form.instance) form.fields[id] = field form.helper.layout.append(Fieldset(self.title, HTML(lazy(self.render_part)())))