libreForms / libreForms-flask

Flask implementation of the libreForms API
https://libreforms.readthedocs.io
GNU Affero General Public License v3.0
4 stars 1 forks source link

[forms] transition webargs form parsing to WTForms #30

Open signebedi opened 2 years ago

signebedi commented 2 years ago

WTForms seems to have more active support in Flask. One of the constraints -- that is, settings kwargs as class attrs -- is solved by https://stackoverflow.com/questions/8187082/how-can-you-set-class-attributes-from-variable-arguments-kwargs-in-python.

signebedi commented 1 year ago

[forms] use wtforms to render forms in jinja2 As a follow on to #30, where we chiefly concerned ourselves with transitioning to wtforms to parse form data, now we should re-write forms.html.jinja to render forms dynamically as well.

signebedi commented 1 year ago

We are going to focus this issue on replacing the webargs parser only. This will allow us to incrementalize changes to other areas of the code base and avoid too much change, too fast. Future issues will deal with replacing forms.html.jinja eg. with some variation on the code below:

{{ form_instance.field_name.label }}: {{ form_instance.field_name }}
{% if form_instance.field_name.errors %}
    <ul>
    {% for error in form_instance.field_name.errors %}
        <li>{{ error }}</li>
    {% endfor %}
    </ul>
{% endif %}
<form method="POST">
    {{ form.csrf_token }}
    {% for field in form %}
        {% if field.type != 'SubmitField' %}
            <div class="form-group">
                {{ field.label }}<br>
                {{ field }}
                {% if field.errors %}
                    <div class="errors">
                        {% for error in field.errors %}
                            <p>{{ error }}</p>
                        {% endfor %}
                    </div>
                {% endif %}
            </div>
        {% endif %}
    {% endfor %}
    {{ form.submit }}
</form>
signebedi commented 1 year ago

[forms] add backend form field validation to wtforms Now that we are moving toward using wtforms, we should also add back end form validation to supplement the front end field validation that we implemented in #380.

signebedi commented 1 year ago

Ok. We've added form parsing. Now, we need to propagate it to other views like the form edits view. In addition, we still need to implement backend validation #416 and rendering #415. These are separate issues not associated with the acceptance criteria for this issue.