diff --git a/registry/donor/forms.py b/registry/donor/forms.py index 8fa7e946..0133747b 100644 --- a/registry/donor/forms.py +++ b/registry/donor/forms.py @@ -49,12 +49,6 @@ class RemoveFromIgnoredForm(FlaskForm): class DonorsOverrideForm(FlaskForm): - class Meta: - def render_field(self, field, render_kw): - # Set the HTML "form" parameter for each of the fields - render_kw["form"] = "donorsOverrideForm" - return field.widget(field, **render_kw) - rodne_cislo = StringField("Rodné číslo", validators=[DataRequired()]) first_name = StringField("Jméno") last_name = StringField("Příjmení") @@ -124,7 +118,3 @@ def _get_field_data(self): self.field_data[field] = data else: self.field_data[field] = None - - -class DonorsOverrideDeleteForm(FlaskForm): - rodne_cislo = HiddenField(validators=[DataRequired()]) diff --git a/registry/donor/views.py b/registry/donor/views.py index 5e430cb0..f1d3c9d7 100644 --- a/registry/donor/views.py +++ b/registry/donor/views.py @@ -20,7 +20,6 @@ from .forms import ( AwardMedalForm, - DonorsOverrideDeleteForm, DonorsOverrideForm, IgnoreDonorForm, NoteForm, @@ -104,7 +103,6 @@ def detail(rc): if overview.note: note_form.note.data = overview.note.note donors_override_form = DonorsOverrideForm().init_fields(rc) - donors_override_delete_form = DonorsOverrideDeleteForm() return render_template( "donor/detail.html", @@ -117,7 +115,6 @@ def detail(rc): award_medal_form=award_medal_form, note_form=note_form, donors_override_form=donors_override_form, - donors_override_delete_form=donors_override_delete_form, ) @@ -257,36 +254,31 @@ def unignore_donor(): @blueprint.post("/override/") @login_required def save_override(): - override_form = DonorsOverrideForm() - - if override_form.validate_on_submit(): - override = DonorsOverride(**override_form.field_data) - db.session.merge(override) - db.session.commit() - - DonorsOverview.refresh_overview() - flash("Výjimka uložena", "success") - else: - flash_errors(override_form) - - return redirect(url_for("donor.detail", rc=override_form.rodne_cislo.data)) - - -@blueprint.post("/override/delete") -@login_required -def delete_override(): - form = DonorsOverrideDeleteForm() + form = DonorsOverrideForm() + delete = "delete_btn" in request.form if form.validate_on_submit(): - override = DonorsOverride.query.get(form.rodne_cislo.data) - if override is not None: - db.session.delete(override) + if not delete: + # Save the override + override = DonorsOverride(**form.field_data) + db.session.merge(override) db.session.commit() DonorsOverview.refresh_overview() - flash("Výjimka smazána", "success") + flash("Výjimka uložena", "success") else: - flash("Není co mazat", "warning") + # Delete the override + override = DonorsOverride.query.get(form.rodne_cislo.data) + if override is not None: + db.session.delete(override) + db.session.commit() + + DonorsOverview.refresh_overview() + flash("Výjimka smazána", "success") + else: + flash("Není co mazat", "warning") + else: + flash_errors(form) return redirect(url_for("donor.detail", rc=form.rodne_cislo.data)) diff --git a/registry/templates/donor/detail.html b/registry/templates/donor/detail.html index 2f4f4898..e13ac7f7 100644 --- a/registry/templates/donor/detail.html +++ b/registry/templates/donor/detail.html @@ -1,18 +1,18 @@ {% extends "layout.html" %} {% block css %} @@ -128,7 +128,8 @@