diff options
-rw-r--r-- | app/__init__.py | 2 | ||||
-rw-r--r-- | app/modules/auth/routes.py | 2 | ||||
-rw-r--r-- | app/modules/common.py | 2 | ||||
-rw-r--r-- | app/modules/forms.py | 5 | ||||
-rw-r--r-- | app/modules/invoices/forms.py | 2 | ||||
-rw-r--r-- | app/templates/modules/add-invoice.html | 48 | ||||
-rw-r--r-- | app/templates/modules/add-item.html | 2 | ||||
-rw-r--r-- | app/templates/modules/invoices.html | 39 |
8 files changed, 32 insertions, 70 deletions
diff --git a/app/__init__.py b/app/__init__.py index 0e553b3..04c4c99 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -38,5 +38,7 @@ def create_app(): app.register_blueprint(invoices) app.register_blueprint(orders) + # with app.app_context(): + # db.create_all() return app diff --git a/app/modules/auth/routes.py b/app/modules/auth/routes.py index dd9e396..d0aee0c 100644 --- a/app/modules/auth/routes.py +++ b/app/modules/auth/routes.py @@ -62,7 +62,7 @@ def register(): db.session.commit() flash(f"Created user {req['name_first']} {req['name_last']} successfully.") return redirect(url_for("main.home")) - return render_template("register.html", form=form) + return render_template("modules/register.html", form=form) @auth.route("/logout") diff --git a/app/modules/common.py b/app/modules/common.py index 9e96f41..f9ccba6 100644 --- a/app/modules/common.py +++ b/app/modules/common.py @@ -48,7 +48,7 @@ def edit_item(module, table, pk): form = getattr(forms, f"Add{table}")(**item.__dict__) if form.validate_on_submit(): table_fields = inspect.signature(model).parameters - form_values = {key: request.form[key] for key in table_fields} + form_values = {key: request.form.get(key) for key in table_fields} print(f"Ready to update {form_values}") model.query.filter_by(primary_key=pk).update(form_values) db.session.commit() diff --git a/app/modules/forms.py b/app/modules/forms.py index f98995d..7e4acde 100644 --- a/app/modules/forms.py +++ b/app/modules/forms.py @@ -1,5 +1,10 @@ # -*- mode: python; -*- +"""Form class attribute names must match model class attribute names +for proper request.form dictionary splatting. + +""" + from .customers.forms import AddCustomer from .ferti.forms import AddFertiLog, AddFertiTarget from .invoices.forms import AddInvoice diff --git a/app/modules/invoices/forms.py b/app/modules/invoices/forms.py index 8ef7bd0..74df40e 100644 --- a/app/modules/invoices/forms.py +++ b/app/modules/invoices/forms.py @@ -26,7 +26,7 @@ class AddInvoice(FlaskForm): amount_tax = FloatField("Amount of tax", default=0) submit = SubmitField("Add new Invoice") - def __init__(self, **kwargs): + def __init__(self): super().__init__() self.customer_id.choices = [ (cus.primary_key, cus.name) for cus in Customer.query.all() diff --git a/app/templates/modules/add-invoice.html b/app/templates/modules/add-invoice.html deleted file mode 100644 index 92748be..0000000 --- a/app/templates/modules/add-invoice.html +++ /dev/null @@ -1,48 +0,0 @@ -{# -*- mode: web; -*- #} - -{% extends "base.html" %} - - -{% block title %}Add a new invoice{% endblock %} -{% block content %} - -{% if message %} -{# the form was submitted and message exists #} -<p><strong>{{ item }}</strong></p> -{# links #} -<p><a href="{{ url_for('add_item', item=item) }}" class="button">Submit another {{ item }}</a></p> -<p><a href="/fapg/home">Return to the index</a></p> - -{% else %} -{# the form is displayed when template opens via GET not POST #} - -{# show flash - based on WTForms validators see -https://pythonprogramming.net/flash-flask-tutorial/ -get_flashed_messages() exists here because of flash() in the route -function #} - -{% with errors = get_flashed_messages() %} {% if errors %} -{% for err in errors %} -<div class="alert alert-danger alert-dismissible" role="alert"> - <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button> - {{ err }} -</div> -{% endfor %} -{% endif %} -{% endwith %} -{# end of flash #} - - -{# the form #} -<form action="{{ url_for('add_item', item=item) }}" method="POST"> - <fieldset> - <legend>Add a new {{ item }} to our database.</legend> - {% for field in form %} - {{ field.label() }} - {{ field() }}<br/> - {% endfor %} - </fieldset> -</form> - -{% endif %} -{% endblock %} diff --git a/app/templates/modules/add-item.html b/app/templates/modules/add-item.html index 356ce9f..4eaee3d 100644 --- a/app/templates/modules/add-item.html +++ b/app/templates/modules/add-item.html @@ -10,7 +10,7 @@ <fieldset> <legend>Add a new item to our {{ table }} table.</legend> {% for field in form %} - {{ field.label() }} + {{ field.label() }}<br/> {{ field() }}<br/> {% endfor %} </fieldset> diff --git a/app/templates/modules/invoices.html b/app/templates/modules/invoices.html index 55a4b87..293a45b 100644 --- a/app/templates/modules/invoices.html +++ b/app/templates/modules/invoices.html @@ -13,25 +13,28 @@ Invoices {% block content %} <i>Track your invoices and create new ones here.</i><br/> +{# Pagination Links #} +{# gotten from https://betterprogramming.pub/simple-flask-pagination-example-4190b12c2e2e #} <center> -{% for page_num in invoices.iter_pages(left_edge=1, right_edge=1, left_current=1, right_current=2) %} -{% if page_num %} -<!-- Check for the active page and set the link to "Active"--> -{% if invoices.page == page_num %} -<a href="{{ url_for('invoices.view', page=page_num) }}" - class="button"> - {{ page_num }} -</a> -{% else %} -<a href="{{ url_for('invoices.view', page=page_num) }}" - class="button button-light"> - {{ page_num }} -</a> -{% endif %} -{% else %} -... -{% endif %} -{% endfor %} + {# Loop through the number of pages to display a link for each #} + {% for page_num in invoices.iter_pages(left_edge=1, right_edge=1, left_current=1, right_current=2) %} + {% if page_num %} + {# Check for the active page and set the link to "Active" #} + {% if invoices.page == page_num %} + <a href="{{ url_for('invoices.view', page=page_num) }}" + class="button"> + {{ page_num }} + </a> + {% else %} + <a href="{{ url_for('invoices.view', page=page_num) }}" + class="button button-light"> + {{ page_num }} + </a> + {% endif %} + {% else %} + ... + {% endif %} + {% endfor %} </center> <table> <thead> |