-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
230 lines (181 loc) · 9.12 KB
/
main.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
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
from flask import Blueprint, render_template, request, flash, redirect, url_for, abort
import requests
from db import db
from flask_login import login_required, current_user
from models.user import User
from werkzeug.utils import secure_filename
from models.warehouse import Warehouse
from models.warehouse_service import WarehouseServices
from models.warehouse_booking import WarehouseBooking
from models.img import Img
main = Blueprint('main', __name__)
@main.route('/')
def index():
return render_template('index.html', title = "Home")
@main.route('/dashboard/remove/<int:warehouse_id>')
def remove(warehouse_id):
data = Warehouse.query.filter_by(id=warehouse_id).first()
data_price = WarehouseServices.query.filter_by(warehouse_id=warehouse_id).first()
if data_price:
db.session.delete(data_price)
db.session.delete(data)
db.session.commit()
return redirect(url_for('main.dashboard'))
@main.route('/dashboard')
@login_required
def dashboard():
if current_user.isAdmin:
data = Warehouse.query.order_by(Warehouse.id.asc()).all()
users = User.query.all()
return render_template('dashboard.html', data = data, users = users, title = "Dashboard")
elif current_user.u_role == "owner":
bookings = []
for x in current_user.warehouse_id:
temp = WarehouseBooking.query.filter(WarehouseBooking.warehouse_id == x, WarehouseBooking.contracted == None).all()
if temp:
for item in temp:
bookings.append(item)
users = User.query.all()
data = Warehouse.query.filter_by(owner = current_user.id).order_by(Warehouse.id.asc()).all()
return render_template('dashboard.html', data = data, users = users, booking = bookings, title = "Dashboard")
elif current_user.u_role == "merchant":
requests = WarehouseBooking.query.filter(WarehouseBooking.merchant_id == current_user.id, WarehouseBooking.contracted == None).all()
active_bookings = WarehouseBooking.query.filter(WarehouseBooking.merchant_id == current_user.id, WarehouseBooking.contracted == True).all()
data = []
active_warehouses = []
for x in requests:
data.append(Warehouse.query.filter(Warehouse.id == x.warehouse_id).first())
for x in active_bookings:
active_warehouses.append(Warehouse.query.filter(Warehouse.id == x.warehouse_id).first())
data = list(dict.fromkeys(data))
print(active_warehouses)
return render_template('dashboard-merchant.html', requests = requests, data = data, active_bookings=active_bookings, active_warehouses=active_warehouses)
else:
abort(403)
@main.route('/edit/details/<int:warehouse_id>')
@login_required
def warehouse_view(warehouse_id):
if current_user.u_role == "owner" or current_user.isAdmin:
data = Warehouse.query.filter_by(id=warehouse_id).one()
if data.owner == current_user.id or current_user.isAdmin:
return render_template('admin/warehouse_view.html', data = data, title = "Edit")
else:
abort(403)
else:
abort(403)
@main.route('/edit/details/<int:warehouse_id>', methods = ['POST'])
def warehouse_edit(warehouse_id):
data = Warehouse.query.filter_by(id=warehouse_id).first()
w_price = WarehouseServices.query.filter_by(warehouse_id=warehouse_id).first()
data.name = request.form.get("name")
data.volume_available = request.form.get("a_volume")
data.volume_total = request.form.get("t_volume")
data.address = request.form.get("address")
data.email = request.form.get("email")
data.phone = request.form.get("phone")
data.labelling = True if request.form.getlist('labelling') else False
data.manual_geo_data_entry = True if request.form.getlist('manual_geo_data_entry') else False
data.item_packaging = True if request.form.getlist('item_packaging') else False
data.palette_packaging = True if request.form.getlist('palette_packaging') else False
if w_price:
if w_price.goods_receiving_labelling and not data.labelling:
w_price.goods_receiving_labelling = None
if w_price.goods_receiving_manuel_geo_data and not data.manual_geo_data_entry:
w_price.goods_receiving_manuel_geo_data = None
if w_price.item_packaging and not data.item_packaging:
w_price.item_packaging = None
if w_price.palette_packaging and not data.palette_packaging:
w_price.palette_packaging = None
db.session.commit()
if current_user.isAdmin:
return redirect(url_for('main.admin'))
elif current_user.u_role == "owner":
return redirect(url_for('main.dashboard'))
@main.route('/prices/<int:warehouse_id>')
@login_required
def warehouse_price(warehouse_id):
if current_user.u_role == "owner" or current_user.isAdmin:
data = Warehouse.query.filter_by(id=warehouse_id).one()
if data.owner == current_user.id or current_user.isAdmin:
data_price = WarehouseServices.query.filter_by(warehouse_id=warehouse_id).first()
return render_template('admin/warehouse_price.html', data = data, data_price = data_price, title = "Prices")
else:
abort(403)
else:
abort(403)
@main.route('/prices/<int:warehouse_id>', methods = ['POST'])
def warehouse_price_Edit(warehouse_id):
print("test")
data = Warehouse.query.filter_by(id=warehouse_id).one()
check = WarehouseServices.query.filter_by(warehouse_id=warehouse_id).first()
if not check:
storage = request.form.get("storage")
item_picking = request.form.get("item_picking")
packaging_material = request.form.get("packaging_material")
goods_processing = request.form.get("goods_receiving_processing")
new_wprice = WarehouseServices(storage, item_picking, goods_processing, packaging_material, warehouse_id)
if data.labelling:
new_wprice.set_labelling(request.form.get("goods_receiving_labelling"))
if data.manual_geo_data_entry:
new_wprice.set_manualgeodata(request.form.get("goods_receiving_manuel_geo_data"))
if data.item_packaging:
new_wprice.set_item(request.form.get("item_packaging"))
if data.palette_packaging:
new_wprice.set_packaging(request.form.get("palette_packaging"))
db.session.add(new_wprice)
else:
check.storage = request.form.get("storage")
check.item_picking = request.form.get("item_picking")
check.packaging_material = request.form.get("packaging_material")
check.goods_receiving_processing = request.form.get("goods_receiving_processing")
if data.labelling:
check.goods_receiving_labelling = request.form.get("goods_receiving_labelling")
if data.manual_geo_data_entry:
check.goods_receiving_manuel_geo_data = request.form.get("goods_receiving_manuel_geo_data")
if data.item_packaging:
check.item_packaging = request.form.get("item_packaging")
if data.palette_packaging:
check.palette_packaging = request.form.get("palette_packaging")
db.session.commit()
return redirect(url_for('main.dashboard'))
@main.route('/profile')
@login_required
def profile():
if current_user.u_role == "owner":
data = Warehouse.query.filter_by(owner = current_user.id).order_by(Warehouse.id.asc()).all()
return render_template('profile.html', data = data, title = "Profile")
else:
return render_template('profile.html', title = "Profile")
@main.route('/add-warehouse')
@login_required
def add_warehouse():
if current_user.u_role == "merchant":
abort(403)
elif current_user.u_role == "owner":
return render_template('authentication/add_warehouse.html', title = "Add warehouse")
@main.route('/add-warehouse', methods = ['POST'])
def add_warehousePost():
""" pic = request.files['pic']
filename = secure_filename(pic.filename)
mimetype = pic.mimetype
img = Img(img=pic.read(), name=filename, mimetype=mimetype, warehouse=current_user.id) """
name = request.form.get('w_name')
available_storage = request.form.get('w_astorage')
total_storage = request.form.get('w_tstorage')
labelling = True if request.form.getlist('labelling') else False
manual_geo_data_entry = True if request.form.getlist('manual_geo_data_entry') else False
item_packaging = True if request.form.getlist('item_packaging') else False
palette_packaging = True if request.form.getlist('palette_packaging') else False
address = request.form.get('address')
email = request.form.get('email')
phone = request.form.get('phone')
new_warehouse = Warehouse(name, available_storage, total_storage, labelling, manual_geo_data_entry, item_packaging, palette_packaging, address, email, phone, current_user.id)
""" db.session.add(img) """
db.session.add(new_warehouse)
print("Added new warehouse")
db.session.commit()
print("Commited warehouse")
return redirect(url_for('main.warehouse_price',warehouse_id = new_warehouse.id))
@main.route('/software')
def software():
return render_template('software/software.html', title = "Under construction")