Lil fixes.

Commit
eac5bb765c8d609d3b7eb31316228f8058581796
Author
Marius Peter <marius.peter@tutanota.com>
Author date
Committer
Marius Peter <marius.peter@tutanota.com>
Committer date
Changed files
app/__init__.py
index 0e553b39..04c4c994 100644..100644
@@ -38,5 +38,7 @@
38 38 app.register_blueprint(invoices)
39 39 app.register_blueprint(orders)
40 40
41 Added: # with app.app_context():
42 Added: # db.create_all()
41 43
42 44 return app
app/modules/auth/routes.py
index dd9e3967..d0aee0c4 100644..100644
@@ -62,7 +62,7 @@
62 62 db.session.commit()
63 63 flash(f"Created user {req['name_first']} {req['name_last']} successfully.")
64 64 return redirect(url_for("main.home"))
65 Removed: return render_template("register.html", form=form)
65 Added: return render_template("modules/register.html", form=form)
66 66
67 67
68 68 @auth.route("/logout")
app/modules/common.py
index 9e96f416..f9ccba61 100644..100644
@@ -48,7 +48,7 @@
48 48 form = getattr(forms, f"Add{table}")(**item.__dict__)
49 49 if form.validate_on_submit():
50 50 table_fields = inspect.signature(model).parameters
51 Removed: form_values = {key: request.form[key] for key in table_fields}
51 Added: form_values = {key: request.form.get(key) for key in table_fields}
52 52 print(f"Ready to update {form_values}")
53 53 model.query.filter_by(primary_key=pk).update(form_values)
54 54 db.session.commit()
app/modules/forms.py
index f98995df..7e4acde6 100644..100644
@@ -1,5 +1,10 @@
1 1 # -*- mode: python; -*-
2 2
3 Added: """Form class attribute names must match model class attribute names
4 Added: for proper request.form dictionary splatting.
5 Added:
6 Added: """
7 Added:
3 8 from .customers.forms import AddCustomer
4 9 from .ferti.forms import AddFertiLog, AddFertiTarget
5 10 from .invoices.forms import AddInvoice
app/modules/invoices/forms.py
index 8ef7bd03..74df40e2 100644..100644
@@ -26,7 +26,7 @@
26 26 amount_tax = FloatField("Amount of tax", default=0)
27 27 submit = SubmitField("Add new Invoice")
28 28
29 Removed: def __init__(self, **kwargs):
29 Added: def __init__(self):
30 30 super().__init__()
31 31 self.customer_id.choices = [
32 32 (cus.primary_key, cus.name) for cus in Customer.query.all()
app/templates/modules/add-invoice.html
index 92748be4..00000000 100644..000000
@@ -1,48 +0,0 @@
1 Removed: {# -*- mode: web; -*- #}
2 Removed:
3 Removed: {% extends "base.html" %}
4 Removed:
5 Removed:
6 Removed: {% block title %}Add a new invoice{% endblock %}
7 Removed: {% block content %}
8 Removed:
9 Removed: {% if message %}
10 Removed: {# the form was submitted and message exists #}
11 Removed: <p><strong>{{ item }}</strong></p>
12 Removed: {# links #}
13 Removed: <p><a href="{{ url_for('add_item', item=item) }}" class="button">Submit another {{ item }}</a></p>
14 Removed: <p><a href="/fapg/home">Return to the index</a></p>
15 Removed:
16 Removed: {% else %}
17 Removed: {# the form is displayed when template opens via GET not POST #}
18 Removed:
19 Removed: {# show flash - based on WTForms validators see
20 Removed: https://pythonprogramming.net/flash-flask-tutorial/
21 Removed: get_flashed_messages() exists here because of flash() in the route
22 Removed: function #}
23 Removed:
24 Removed: {% with errors = get_flashed_messages() %} {% if errors %}
25 Removed: {% for err in errors %}
26 Removed: <div class="alert alert-danger alert-dismissible" role="alert">
27 Removed: <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button>
28 Removed: {{ err }}
29 Removed: </div>
30 Removed: {% endfor %}
31 Removed: {% endif %}
32 Removed: {% endwith %}
33 Removed: {# end of flash #}
34 Removed:
35 Removed:
36 Removed: {# the form #}
37 Removed: <form action="{{ url_for('add_item', item=item) }}" method="POST">
38 Removed: <fieldset>
39 Removed: <legend>Add a new {{ item }} to our database.</legend>
40 Removed: {% for field in form %}
41 Removed: {{ field.label() }}
42 Removed: {{ field() }}<br/>
43 Removed: {% endfor %}
44 Removed: </fieldset>
45 Removed: </form>
46 Removed:
47 Removed: {% endif %}
48 Removed: {% endblock %}
app/templates/modules/add-item.html
index 356ce9f3..4eaee3d3 100644..100644
@@ -10,7 +10,7 @@
10 10 <fieldset>
11 11 <legend>Add a new item to our {{ table }} table.</legend>
12 12 {% for field in form %}
13 Removed: {{ field.label() }}
13 Added: {{ field.label() }}<br/>
14 14 {{ field() }}<br/>
15 15 {% endfor %}
16 16 </fieldset>
app/templates/modules/invoices.html
index 55a4b87c..293a45bb 100644..100644
@@ -13,25 +13,28 @@
13 13 {% block content %}
14 14 <i>Track your invoices and create new ones here.</i><br/>
15 15
16 Added: {# Pagination Links #}
17 Added: {# gotten from https://betterprogramming.pub/simple-flask-pagination-example-4190b12c2e2e #}
16 18 <center>
17 Removed: {% for page_num in invoices.iter_pages(left_edge=1, right_edge=1, left_current=1, right_current=2) %}
18 Removed: {% if page_num %}
19 Removed: <!-- Check for the active page and set the link to "Active"-->
20 Removed: {% if invoices.page == page_num %}
21 Removed: <a href="{{ url_for('invoices.view', page=page_num) }}"
22 Removed: class="button">
23 Removed: {{ page_num }}
24 Removed: </a>
25 Removed: {% else %}
26 Removed: <a href="{{ url_for('invoices.view', page=page_num) }}"
27 Removed: class="button button-light">
28 Removed: {{ page_num }}
29 Removed: </a>
30 Removed: {% endif %}
31 Removed: {% else %}
32 Removed: ...
33 Removed: {% endif %}
34 Removed: {% endfor %}
19 Added: {# Loop through the number of pages to display a link for each #}
20 Added: {% for page_num in invoices.iter_pages(left_edge=1, right_edge=1, left_current=1, right_current=2) %}
21 Added: {% if page_num %}
22 Added: {# Check for the active page and set the link to "Active" #}
23 Added: {% if invoices.page == page_num %}
24 Added: <a href="{{ url_for('invoices.view', page=page_num) }}"
25 Added: class="button">
26 Added: {{ page_num }}
27 Added: </a>
28 Added: {% else %}
29 Added: <a href="{{ url_for('invoices.view', page=page_num) }}"
30 Added: class="button button-light">
31 Added: {{ page_num }}
32 Added: </a>
33 Added: {% endif %}
34 Added: {% else %}
35 Added: ...
36 Added: {% endif %}
37 Added: {% endfor %}
35 38 </center>
36 39 <table>
37 40 <thead>