add sql support
This commit is contained in:
parent
17ab0b1840
commit
e794fc6032
@ -1,3 +1,9 @@
|
||||
# freeriders
|
||||
|
||||
Web app for tracking current ticket numbers
|
||||
|
||||
# Architecture
|
||||
|
||||
- keep all ticket numbers and timestamps in SQL table "tickets"
|
||||
- display last ticket number
|
||||
- don't allow tickets that are out of probable ticket number range
|
||||
|
@ -4,7 +4,7 @@ Priority: optional
|
||||
Architecture: all
|
||||
Essential: no
|
||||
Installed-Size: 2000
|
||||
Depends: python3-flask, gunicorn
|
||||
Depends: gunicorn, python3-flask-sqlalchemy
|
||||
Homepage: https://gitea.dmz.rs/Decentrala/freeriders
|
||||
Maintainer: Decentrala <dmz@dmz.rs>
|
||||
Description: Web app that tracks bus transport ticket numbers
|
||||
|
@ -1,5 +1,16 @@
|
||||
from flask import Flask
|
||||
from flask_sqlalchemy import SQLAlchemy
|
||||
import os # if you wanna have db credenitalas in os.environ
|
||||
|
||||
app = Flask(__name__)
|
||||
|
||||
# SQLAlchemy setup
|
||||
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///freeriders.db'
|
||||
|
||||
#MySql setup
|
||||
#app.config['SQLALCHEMY_DATABASE_URI'] = 'mysql://user:pass@localhost/dbname'
|
||||
|
||||
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
|
||||
db = SQLAlchemy(app)
|
||||
|
||||
from freeriders import routes
|
||||
|
6
freeriders/models.py
Normal file
6
freeriders/models.py
Normal file
@ -0,0 +1,6 @@
|
||||
from freeriders import db
|
||||
|
||||
class Tickets(db.Model):
|
||||
id = db.Column(db.Integer, primary_key=True)
|
||||
ticket = db.Column(db.Integer, nullable=False)
|
||||
timestamp = db.Column(db.Integer, nullable=False)
|
@ -1,11 +1,23 @@
|
||||
from flask import render_template, request, redirect
|
||||
from freeriders import app
|
||||
from freeriders import app, db
|
||||
from freeriders.models import Ticket
|
||||
import time
|
||||
|
||||
@app.route('/', methods=['POST', 'GET'])
|
||||
def changepassword():
|
||||
if request.method == 'GET':
|
||||
return render_template('index.html')
|
||||
elif request.method == 'POST':
|
||||
return 'Post'
|
||||
timenow = int(time.time())
|
||||
ticket_input = request.form['ticket']
|
||||
ticket = Ticket(ticket=ticket_input, timestamp=timenow)
|
||||
|
||||
try:
|
||||
db.session.add(ticket)
|
||||
db.session.commit()
|
||||
return 'Ticket je dodat'
|
||||
except:
|
||||
return 'Dodavanje ticketa nije uspelo'
|
||||
|
||||
else:
|
||||
return 'HTTP request method not recogniezed'
|
||||
|
10
init_db.py
Executable file
10
init_db.py
Executable file
@ -0,0 +1,10 @@
|
||||
#!/usr/bin/env python3
|
||||
from freeriders import db
|
||||
|
||||
print('[i] Trying to create databse...')
|
||||
try:
|
||||
db.create_all()
|
||||
print('[+] Success you can proceed with deployment!')
|
||||
except:
|
||||
print('[-] Creating db failed :/')
|
||||
|
@ -1 +1,2 @@
|
||||
flask
|
||||
SQLAlchemy
|
||||
|
Loading…
Reference in New Issue
Block a user