Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions Workshop3/Procfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
web: gunicorn app:app --log-file -
10 changes: 10 additions & 0 deletions Workshop3/Templates/404.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>404 page</title>
</head>
<body>
<h2>Wrong action value: {{action_value}}</h2>
</body>
</html>
12 changes: 12 additions & 0 deletions Workshop3/Templates/all.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>all</title>
</head>
<body>
<p> Customer {{customer}}</p>
<p> Nutrition {{nutrition}}</p>

</body>
</html>
24 changes: 24 additions & 0 deletions Workshop3/Templates/customer.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>client</title>
</head>
<body>


<form action = "/api/customer/submit" method = "POST" id="form_customer">
<p>Name <input type = "text" name = "name" value="{{customer.get('cust_name')}}"/></p>
<p>Surname <input type = "text" name = "surname" value="{{customer.get('cust_surname')}}" /></p>
<p>Login<input type = "text" name = "login" value="{{customer.get('cust_login')}}" /></p>
<p>Password<input type = "text" name = "pass" value="{{customer.get('cust_pass')}}" /></p>
<p>E-mail <input type = "text" name = "email" value="{{customer.get('cust_email')}}"/></p>
<p>Adress <input type = "text" name = "adress" value="{{customer.get('cust_adress')}}" /></p>

</form>

<button type="submit" form="form_customer" name="action" value="customer_update">Submit</button>


</body>
</html>
25 changes: 25 additions & 0 deletions Workshop3/Templates/nutrition.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>event</title>
</head>
<body>


<form action = "/api/nutrition/submit" method = "POST" id="form_nutrition">
<p>Title <input type = "text" name = "title" value="{{nutrition.get('nutr_title')}}"/></p>
<p>Brand <input type = "text" name = "brand" value="{{nutrition.get('nutr_brand')}}" /></p>
<p>Ingredient <input type = "text" name = "ingredient" value="{{nutrition.get('nutr_ingredient')}}" /></p>
<p>Weight <input type = "text" name = "weight" value="{{nutrition.get('nutr_weight')}}"/></p>
<p>Price <input type = "text" name = "price" value="{{nutrition.get('nutr_price')}}" /></p>
<p>Description <input type = "text" name = "descr" value="{{nutrition.get('nutr_description')}}"/></p>


</form>

<button type="submit" form="form_nutrition" name="action" value="nutriton_update">Submit</button>


</body>
</html>
Binary file added Workshop3/WorkShop3 Flask.pdf
Binary file not shown.
73 changes: 73 additions & 0 deletions Workshop3/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
from flask import Flask, request, render_template

app = Flask(__name__)


nutrition_dictionary = {
"nutr_title": "Big chicken nutrition pack",
"nutr_brand": "Purina Pro plan",
"nutr_ingredient": "Chicken",
"nutr_weight": 10,
"nutr_price": 400,
"nutr_description": "This is a food for dogs"
}

customer_dictionary = {
"cust_name": "Fedor",
"cust_surname": "Kuprianov",
"cust_login": "fedyakup",
"cust_pass": "poc123poc",
"cust_email": "fedya_kup@gmail.com",
"cust_adress": "Volgogradska str."
}


@app.route('/')
def main():
return 'Priv che delaesh'



@app.route('/api/<action>', methods=['GET'])
def apiget(action):
if action == "nutrition":
return render_template('nutrition.html', nutrition=nutrition_dictionary)
elif action == "customer":
return render_template('customer.html', customer=customer_dictionary)
elif action == "all":
return render_template('all.html', nutrition=nutrition_dictionary, customer=customer_dictionary)
else:
return render_template('404.html', action_value=action)


@app.route('/api/nutrition/submit', methods=['POST'])
def nitrition_submit():
if request.method == "POST":
nutrition_dictionary["Title"] = request.form['title']
nutrition_dictionary["Brand"] = request.form['brand']
nutrition_dictionary["Ingredient"] = request.form['ingredient']
nutrition_dictionary["Weight"] = request.form['weight']
nutrition_dictionary["Price"] = request.form['price']
nutrition_dictionary["Short description"] = request.form['descr']
return render_template("all.html", nutrition=nutrition_dictionary, customer=customer_dictionary)
else:
return render_template("nutrition.html", nutrition=nutrition_dictionary)


@app.route('/api/customer/submit', methods=['POST'])
def customer_submit():
if request.method == "POST":
customer_dictionary["Name"] = request.form['name']
customer_dictionary["Surname"] = request.form['surname']
customer_dictionary["Login"] = request.form['login']
customer_dictionary["Password"] = request.form['pass']
customer_dictionary["E-mail"] = request.form['email']
customer_dictionary["Adress"] = request.form['adress']
return render_template("all.html", nutrition=nutrition_dictionary, customer=customer_dictionary)
else:
return render_template("customer.html", customer=customer_dictionary)



if __name__ == "__main__":
app.run(debug=True)
7 changes: 7 additions & 0 deletions Workshop3/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
click==7.1.2
Flask==1.1.2
itsdangerous==1.1.0
Jinja2==2.11.2
MarkupSafe==1.1.1
Werkzeug==1.0.1
gunicorn == 20.0.4
1 change: 1 addition & 0 deletions Workshop3/runtime.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
python-3.8.2
11 changes: 11 additions & 0 deletions Workshop4/source/connection.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from sqlalchemy.engine import create_engine

username = 'user'
password = '1234'
sid = 'XE'
host = 'localhost'
port = '1521'


oracle_connection_path = 'oracle+cx_oracle://{username}:{password}@{host}:{port}/{sid}'
engine = create_engine(oracle_connection_path)
120 changes: 120 additions & 0 deletions Workshop4/source/workshop4.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
from sqlalchemy import Integer, String, Column, MetaData, Float, DateTime, ForeignKey, CheckConstraint
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy_utils import EmailType
from database_connection import engine
from sqlalchemy.orm import sessionmaker
from sqlalchemy.orm import relationship
import re
Base = declarative_base()
meta = MetaData()


class nutrition(Base):
__tablename__ = 'nutrition'
nutr_title = Column(String(100), primary_key=True, nullable=False)
nutr_brand = Column(String(40), primary_key=True, nullable=False)
nutr_price = Column(Float, primary_key=True, nullable=False)
nutr_weight = Column(Float, primary_key=True, nullable=False)
nutr_ingredient = Column(String(30), primary_key=True, nullable=False)
nutr_description = Column(String(500), nullable=False)
CheckConstraint('price > 0', name='check_price')
CheckConstraint('weight > 0', name='check_weight')



@classmethod
def add(cls, nutr_title, nutr_brand, nutr_price, nutr_weight, nutr_ingredient, nutr_description):
if not nutr_title.isalpha() or not nutr_brand.isalpha() or not nutr_ingredient.isalpha() or not nutr_description.isalpha() \
or not isinstance(nutr_price, float) or not isinstance(nutr_weight, float):
print("Data is not correct!")
return -1
Session = sessionmaker(bind=engine)
session = Session()
Nutrition = nutrition(nutr_title=nutr_title, nutr_brand=nutr_brand, nutr_price=nutr_price, nutr_weight=nutr_weight, nutr_ingredient=nutr_ingredient,
nutr_description=nutr_description)
session.add(Nutrition)
session.commit()

class customer(Base):
__tablename__ = 'customer'

cust_name = Column(String(80), nullable=False)
cust_surname = Column(String(90))
cust_login = Column(String(40), primary_key=True, nullable=False)
cust_password = Column(String(50), nullable=False)
cust_email = Column(EmailType, nullable=False)
cust_adress = Column(String(300), nullable=False)

@classmethod
def add(cls, cust_name, cust_surname, cust_login, cust_password, cust_email, cust_adress):
if not cust_name.isalpha() or not cust_surname.isalpha() or not cust_login.isalpha() or not cust_password.isalpha() \
or not cust_adress.isalpha() or not re.match(r"[^@]+@[^@]+\.[^@]+", cust_email):
print("Data is not correct!")
return -1
Session = sessionmaker(bind=engine)
session = Session()
Customer1 = customer(cust_name=cust_name, cust_surname=cust_surname, cust_login=cust_login, cust_password=cust_password,
cust_email=cust_email, cust_adress=cust_adress)
session.add(Customer1)
session.commit()


class review(Base):
__tablename__ = 'review'
nutr_title = Column(String(100), ForeignKey('nutrition.nutr_title'), primary_key=True, nullable=False)
nutr_brand = Column(String(40), ForeignKey('nutrition.nutr_brand'), primary_key=True, nullable=False)
nutr_price_fk = Column(Float, ForeignKey('nutrition.nutr_price'))
nutr_ingredient_fk = Column(String(30), ForeignKey('nutrition.nutr_ingredient'))
reviews = Column(String(600), nullable=False)
rating = Column(Integer, nullable=False)
CheckConstraint('nutr_price_fk >= 0', name='check_nutr_price_fk')
CheckConstraint('rating >= 0', name='check_rating')
nutritions = relationship("nutrition", foreign_keys=[nutr_title])
nutritions_brand = relationship("nutrition", foreign_keys=[nutr_brand])
nutritions_price = relationship("nutrition", foreign_keys=[nutr_price_fk])
nutritions_ingredient = relationship("nutrition", foreign_keys=[nutr_ingredient_fk])

@classmethod
def add(cls, nutr_title, nutr_brand, nutr_price_fk, nutr_ingredient_fk, reviews, rating):
if not nutr_title.isalpha() or not nutr_brand.isalpha() \
or not isinstance(nutr_price_fk, float) or not nutr_ingredient_fk.isalpha() or not reviews.isalpha() \
or not isinstance(rating, int):
print("Data is not correct!")
return -1
Session = sessionmaker(bind=engine)
session = Session()
review1 = review(nutr_title=nutr_title, nutr_brand=nutr_brand, nutr_price_fk=nutr_price_fk,
nutr_ingredient_fk=nutr_ingredient_fk, reviews=reviews, rating=rating)
session.add(review1)
session.commit()


class cust_order(Base):
__tablename__ = 'cust_order'

nutr_title = Column(String(100), ForeignKey('nutrition.nutr_title'), primary_key=True, nullable=False)
nutr_brand = Column(String(40), ForeignKey('nutrition.nutr_brand'), primary_key=True, nullable=False)
nutr_price = Column(Float, ForeignKey('nutrition.nutr_price'))
nutr_ingredient_fk = Column(String(30), ForeignKey('nutrition.genre'), nullable=False)
status = Column(String(25), nullable=False)
CheckConstraint('price >= 0', name='check_price')
nutritions = relationship("nutrition", foreign_keys=[nutr_title])
nutritions_brand = relationship("nutrition", foreign_keys=[nutr_brand])
nutritions_price = relationship("nutrition", foreign_keys=[nutr_price])
nutritions_ingredient = relationship("nutrition", foreign_keys=[nutr_ingredient_fk])

@classmethod
def add(cls, nutr_title, nutr_brand, nutr_price, nutr_ingredient_fk, status):
if not nutr_title.isalpha() or not nutr_brand.isalpha() \
or not isinstance(nutr_price, float) or not nutr_brand.isalpha() or not status.isalpha():
print("Data is not correct!")
return -1
Session = sessionmaker(bind=engine)
session = Session()
cust_order1 = cust_order(nutr_title=nutr_title, nutr_brand=nutr_brand, nutr_price=nutr_price, nutr_ingredient_fk=nutr_ingredient_fk,
status=status)
session.add(cust_order1)
session.commit()


Base.metadata.create_all(engine)
46 changes: 46 additions & 0 deletions Workshop4/sql/add_tables.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
create table nutrition(
nutr_title VARCHAR2(100),
nutr_brand VARCHAR2(40),
nutr_price NUMBER(8, 2),
nutr_weight NUMBER(6, 2),
nutr_ingredient VARCHAR2(30),
nutr_description VARCHAR2(500) NOT NULL,
CONSTRAINT nutr_constraint PRIMARY KEY (nutr_title, nutr_brand, nutr_price, nutr_ingredient),
CONSTRAINT check_nutr_price CHECK (nutr_price >= 0),
CONSTRAINT check_nutr_weight CHECK (nutr_weight >= 0),
);

create table customer(
cust_name VARCHAR2(80) NOT NULL,
cust_surname VARCHAR2(90),
cust_login VARCHAR2(40) NOT NULL PRIMARY KEY,
cust_password VARCHAR2(50) NOT NULL,
cust_email VARCHAR2(50) NOT NULL UNIQUE,
cust_adress VARCHAR2(300) NOT NULL
CONSTRAINT cust_email_check CHECK (REGEXP_LIKE (cust_email, '^(\S+)\@(\S+)\.(\S+)$'))
);

create table review(
nutr_title VARCHAR2(100) NOT NULL,
nutr_brand VARCHAR2(40) NOT NULL,
nutr_price_fk NUMBER(8, 2),
nutr_ingredient_fk VARCHAR2(30),
reviews VARCHAR2(600) NOT NULL,
rating INTEGER NOT NULL,
CONSTRAINT review_constraint PRIMARY KEY (nutr_title, nutr_brand),
CONSTRAINT check_review_nutr_price CHECK (nutr_price_fk >= 0),
CONSTRAINT rating CHECK (rating > 0 and rating <= 10)
);


create table cust_order(
nutr_title VARCHAR2(100) NOT NULL,
nutr_brand VARCHAR2(40) NOT NULL,
nutr_price NUMBER(8, 2) NOT NULL,
nutr_ingredient_fk VARCHAR2(30),
status VARCHAR2(25) NOT NULL,
CONSTRAINT order_constraint PRIMARY KEY (nutr_title, nutr_brand),
CONSTRAINT check_order_nutr_price CHECK (nutr_price >= 0)
);


Loading