Add bills func
This commit is contained in:
parent
72d196ee7f
commit
850cbfe46e
|
@ -1,8 +1,15 @@
|
|||
from wtforms import Form, BooleanField, StringField, PasswordField, validators
|
||||
from wtforms import Form, BooleanField, IntegerField, DecimalField, StringField, DateField, PasswordField, validators
|
||||
from flask_login import UserMixin
|
||||
|
||||
from objects import glob
|
||||
|
||||
class BillForm(Form):
|
||||
payment_to = StringField("Payment to", [validators.DataRequired()])
|
||||
description = StringField("Description")
|
||||
sum = DecimalField("Sum")
|
||||
kid = IntegerField("KID")
|
||||
date_due = DateField("Date Due (YYYY-MM-DD )")
|
||||
|
||||
class LoginForm(Form):
|
||||
email = StringField("Email", [
|
||||
validators.DataRequired(),
|
||||
|
|
19
routes.py
19
routes.py
|
@ -2,7 +2,7 @@ from flask import render_template, url_for, request, redirect, flash, abort
|
|||
from wtforms import Form, BooleanField, StringField, PasswordField, validators
|
||||
import flask_login
|
||||
|
||||
from forms.login import LoginForm, RegisterForm, User, register_account
|
||||
from forms.login import LoginForm, RegisterForm, BillForm, User, register_account
|
||||
|
||||
from objects import glob # Global sharing of python objects in a manageable way
|
||||
|
||||
|
@ -19,12 +19,25 @@ logged_in_users = []
|
|||
def dashboard():
|
||||
return render_template("pages/dashboard.html")
|
||||
|
||||
@glob.app.route("/bills")
|
||||
@glob.app.route("/bills", methods = ["GET", "POST"])
|
||||
@flask_login.login_required
|
||||
def bills():
|
||||
form = BillForm(request.form)
|
||||
|
||||
conn = glob.make_sql_connection()
|
||||
cur = conn.cursor()
|
||||
|
||||
if request.method == "POST" and form.validate():
|
||||
cur.execute("""
|
||||
INSERT
|
||||
INTO Regninger
|
||||
VALUES (NULL, %s, %s, %s, %s, %s, 0, 1, %s)
|
||||
""", (form.payment_to.data, form.description.data, form.kid.data, form.sum.data, form.date_due.data, flask_login.current_user.id))
|
||||
|
||||
conn.commit()
|
||||
|
||||
return redirect(url_for("bills"))
|
||||
|
||||
cur.execute("""
|
||||
SELECT Betaletil, Regningfor, Regningsum, KID, Betalingsfrist, Betalt
|
||||
FROM Regninger
|
||||
|
@ -37,7 +50,7 @@ def bills():
|
|||
|
||||
cur.close()
|
||||
conn.close()
|
||||
return render_template("pages/bills.html", data=data)
|
||||
return render_template("pages/bills.html", data=data, form=form)
|
||||
|
||||
@glob.app.route("/warranties")
|
||||
@flask_login.login_required
|
||||
|
|
|
@ -6,6 +6,46 @@
|
|||
|
||||
<div class="container module">
|
||||
|
||||
<button type="button" class="btn btn-primary" style="margin:10px;" data-toggle="modal" data-target="#myModal">Add</button>
|
||||
<div class="modal fade" id="myModal" role="dialog">
|
||||
<div class="modal-dialog">
|
||||
<!-- Modal content-->
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h4 class="modal-title">Add bill</h4>
|
||||
<button type="button" class="close" data-dismiss="modal">×</button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
{% macro render_field(field) %}
|
||||
<dt>{{ field.label }}
|
||||
<dd>{{ field(**kwargs)|safe }}
|
||||
{% if field.errors %}
|
||||
<ul class=errors>
|
||||
{% for error in field.errors %}
|
||||
<li>{{ error }}</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
{% endif %}
|
||||
</dd>
|
||||
{% endmacro %}
|
||||
<form method=post>
|
||||
<dl>
|
||||
{{ render_field(form.payment_to) }}
|
||||
{{ render_field(form.description) }}
|
||||
{{ render_field(form.sum) }}
|
||||
{{ render_field(form.kid) }}
|
||||
{{ render_field(form.date_due) }} YYYY-MM-DD
|
||||
</dl>
|
||||
<input type=submit value="Add">
|
||||
</form>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<table class="table">
|
||||
<thead class="thead-light">
|
||||
<tr>
|
||||
|
|
Loading…
Reference in New Issue
Block a user