18 Commits

Autor SHA1 Nachricht Datum
  Jose Reyes 59ffe580a3 Adds datetime to turno vor 6 Jahren
  Jose Reyes 719d3ef925 Fixes form names for queries vor 6 Jahren
  Jose Reyes ee1d6ba168 Fixes retrieval of vals to int vor 6 Jahren
  Jose Reyes 8925b61f6b Changes index redirect and template stuff vor 6 Jahren
  Jose Reyes 2560b41cae Removes error stuff vor 6 Jahren
  Jose Reyes f086a73eb6 Fixes some styling vor 6 Jahren
  Jose Reyes b4505a3cdb Removes old comments vor 6 Jahren
  Jose Reyes 8e7e467e86 Moves index stuff to seperate blueprint vor 6 Jahren
  Jose Reyes 449bd9a7f9 Ignores instance dir vor 6 Jahren
  Jose Reyes 64d20dc193 Arranges structure into app dir vor 6 Jahren
  Jose Reyes 42006f187c Adds test radio button input vor 6 Jahren
  Jose Reyes 999cc93e69 Adds station retrieval from form vor 6 Jahren
  Jose Reyes 2b14abd89b Adds fetchone to turn retrieval query vor 6 Jahren
  Jose Reyes 86ea41bcf4 Fixes inputs to db.execute() vor 6 Jahren
  Jose Reyes 9284ee817b Adds turn number to insert query vor 6 Jahren
  Jose Reyes db88574082 Separates query for looking up station id vor 6 Jahren
  Jose Reyes 7596fab6fe Adds turn number entry to turno table vor 6 Jahren
  Jose Reyes 7cf50790c0 Fixes INTEGER in schema, adds mock index function and templates vor 6 Jahren
9 geänderte Dateien mit 133 neuen und 37 gelöschten Zeilen
  1. 1
    0
      .gitignore
  2. 0
    8
      __init__.py
  3. 28
    0
      app/__init__.py
  4. 0
    3
      app/db.py
  5. 44
    0
      app/index.py
  6. 30
    0
      app/schema.sql
  7. 13
    0
      app/templates/base.html
  8. 17
    0
      app/templates/index.html
  9. 0
    26
      schema.sql

+ 1
- 0
.gitignore Datei anzeigen

@@ -16,6 +16,7 @@ _mailinglist
16 16
 .pytest_cache/
17 17
 .idea/
18 18
 docs/_build/
19
+instance/
19 20
 
20 21
 # Coverage reports
21 22
 htmlcov/

+ 0
- 8
__init__.py Datei anzeigen

@@ -1,8 +0,0 @@
1
-def create_app():
2
-    app = ...
3
-    # existing code omitted
4
-
5
-    from . import db
6
-    db.init_app(app)
7
-
8
-    return app

+ 28
- 0
app/__init__.py Datei anzeigen

@@ -0,0 +1,28 @@
1
+import os
2
+from flask import Flask
3
+
4
+def create_app(test_config=None):
5
+    app = Flask(__name__, instance_relative_config=True)
6
+    app.config.from_mapping(
7
+        SECRET_KEY='dev',
8
+        DATABASE=os.path.join(app.instance_path, 'upr_espera.sqlite'),
9
+    )
10
+
11
+    if test_config is None:
12
+        app.config.from_pyfile('config.py', silent=True)
13
+    else:
14
+        app.config.from_mapping(test_config)
15
+
16
+    try:
17
+        os.makedirs(app.instance_path)
18
+    except OSError:
19
+        pass
20
+
21
+    from . import db
22
+    db.init_app(app)
23
+
24
+    from . import index
25
+    app.register_blueprint(index.bp)
26
+    app.add_url_rule('/', endpoint='index')
27
+
28
+    return app

db.py → app/db.py Datei anzeigen

@@ -4,7 +4,6 @@ import click
4 4
 from flask import current_app, g
5 5
 from flask.cli import with_appcontext
6 6
 
7
-
8 7
 def get_db():
9 8
     if 'db' not in g:
10 9
         g.db = sqlite3.connect(
@@ -15,7 +14,6 @@ def get_db():
15 14
 
16 15
     return g.db
17 16
 
18
-
19 17
 def close_db(e=None):
20 18
     db = g.pop('db', None)
21 19
 
@@ -27,7 +25,6 @@ def init_db():
27 25
     with current_app.open_resource('schema.sql') as f:
28 26
         db.executescript(f.read().decode('utf8'))
29 27
 
30
-
31 28
 @click.command('init-db')
32 29
 @with_appcontext
33 30
 def init_db_command():

+ 44
- 0
app/index.py Datei anzeigen

@@ -0,0 +1,44 @@
1
+from datetime import datetime
2
+
3
+from flask import (
4
+    Blueprint, flash, g, redirect, render_template, request, url_for
5
+)
6
+from werkzeug.exceptions import abort
7
+
8
+from app.db import get_db
9
+
10
+bp = Blueprint('index', __name__)
11
+
12
+@bp.route('/', methods=('GET', 'POST'))
13
+def index():
14
+    if request.method == 'POST':
15
+        cName = request.form['cName']
16
+        cEmail = request.form['cEmail']
17
+        station_name = request.form['station']
18
+
19
+        db = get_db()
20
+        station_query_res = db.execute(
21
+            'SELECT s_id FROM station WHERE nombre_empleado=?',
22
+            (station_name,)
23
+        ).fetchone()
24
+        if station_query_res is not None:
25
+            station_id = station_query_res[0]
26
+        db.execute(
27
+            'UPDATE station SET last_turn = last_turn + 1 WHERE s_id=?',
28
+            (station_id,)
29
+        )
30
+        turn_query_res = db.execute(
31
+            'SELECT last_turn FROM station WHERE s_id=?',
32
+            (station_id,)
33
+        ).fetchone()
34
+        if turn_query_res is not None:
35
+            turn = turn_query_res[0]
36
+        db.execute(
37
+            'INSERT INTO turno (cName, cEmail, turn, timeArrival, station)'
38
+            ' VALUES (?, ?, ?, ?, ?)',
39
+            (cName, cEmail, turn, '{0:%H:%M}'.format(datetime.now()), station_id)
40
+        )
41
+        db.commit()
42
+        return redirect(url_for('index'))
43
+
44
+    return render_template('index.html')

+ 30
- 0
app/schema.sql Datei anzeigen

@@ -0,0 +1,30 @@
1
+DROP TABLE IF EXISTS station;
2
+DROP TABLE IF EXISTS user;
3
+DROP TABLE IF EXISTS turn;
4
+
5
+CREATE TABLE station (
6
+  s_id INTEGER PRIMARY KEY AUTOINCREMENT,
7
+  nombre_empleado CHAR(20)  NOT NULL,
8
+  oficina CHAR(20) NOT NULL,
9
+  last_turn INTEGER NOT NULL
10
+);
11
+
12
+CREATE TABLE user (
13
+  u_id INTEGER PRIMARY KEY AUTOINCREMENT,
14
+  uName CHAR(20) NOT NULL,
15
+  isAdmin BIT NOT NULL,
16
+  email CHAR(30) NOT NULL
17
+);
18
+
19
+CREATE TABLE turno (
20
+ t_id INTEGER PRIMARY KEY AUTOINCREMENT,
21
+ cName CHAR(20) NOT NULL, 
22
+ cEmail CHAR(30) NOT NULL, 
23
+ purpose CHAR(40), 
24
+ turn INTEGER NOT NULL, 
25
+ timeArrival CHAR(5) NOT NULL, 
26
+ timeEnter CHAR(5),
27
+ station INTEGER NOT NULL, 
28
+ FOREIGN KEY (station) REFERENCES station (s_id) 
29
+);
30
+

+ 13
- 0
app/templates/base.html Datei anzeigen

@@ -0,0 +1,13 @@
1
+<!doctype html>
2
+<title>{% block title %}{% endblock %} - UPR Queue</title>
3
+
4
+<section class="content">
5
+    <header>
6
+        {% block header %}{% endblock %}
7
+    </header>
8
+    {% for message in get_flashed_messages() %}
9
+        <div class="flash">{{ message }}</div>
10
+    {% endfor %}
11
+    {% block content %}{% endblock %}
12
+</section>
13
+

+ 17
- 0
app/templates/index.html Datei anzeigen

@@ -0,0 +1,17 @@
1
+{% extends 'base.html' %}
2
+
3
+{% block header %}
4
+    <h1>{% block title %}UPR Queue{% endblock %}</h1>
5
+{% endblock %}
6
+
7
+{% block content %}
8
+    <form method="post">
9
+        <label for="cName">Name</label>
10
+        <input name="cName" id="name" required></input><br>
11
+		<label for="cEmail">email</label>
12
+        <input name="cEmail" id="email" required></input><br>
13
+        <input type="radio" name="station" id="station1" value="Fulano"> Fulano </input><br>
14
+        <input type="radio" name="station" id="station2" value="Mengana"> Mengana </input><br>
15
+        <input type="submit" value="Get ticket">
16
+    </form>
17
+{% endblock %}

+ 0
- 26
schema.sql Datei anzeigen

@@ -1,26 +0,0 @@
1
-
2
-CREATE TABLE station (
3
-  s_id INT PRIMARY KEY AUTOINCREMENT,
4
-  nombre_empleado CHAR(20)  NOT NULL,
5
-  oficina CHAR(20) NOT NULL,
6
-  last_turn INT NOT NULL
7
-);
8
-
9
-CREATE TABLE user (
10
-  u_id INT PRIMARY KEY AUTOINCREMENT,
11
-  uName CHAR(20) NOT NULL,
12
-  isAdmin BIT NOT NULL,
13
-  email CHAR(30) NOT NULL
14
-);
15
-
16
-CREATE TABLE turno(
17
- t_id INT PRIMARY KEY AUTOINCREMENT,
18
- cName CHAR(20) NOT NULL, 
19
- cEmail CHAR(30) NOT NULL, 
20
- purpose CHAR(40), 
21
- timeArrival CHAR(5) NOT NULL, 
22
- timeEnter CHAR(5),
23
- station INT NOT NULL, 
24
- FOREIGN KEY (station) REFERENCES station (id) 
25
-);
26
-