diff --git a/forms/login.py b/forms/login.py index 3ee0a9e..0b272b5 100644 --- a/forms/login.py +++ b/forms/login.py @@ -27,6 +27,13 @@ class WarrantyForm(Form): date_to = DateField(_("Warranty duration"), render_kw = FORM_RENDER_KW) sum = DecimalField(_("Sum"), render_kw = FORM_RENDER_KW) +class ServiceForm(Form): + name = StringField(_("Name"), [validators.DataRequired()], render_kw = FORM_RENDER_KW) + type = StringField(_("Type"), [validators.DataRequired()], render_kw = FORM_RENDER_KW) + contact = StringField(_("Contact"), render_kw = FORM_RENDER_KW) + phone = IntegerField(_("Phone"), render_kw = FORM_RENDER_KW) + website = StringField(_("Website"), render_kw = FORM_RENDER_KW) + class LoginForm(Form): email = StringField(_("Email"), [ validators.DataRequired(), diff --git a/requirements.txt b/requirements.txt index cb3cbd3..db893c5 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,4 +2,5 @@ Flask>=1.0.2 Flask-WTF>=0.14.2 flask_login>=0.4.1 Flask-Babel>=0.12.2 +mysql-connector bcrypt \ No newline at end of file diff --git a/routes.py b/routes.py index dd33ae1..3ca514e 100644 --- a/routes.py +++ b/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, BillForm, WarrantyForm, User, register_account +from forms.login import LoginForm, RegisterForm, BillForm, WarrantyForm, ServiceForm, User, register_account from objects import glob # Global sharing of python objects in a manageable way @@ -92,6 +92,39 @@ def warranties(): def receipts(): return render_template("pages/receipts.html") +@glob.app.route("/services", methods = ["GET", "POST"]) +@flask_login.login_required +def services(): + form = ServiceForm(request.form) + + conn = glob.make_sql_connection() + cur = conn.cursor() + + if request.method == "POST" and form.validate(): + cur.execute(""" + INSERT + INTO Services + VALUES (NULL, %s, %s, %s, %s, 1, %s, %s) + """, (form.name.data, form.type.data, form.contact.data, form.phone.data, flask_login.current_user.id, form.website.data)) + + conn.commit() + + return redirect(url_for("services")) + + cur.execute(""" + SELECT ServiceName, ServiceType, Kontaktperson, Telefonnummer, Hjemmeside + FROM Services + WHERE BrukerID = %s + """, (flask_login.current_user.id,)) + + data = [] + for row in cur: + data.append(row) + + cur.close() + conn.close() + return render_template("pages/services.html", data=data, form=form) + @glob.app.route("/login", methods = ["GET", "POST"]) def login(): if flask_login.current_user.is_authenticated: diff --git a/templates/layout/includes/side_nav.html b/templates/layout/includes/side_nav.html index 6b83349..827f40a 100644 --- a/templates/layout/includes/side_nav.html +++ b/templates/layout/includes/side_nav.html @@ -131,6 +131,14 @@ + +
+

{{ _("Contacts") }}

+
+
+ + {{ _("Services") }} +
diff --git a/templates/pages/services.html b/templates/pages/services.html new file mode 100644 index 0000000..13519f8 --- /dev/null +++ b/templates/pages/services.html @@ -0,0 +1,82 @@ +{% set title = _("Services") %} + +{% extends "layout/dash.html" %} + +{% block content %} + + + +
+ + + + + + + + + + + + + + + +{% for row in data %} + + + + + + + + +{% endfor %} + +
{{ _("Name") }}{{ _("Type") }}{{ _("Contact") }}{{ _("Phone") }}{{ _("Website") }}
{{ row[0] }}{{ row[1] }}{{ row[2] }}{{ row[3] }}{{ row[4] }}
+ +
+ +{% endblock %} \ No newline at end of file