-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.py
77 lines (57 loc) · 1.82 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
# main.py
from app import app
from db_setup import init_db, db_session
from forms import roomForm,MusicSearchForm
from flask import flash, render_template, request, redirect
from models import Buildings, Room
from tables import Results
init_db()
@app.route('/', methods=['GET', 'POST'])
def index():
search = MusicSearchForm(request.form)
if request.method == 'POST':
return search_results(search)
return render_template('index.html', form=search)
@app.route('/new_data', methods=['GET', 'POST'])
def new_data():
"""
Add a new album
"""
form = roomForm(request.form)
if request.method == 'POST' and form.validate():
# save the album
rooms = Room()
save_changes(rooms, form, new=True)
flash(' created successfully!')
return redirect('/')
return render_template('new_data.html', form=form)
def save_changes(rooms, form, new=False):
"""
Save the changes to the database
"""
# Get data from form and assign it to the correct attributes
# of the SQLAlchemy table object
buildings = Buildings()
buildings.buildingName=form.buildingName.data
buildings.address=form.address.data
buildings.l1=form.l1.data
buildings.l2=form.l2.data
buildings.l3=form.l3.data
rooms.buildings = rooms
rooms.flatno = form.flatno.data
rooms.rent = form.rent.data
rooms.area = form.area.data
#rooms.bathrooms = form.bathrooms.data
rooms.electricity = form.electricity.data
rooms.maintain = form.maintain.data
if new:
# Add the new album to the database
db_session.add(rooms)
db_session.add(buildings)
# commit the data to the database
db_session.commit()
if __name__ == '__main__':
import os
if 'WINGDB_ACTIVE' in os.environ:
app.debug = True
app.run(debug=True)