Prześlij pliki do ''
This commit is contained in:
parent
be4a52ee75
commit
06cc3604e5
88
app.py
88
app.py
@ -1,3 +1,5 @@
|
||||
from flask import Flask, request, flash, url_for, redirect, render_template
|
||||
from flask_sqlalchemy import SQLAlchemy
|
||||
from flask import *
|
||||
import sqlite3, hashlib, os
|
||||
from werkzeug.utils import secure_filename
|
||||
@ -7,6 +9,21 @@ app.secret_key = 'random string'
|
||||
UPLOAD_FOLDER = 'static/uploads'
|
||||
ALLOWED_EXTENSIONS = set(['jpeg', 'jpg', 'png', 'gif'])
|
||||
app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER
|
||||
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///C:\\Users\\Sławek\\Scripts\\Flask\\pracownia programowania1.1\\database.db'
|
||||
app.config['SECRET_KEY'] = "random string"
|
||||
|
||||
db = SQLAlchemy(app)
|
||||
|
||||
class komentarze(db.Model):
|
||||
nick = db.Column(db.String(100), primary_key = True)
|
||||
produkt = db.Column(db.String(50))
|
||||
koment = db.Column(db.String(200))
|
||||
|
||||
def __init__(self, nick, produkt, koment):
|
||||
self.nick = nick
|
||||
self.produkt = produkt
|
||||
self.koment = koment
|
||||
|
||||
|
||||
def getLoginDetails():
|
||||
with sqlite3.connect('database.db') as conn:
|
||||
@ -72,6 +89,58 @@ def addItem():
|
||||
conn.close()
|
||||
print(msg)
|
||||
return redirect(url_for('root'))
|
||||
|
||||
@app.route("/delete")
|
||||
def delete():
|
||||
with sqlite3.connect('database.db') as conn:
|
||||
cur = conn.cursor()
|
||||
cur.execute('SELECT productId, name, price, description, image, stock FROM products')
|
||||
data = cur.fetchall()
|
||||
conn.close()
|
||||
return render_template('delete.html', data=data)
|
||||
|
||||
@app.route("/deleteItem")
|
||||
def deleteItem():
|
||||
productId = request.args.get('productId')
|
||||
with sqlite3.connect('database.db') as conn:
|
||||
try:
|
||||
cur = conn.cursor()
|
||||
cur.execute('DELETE FROM products WHERE productID = ?', (productId, ))
|
||||
conn.commit()
|
||||
msg = "Deleted successsfully"
|
||||
except:
|
||||
conn.rollback()
|
||||
msg = "Error occured"
|
||||
conn.close()
|
||||
print(msg)
|
||||
return redirect(url_for('root'))
|
||||
|
||||
@app.route("/update")
|
||||
def update():
|
||||
with sqlite3.connect('database.db') as conn:
|
||||
cur = conn.cursor()
|
||||
cur.execute('SELECT productId, name, price, description, image, stock FROM products')
|
||||
data = cur.fetchall()
|
||||
conn.close()
|
||||
return render_template('update.html', data=data)
|
||||
|
||||
@app.route("/updateItem", methods=["GET", "POST"])
|
||||
def updateItem():
|
||||
if request.method == "POST":
|
||||
price = float(request.form['price'])
|
||||
name = request.form['name']
|
||||
with sqlite3.connect('database.db') as conn:
|
||||
try:
|
||||
cur = conn.cursor()
|
||||
cur.execute('UPDATE products SET price = ? where name = ?', (price, name, ))
|
||||
conn.commit()
|
||||
msg = "upload successsfully"
|
||||
except:
|
||||
conn.rollback()
|
||||
msg = "Error occured"
|
||||
conn.close()
|
||||
print(msg)
|
||||
return redirect(url_for('update'))
|
||||
|
||||
@app.route("/displayCategory")
|
||||
def displayCategory():
|
||||
@ -152,7 +221,7 @@ def updateProfile():
|
||||
cur = con.cursor()
|
||||
cur.execute('UPDATE users SET firstName = ?, lastName = ?, address1 = ?, address2 = ?, zipcode = ?, city = ?, state = ?, country = ?, phone = ? WHERE email = ?', (firstName, lastName, address1, address2, zipcode, city, state, country, phone, email))
|
||||
|
||||
con.commit()
|
||||
con.commit()
|
||||
msg = "Saved Successfully"
|
||||
except:
|
||||
con.rollback()
|
||||
@ -313,6 +382,23 @@ def parse(data):
|
||||
ans.append(curr)
|
||||
return ans
|
||||
|
||||
@app.route('/show')
|
||||
def show():
|
||||
return render_template('show.html', komentarze = komentarze.query.all() )
|
||||
|
||||
@app.route('/new', methods = ['GET', 'POST'])
|
||||
def new():
|
||||
if request.method == 'POST':
|
||||
if not request.form['nick'] or not request.form['produkt'] or not request.form['koment']:
|
||||
flash('Please enter all the fields', 'error')
|
||||
else:
|
||||
komentarz = komentarze(nick=request.form['nick'], produkt=request.form['produkt'], koment=request.form['koment'])
|
||||
db.session.add(komentarz)
|
||||
db.session.commit()
|
||||
flash('Record was successfully added')
|
||||
return redirect(url_for('show'))
|
||||
return render_template('new.html')
|
||||
|
||||
@app.errorhandler(404)
|
||||
def page_not_found(e):
|
||||
return render_template("404.html")
|
||||
|
BIN
database.db
BIN
database.db
Binary file not shown.
Loading…
Reference in New Issue
Block a user