This commit is contained in:
Emily 2019-05-28 19:48:37 +02:00
parent eb15103ec9
commit 58da211027
5 changed files with 132 additions and 1 deletions

View File

@ -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(),

View File

@ -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

View File

@ -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:

View File

@ -131,6 +131,14 @@
</div>
</div>
</div>
</div>
<div>
<h4>{{ _("Contacts") }}</h4>
</div>
<div>
<a class="item" href="{{ url_for('services') }}">
<i class="fas fa-tools"></i><span>{{ _("Services") }}</span>
</a>
</div>
</div>
</div>

View File

@ -0,0 +1,82 @@
{% set title = _("Services") %}
{% extends "layout/dash.html" %}
{% block content %}
<style id="grid">
.container.module:nth-child(1n) {
grid-area: 1 / 1 / 5 / 5;
}
</style>
<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 warrenty") }}</h4>
<button type="button" class="close" data-dismiss="modal">&times;</button>
</div>
<div class="modal-body">
{% macro render_field(field) %}
<div class="form-group">
<label for="{{ field.label.field_id }}">{{ _(field.label.text) }}</label>
{{ field(**kwargs)|safe }}
{% if field.errors %}
<ul class=errors>
{% for error in field.errors %}
<li>{{ error }}</li>
{% endfor %}
</ul>
{% endif %}
</div>
{% endmacro %}
<form method=post>
<dl>
{{ render_field(form.name) }}
{{ render_field(form.type) }}
{{ render_field(form.contact) }}
{{ render_field(form.phone) }}
{{ render_field(form.website) }}
</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>
<th scope="col">{{ _("Name") }}</th>
<th scope="col">{{ _("Type") }}</th>
<th scope="col">{{ _("Contact") }}</th>
<th scope="col">{{ _("Phone") }}</th>
<th scope="col">{{ _("Website") }}</th>
</tr>
</thead>
<tbody>
{% for row in data %}
<!--<tr class="table-{{ 'success' if row[5] else 'danger' }}">-->
<tr>
<th>{{ row[0] }}</th>
<td>{{ row[1] }}</td>
<td>{{ row[2] }}</td>
<td>{{ row[3] }}</td>
<td>{{ row[4] }}</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
{% endblock %}