Остался вывод типов и приведение к ним.

This commit is contained in:
ElEgEv 2023-09-14 17:46:46 +04:00
parent 6ea1e6a43c
commit f34f013b4a
5 changed files with 109 additions and 7 deletions

16
LabWork01/FuncLoad.py Normal file
View File

@ -0,0 +1,16 @@
import csv
from LabWork01.Shop import Shop
def createList():
newListShop = []
file = open("../res/Stores.csv", "r")
data = list(csv.reader(file, delimiter=","))
file.close()
for elem in data:
newListShop.append(Shop(elem[1], elem[2], elem[3], elem[4]))
newListShop.pop(0)
return newListShop

View File

@ -1,7 +1,23 @@
import csv
from flask import Flask, redirect, url_for, request, render_template
from LabWork01.FuncLoad import createList
app = Flask(__name__)
@app.route("/")
def home():
return render_template('main_page.html', firstColumn=1, secondColumn=4)
@app.route("/showDiapason", methods=['GET','POST'])
def numtext():
data = request.args
listShops = createList()
if int(data['firstRow']) and int(data['secondRow']) and int(data['firstColumn']) and int(data['secondColumn']):
listShops = listShops[int(data['firstRow']):int(data['secondRow'])+1:1]
return render_template('main_page.html', context=listShops, firstColumn=int(data['firstColumn']), secondColumn=int(data['secondColumn']))
if __name__=="__main__":
app.run(debug=True)
#тут просто прочитали все значения
with open('../res/Stores.csv', newline='') as csvfile:
spamreader = csv.reader(csvfile, delimiter=' ', quotechar='|')
for row in spamreader:
print(', '.join(row))

11
LabWork01/Shop.py Normal file
View File

@ -0,0 +1,11 @@
class Shop:
def __init__(self, store_area, items_available, daily_customer_count, store_sales):
self.store_area = store_area
self.items_available = items_available
self.daily_customer_count = daily_customer_count
self.store_sales = store_sales
def display_shop(self):
print('Площадь: {}. Кол-во товаров: {}. Кол-во посетителей в день: {}. '
'Кол-во покупок: {}'.format(self.store_area, self.items_available,
self.daily_customer_count, self.store_sales))

View File

@ -0,0 +1,59 @@
<!DOCTYPE html>
<html lang="ru">
<head>
<meta charset="UTF-8">
<title>Список магазинов</title>
<style>
.head {
background: #fc3;
border: 2px solid black;
padding: 20px;
}
</style>
</head>
<body>
<div>
<form action='http://127.0.0.1:5000/showDiapason' method=get>
<input type=text size=20 name=firstRow>
<input type=text size=20 name=secondRow>
<input type=text size=20 name=firstColumn>
<input type=text size=20 name=secondColumn>
<input type=submit value='Вывод'>
</form>
</div>
<div>
<table>
<tr>
{% if firstColumn == 1 %}
<th class="head">Площадь магазина, кв. м, double</th>
{% endif %}
{% if firstColumn <= 2 and secondColumn >= 2 %}
<th class="head">Кол-во продукции, шт, int</th>
{% endif %}
{% if firstColumn <= 3 and secondColumn >= 3 %}
<th class="head">Кол-во посетителей в день, чел., int</th>
{% endif %}
{% if secondColumn == 4 %}
<th class="head">Кол-во проданных товаров, шт., int</th>
{% endif %}
</tr>
{% for elem in context %}
<tr>
{% if firstColumn == 1 %}
<td>{{ elem.store_area }}</td>
{% endif %}
{% if firstColumn <= 2 and secondColumn >= 2 %}
<td>{{ elem.items_available }}</td>
{% endif %}
{% if firstColumn <= 3 and secondColumn >= 3 %}
<td>{{ elem.daily_customer_count }}</td>
{% endif %}
{% if secondColumn == 4 %}
<td>{{ elem.store_sales }}</td>
{% endif %}
</tr>
{% endfor %}
</table>
</div>
</body>
</html>

View File

@ -15,4 +15,4 @@ def numtext():
return num2words(data['name'], lang='ru')
if __name__=="__main__":
app.run(debug=False)
app.run(debug=True)