Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
e6aef67
Add files via upload
maksbulova May 12, 2020
0aa9314
Create source
maksbulova May 12, 2020
ceb4d49
Delete source
maksbulova May 12, 2020
46de726
Create txt
maksbulova May 12, 2020
dfc928f
Add files via upload
maksbulova May 12, 2020
c548a19
Delete txt
maksbulova May 12, 2020
0c440d9
Create text.txt
maksbulova May 30, 2020
08caec6
Add files via upload
maksbulova May 30, 2020
b528174
Delete text.txt
maksbulova May 30, 2020
5879cf8
Delete meal.html
maksbulova May 30, 2020
077fe47
Add files via upload
maksbulova May 30, 2020
2d4f806
Delete tables_db.py
maksbulova May 30, 2020
ce84a5c
Add files via upload
maksbulova May 30, 2020
81f5f36
Add files via upload
maksbulova May 30, 2020
80c8e22
Add files via upload
maksbulova May 30, 2020
3bf93f9
Add files via upload
maksbulova May 30, 2020
92e213d
Add files via upload
maksbulova May 30, 2020
8c559f5
Create hi.txt
maksbulova May 30, 2020
98e6916
Create hi.txt
maksbulova May 30, 2020
83ec46d
Add files via upload
maksbulova May 30, 2020
0eb3121
Create hi.txt
maksbulova May 30, 2020
de7cfed
Add files via upload
maksbulova May 30, 2020
339182b
Add files via upload
maksbulova May 30, 2020
b0e9b2b
Delete hi.txt
maksbulova May 30, 2020
534bc6c
Delete index.html
maksbulova May 30, 2020
0c7b2f2
Delete meal.html
maksbulova May 30, 2020
c2d1dc5
Delete style.css
maksbulova May 30, 2020
d3f8c5f
Add files via upload
maksbulova May 30, 2020
f74bf70
Delete app.cpython-36.pyc
maksbulova May 30, 2020
663fba5
Delete app.cpython-38.pyc
maksbulova May 30, 2020
5256a25
Delete config.cpython-38.pyc
maksbulova May 30, 2020
5cafbcd
Delete database_connection.cpython-36.pyc
maksbulova May 30, 2020
db9fd00
Delete forms.cpython-36.pyc
maksbulova May 30, 2020
ba5b801
Delete models.cpython-36.pyc
maksbulova May 30, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions Bulovatsky_Max/workshop2/source/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
from flask import Flask, render_template, request, redirect, url_for

app = Flask(__name__)


@app.route('/api/<action>', methods=['GET'])
def apiget(action):

if action == "meal":
return render_template("meal.html", meal=meal_example)

elif action == "menu":
return render_template("menu.html", menu=menu_example)

elif action == "all":
return render_template("all.html", meal=meal_example, menu=menu_example)

else:
return render_template("404.html", action_value=action)


@app.route('/api', methods=['POST'])
def apipost():


# <button type="submit" form="form_meal" name="action" value="meal_update">Submit</button>
# send name="action" and value="meal_update" to POST

if request.form["action"] == "meal_update":

meal_example["name"] = request.form["name"]
meal_example["price"] = request.form["price"]

elif request.form["action"] == "menu_update":

menu_example["name"] = request.form["name"]
menu_example["content"] = request.form["content"]



return redirect(url_for('apiget', action="all"))



if __name__ == '__main__':

meal_example = {
"name":"Ice-cream",
"price": 9.99
}

menu_example = {
"name": "Lite summer kit",
"content": ["MilkShake", "Ice-cream", "French fries"]
}

app.run()
16 changes: 16 additions & 0 deletions Bulovatsky_Max/workshop2/source/templates/404.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>404 page</title>
</head>
<body>
<p>Not correct action value: {{action_value}}</p>

<ul>
<caption>Possible actions</caption>
<li>meal</li>
<li>menu</li>
</ul>
</body>
</html>
36 changes: 36 additions & 0 deletions Bulovatsky_Max/workshop2/source/templates/all.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>all</title>
</head>
<body>


<h2>meal</h2>
<table border="2">
<tr>
<th>name</th>
<th>price</th>
</tr>
<tr>
<td>{{meal.get('name')}}</td>
<td>{{meal.get('price')}}</td>
</tr>
</table>

<h2>menu</h2>
<table border="2">
<tr>
<th>name</th>
<th>content</th>
</tr>
<tr>
<td>{{menu.get('name')}}</td>
<td>{{menu.get('content')}}</td>
</tr>
</table>


</body>
</html>
19 changes: 19 additions & 0 deletions Bulovatsky_Max/workshop2/source/templates/meal.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Meal</title>
</head>
<body>


<form action = "/api" method = "POST" id="form_meal">
<p>Name <input type = "text" name = "name" value="{{meal.get('name')}}"/></p>
<p>Price <input type = number name = "price" value="{{meal.get('price')}}" /></p>
</form>

<button type="submit" form="form_meal" name="action" value="meal_update">Submit</button>


</body>
</html>
20 changes: 20 additions & 0 deletions Bulovatsky_Max/workshop2/source/templates/menu.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>all</title>
</head>
<body>



<form action = "/api" method = "POST" id="form_menu">
<p>Name <input type = "text" name = "name" value="{{menu.get('name')}}"/></p>
<p>What does it include? <input type = text name = "content" value="{{menu.get('content')}}" /></p>
</form>

<button type="submit" form="form_menu" name="action" value="menu_update">Submit</button>


</body>
</html>
1 change: 1 addition & 0 deletions Bulovatsky_Max/workshop4/source/Procfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
web: gunicorn main:app --log-file -
13 changes: 13 additions & 0 deletions Bulovatsky_Max/workshop4/source/forms.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from flask_wtf import FlaskForm
from wtforms import SelectField, StringField, SubmitField, IntegerField, DecimalField, TextAreaField


class MealForm(FlaskForm):
name = StringField("Название: ")
price = DecimalField("Цена (за порцию): ")
taste = SelectField("Вкус: ", choices=[("1", "Сладкое"), ("2", "Соленое"), ("3", "Кислое"), ("4", "Другое")])
risk_name = SelectField("Противопоказания: ", choices=[("1", "Цитрусовые"), ("2", "Молочные продукты"),
("3", "Рыба"), ("4", "Другое")])

submit = SubmitField("Готово")

113 changes: 113 additions & 0 deletions Bulovatsky_Max/workshop4/source/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
from flask import Flask, request, jsonify, redirect, url_for, render_template
from sqlalchemy.orm import sessionmaker
import cx_Oracle
from sqlalchemy import create_engine
from tables_db import Meal, Meal, MenuMeal, Risk, MealRisk
from forms import *
from flask_sqlalchemy import SQLAlchemy

app = Flask(__name__)


oracle_connection_string = 'oracle+cx_oracle://{username}:{password}@{host}:{port}/{database}'
engine = create_engine(
oracle_connection_string.format(

username="SYS as sysdba",
password="dbpass",
sid="XE",
host="laptop",
port="1521",
database="workshopDB"

)
, echo=True
)



meal_example = {
"name": "Ice-cream",
"price": 9.99
}

menu_example = {
"name": "Lite summer kit",
"content": ["MilkShake", "Ice-cream", "French fries"]
}

db = SQLAlchemy(app)

@app.route("/", methods=['GET', 'POST'])
def hello():
return render_template('index.html')


@app.route('/meal', methods=['GET', 'POST'])
def meal():
meal_form = MealForm(request.form)

if request.method == 'POST':

meal_id = request.form['meal_id']
name = request.form['name']
price = request.form['price']
taste = request.form['taste']
risk_name = request.form['risk_name']

try:
meal = Meal(meal_id, name, price, taste, risk_name)
db.session.add(meal)
db.session.commit()

return "Dish added {}".format(meal.meal_id)

except Exception as e:
return str(e)

return render_template('meal.html', form=meal_form)




@app.route('/api/<action>', methods=['GET'])
def apiget(action):

if action == "menu":
return render_template("menu.html", menu=menu_example)

elif action == "all":
return render_template("all.html", meal=meal_example, menu=menu_example)

else:
return render_template("404.html", action_value=action)


@app.route('/api', methods=['POST'])
def apipost():


# <button type="submit" form="form_meal" name="action" value="meal_update">Submit</button>
# send name="action" and value="meal_update" to POST

if request.form["action"] == "meal_update":

meal_example["name"] = request.form["name"]
meal_example["price"] = request.form["price"]

elif request.form["action"] == "menu_update":

menu_example["name"] = request.form["name"]
menu_example["content"] = request.form["content"]

return redirect(url_for('apiget', action="all"))



if __name__ == '__main__':
app.run()





11 changes: 11 additions & 0 deletions Bulovatsky_Max/workshop4/source/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
certifi==2020.4.5.1
click==7.1.2
Flask==1.1.2
Flask-WTF==0.14.3
itsdangerous==1.1.0
Jinja2==2.11.2
MarkupSafe==1.1.1
Werkzeug==1.0.1
wincertstore==0.2
WTForms==2.3.1
gunicorn==20.0.4
Loading