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 @@

Poznámky

Přepsání údajů

{% with form=donors_override_form %} -
+
+ {{ form.csrf_token }}
{{ form.rodne_cislo(readonly=True, size=8, class_="form-control") }} @@ -159,26 +160,16 @@

Přepsání údajů

- - - - {{ form.csrf_token }} - - + +
-{% endwith %} -{% with form=donors_override_delete_form %} -
-
- - {{ form.csrf_token }} - {{ form.rodne_cislo(value=overview.rodne_cislo) }} - -
+
+ +
+ {% endwith %} -

Historie importů

diff --git a/tests/test_functional.py b/tests/test_functional.py index 51b0770d..221c91de 100644 --- a/tests/test_functional.py +++ b/tests/test_functional.py @@ -756,8 +756,8 @@ def test_override(self, user, testapp, rodne_cislo): assert "Příjmení: --Last--" in res # Test deleting the override - form = res.forms["donorsOverrideDeleteForm"] - res = form.submit().follow() + form = res.forms["donorsOverrideForm"] + res = form.submit("delete_btn").follow() assert "Výjimka smazána" in res assert ("Jméno: " + old_first_name) in res