Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @app.route('/')
- def index():
- day_of_week = date.today().strftime('%A')
- json_file = str(os.getcwd()) + "\\static\\data.json"
- with open(json_file, 'r+') as file:
- json_data = json.load(file)
- return render_template('test_table.html', name="Hot Rack", json_data=json_data, return_day_value = day_values, save_data = save_data , day_of_week = day_of_week, build_table_rows = build_table_rows)
- def day_values(day, json_data):
- return json_data[day]
- def save_data(json_data):
- json_file_path = str(os.getcwd())+'\\static\\data.json'
- with open(json_file_path, 'w') as file:
- json.dumps(json_data)
- def build_table_rows(day, json_data, mode):
- header = """<tr class="row100 body">"""
- rows = []
- for item in json_data[day]['Items']:
- foodItem = ""
- row = ""
- foodItem += """<td class="cell100 column1">{0}</td>""".format(item)
- if mode == "AM":
- hours = ['TWELVEAM', 'ONEAM','TWOAM', 'THREEAM', 'FOURAM', 'FIVEAM', 'SIXAM','SEVENAM','EIGHTAM','NINEAM','TENAM','ELEVENAM']
- for hour in hours:
- foodItem += """<td class="cell100 column2">{0}</td>""".format(json_data[day]['Items'][item][hour])
- elif mode == "PM":
- hours = ['TWELVEPM', 'ONEPM','TWOPM', 'THREEPM', 'FOURPM', 'FIVEPM', 'SIXPM','SEVENPM','EIGHTPM','NINEPM','TENPM','ELEVENPM']
- for hour in hours:
- foodItem += """<td class="cell100 column2">{0}</td>""".format(json_data[day]['Items'][item][hour])
- foodItem += '</tr>'
- row = header + foodItem
- rows.append(row)
- tables = ""
- for row in rows:
- tables += row
- return tables
- -------------------------
- html :
- <html>
- <head>
- <title> test page</title>
- </head>
- <body>
- <div class="table100-body js-pscroll">
- <table>
- <tbody>
- {{build_table_rows(day_of_week, json_data, 'AM')}}
- </tbody>
- </table>
- </div>
- </body>
- </html>
- ---------------
- OUPUT:
- <tr class="row100 body"><td class="cell100 column1">Hamburger</td><td class="cell100 column2">0</td><td class="cell100 column2">0</td><td class="cell100 column2">0</td><td class="cell100 column2">0</td><td class="cell100 column2">0</td><td class="cell100 column2">0</td><td class="cell100 column2">0</td><td class="cell100 column2">0</td><td class="cell100 column2">0</td><td class="cell100 column2">0</td><td class="cell100 column2">0</td><td class="cell100 column2">0</td></tr><tr class="row100 body"><td class="cell100 column1">Egg Rolls</td><td class="cell100 column2">0</td><td class="cell100 column2">0</td><td class="cell100 column2">0</td><td class="cell100 column2">0</td><td class="cell100 column2">0</td><td class="cell100 column2">0</td><td class="cell100 column2">0</td><td class="cell100 column2">0</td><td class="cell100 column2">0</td><td class="cell100 column2">0</td><td class="cell100 column2">0</td><td class="cell100 column2">0</td></tr><tr class="row100 body"><td class="cell100 column1">Pork Steaks</td><td class="cell100 column2">0</td><td class="cell100 column2">0</td><td class="cell100 column2">0</td><td class="cell100 column2">0</td><td class="cell100 column2">0</td><td class="cell100 column2">0</td><td class="cell100 column2">0</td><td class="cell100 column2">0</td><td class="cell100 column2">0</td><td class="cell100 column2">0</td><td class="cell100 column2">0</td><td class="cell100 column2">0</td></tr>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement