-
Notifications
You must be signed in to change notification settings - Fork 0
/
ManagementWarehouseApp.py
211 lines (172 loc) · 7.81 KB
/
ManagementWarehouseApp.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
from flask import Flask, render_template, request, redirect, url_for, session
from flask_sqlalchemy import SQLAlchemy
from passlib.hash import sha256_crypt
from forms import LoginForm, RegisterForm, ReceiptForm, NewTypeForm
from management_warehouseDB import User, Application_receipt, Complect, Type, Sort, Manufacturer, Sklad
app = Flask(__name__)
app.config.from_pyfile('config.cfg')
db = SQLAlchemy(app)
@app.route('/SignUp', methods=['GET', 'POST'])
def registration():
form = RegisterForm(request.form)
if request.method == 'POST' and form.validate():
login = form.login.data
password = sha256_crypt.encrypt(str(form.password.data))
email = form.email.data
username = form.username.data
admin = User(login, password, email, username)
db.session.add(admin)
db.session.commit()
session['curent_user'] = admin.login
return redirect(url_for('main_page'))
return render_template('registration.html', form=form)
@app.route('/LogIn', methods=['GET', 'POST'])
def login():
form = LoginForm(request.form)
if request.method == 'POST' and form.validate():
login_form = request.form['login']
password_form_candidate = request.form['password']
user = User.query.filter_by(login=login_form).first()
session['curent_user'] = user.login
if sha256_crypt.verify(password_form_candidate, user.password):
if user.login == 'Admin99':
return redirect(url_for('AdminPage'))
return redirect(url_for('main_page'))
return render_template('singIn.html')
@app.route('/')
def start_page():
session.clear()
return redirect(url_for('login'))
@app.route('/main', methods=['GET', 'POST'])
def main_page():
sesion_user_login = session['curent_user'] # counterpart for session
curent_id = db.session.query(User.id).filter(User.login == sesion_user_login)
join_table = db.session \
.query(Application_receipt, Complect, Manufacturer, Sort, Type) \
.filter(Application_receipt.provider_id == curent_id) \
.join(Complect) \
.filter(Application_receipt.complect_id == Complect.id) \
.join(Manufacturer) \
.filter(Complect.manufacturer_id == Manufacturer.id) \
.join(Sort) \
.filter(Complect.sort_id == Sort.id) \
.join(Type) \
.filter(Sort.types_id == Type.id)
return render_template('mainPage.html', curent_user=sesion_user_login
, second_table=join_table
)
@app.route('/receipt', methods=['GET', 'POST'])
def receipt_application():
form = ReceiptForm(request.form)
conn = db.engine.connect()
session_user_login = session['curent_user']
types_names = db.session.query(Type)
sort_names = db.session.query(Sort)
if request.method == 'POST' and form.validate():
id_type = request.form['typ']
type_price = Type.query.filter_by(id=id_type).first().price
name_sort = request.form['sort']
manufacture_name = form.manufacturer.data
if db.session.query(Manufacturer).filter_by(name=manufacture_name).scalar() == None:
brand_app = Manufacturer(manufacture_name)
db.session.add(brand_app)
db.session.commit()
complect_sort_id = db.session.query(Sort.id).filter_by(name=name_sort)
complect_manufacture_id = db.session.query(Manufacturer.id).filter_by(name=manufacture_name)
complect_app = Complect(complect_sort_id, complect_manufacture_id)
db.session.add(complect_app)
db.session.commit()
app_complect_id = conn.execute('select id from complect order by id desc limit 1')
app_complect_id = app_complect_id.fetchone()
app_complect_id = app_complect_id[0]
app_quantity = form.quantity.data
app_date_adoption = form.date_adoption.data
app_date_issue = form.date_issue.data
#app_provider_id = User.query.filter_by(login=session_user_login).first().id
app_provider_id = db.session.query(User.id).filter(User.login == session_user_login)
app_price = app_quantity * type_price
app_confirmed = False
receipt_app = Application_receipt(app_complect_id, app_quantity, app_date_adoption, app_date_issue,
app_provider_id, app_price, app_confirmed)
db.session.add(receipt_app)
db.session.commit()
conn.close()
return redirect(url_for('main_page'))
return render_template('applicationForReceipt.html', form=form, TypeHtml=types_names, sort_html=sort_names)
@app.route('/admin', methods=['GET', 'POST'])
def AdminPage():
join_table_admin = db.session \
.query(Application_receipt, Complect, Manufacturer, Sort, Type, User) \
.join(Complect) \
.filter(Application_receipt.complect_id == Complect.id) \
.join(Manufacturer) \
.filter(Complect.manufacturer_id == Manufacturer.id) \
.join(Sort) \
.filter(Complect.sort_id == Sort.id) \
.join(Type) \
.filter(Sort.types_id == Type.id) \
.join(User) \
.filter(Application_receipt.provider_id == User.id)
return render_template('adminPage.html', admin_table=join_table_admin)
@app.route('/change_status/<string:id>',methods=['POST','GET'])
def change_status(id):
app_id = id
db.session.query(Application_receipt).filter(Application_receipt.id == app_id). \
update({'confirmed': True})
db.session.commit()
sklad_application_id = app_id
sklad_issued = False
sklad_appl = Sklad(sklad_application_id, sklad_issued)
db.session.add(sklad_appl)
db.session.commit()
return redirect(url_for('AdminPage'))
@app.route('/adminIssue', methods=['GET', 'POST'])
def IssuedPage():
join_table_admin = db.session \
.query(Application_receipt, Complect, Manufacturer, Sort, Type, User, Sklad) \
.join(Complect) \
.filter(Application_receipt.complect_id == Complect.id) \
.join(Manufacturer) \
.filter(Complect.manufacturer_id == Manufacturer.id) \
.join(Sort) \
.filter(Complect.sort_id == Sort.id) \
.join(Type) \
.filter(Sort.types_id == Type.id) \
.join(User) \
.filter(Application_receipt.provider_id == User.id) \
.filter(Application_receipt.confirmed == True) \
.join(Sklad) \
.filter(Application_receipt.id == Sklad.application_id)
return render_template('IssuedPage.html', admin_table=join_table_admin)
@app.route('/change_issue_status/<string:id>',methods=['POST','GET'])
def change_issue_status(id):
db.session.query(Sklad).filter(Sklad.application_id == id). \
update({'issued': True})
db.session.commit()
return redirect(url_for('IssuedPage'))
@app.route('/newType', methods=['GET', 'POST'])
def TypePage():
form = NewTypeForm(request.form)
conn = db.engine.connect()
join_table = db.session.query(Type, Sort) \
.join(Sort) \
.filter(Type.id == Sort.types_id)
if request.method == 'POST' and form.validate():
type_name = form.type.data
type_price = form.price.data
if db.session.query(Type).filter_by(name= type_name).scalar() == None:
type_db = Type(type_name,type_price)
db.session.add(type_db)
db.session.commit()
sort_name = form.sort.data
if db.session.query(Sort).filter_by(name=sort_name).scalar() == None:
types_id = db.session.query(Type.id).filter_by(name=type_name)
sort_db = Sort(sort_name,types_id)
db.session.add(sort_db)
db.session.commit()
conn.close()
return redirect(url_for('AdminPage'))
return render_template('AddNewType.html', all_categ = join_table)
if __name__ == '__main__':
app.secret_key = 'secret123'
app.run(debug=True, port=12345, use_reloader=True)