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 Burova Nastia, KM-72
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

125 changes: 125 additions & 0 deletions Workshop4/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
import uuid
from sqlalchemy import create_engine, ForeignKey
from sqlalchemy import Column, Integer, String
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import relationship, backref, sessionmaker

oracle_connection_string = 'oracle+cx_oracle://{username}:{password}@{host}:{port}/{sid}'

engine = create_engine(
oracle_connection_string.format(

username="OUTLN",
password="1234",
sid="orcl",
host="localhost",
port="1521",
database="orcl",

)
, echo=True
)
Session = sessionmaker(bind=engine)

Base = declarative_base()
session = Session(autocommit=True,autoflush=True)


class Insurer(Base):
__tablename__ = 'insurer_log'

id = Column(String(100), primary_key=True)
insurer_name = Column(String(50))
insurer_password = Column(Integer)
insurer_email = Column(String(50))
styles = relationship('Personalinfo', backref = backref('insurer_log'), lazy=True)


def __init__(self, insurer_name, insurer_password, insurer_email):
self.insurer_name = insurer_name
self.insurer_password = insurer_password
self.insurer_email = insurer_email
self.id = str(uuid.uuid4())

def get_id(self):
return self.id



class Personalinfo(Base):
__tablename__ = 'personal_info'

id = Column(String(100), primary_key=True)
id_person = Column(String(100), ForeignKey("insurer_log.id"))
person_firststname = Column(String(50))
person_lastname = Column(String(50))
person_age = Column(Integer)
person_passport = Column(Integer)
person_itin = Column(Integer)
person_cityzenship = Column(String(50))

def __init__(self, person_firststname, person_lastname, person_age, person_passport, person_itin, person_cityzenship):
self.id = str(uuid.uuid4())
self.id_person = Insurer.get_id()
self.person_firststname = person_firststname
self.person_lastname = person_lastname
self.person_age= person_age
self.person_passport = person_passport
self.person_itin = person_itin
self.person_cityzenship = person_cityzenship

def check_age_value(id, age, values, person_id):
if age > 70 and age < 1:
print('Unacceptable age')
else:
row = Personalinfo(id=id, person_age=values, id_person=person_id)
session.add(row)
session.commit()

def check_cityzenship(id, country, values, person_id):
if country != 'Ukraine':
print('only for citizens of Ukraine ')
else:
l = Personalinfo(id=id, person_cityzenship=values, id_person=person_id)
session.add(l)
session.commit()





class Policy(Base):
__tablename__ = 'policy_type'

id = Column(String(100), ForeignKey('insurer_log.id'), primary_key=True)
policy = Column(String(50), default="basic", primary_key=True)
policies = ['basic', 'business', 'sport', 'active']

def __init__(self, Insurer):
self.id = Insurer.get_id()

def add_policy(self, policy):
if policy in self.policies:
self.policy = policy

def check_policy(self, Insurer, policy):
policies = session.query(Policy).filter_by(id=Insurer.get_id()).all()
return any(i.policy == policy for i in policies)



Base.metadata.create_all(engine)


a = Insurer("Liza", 123, "liza@gmail.com")
session.add(a)
session.flush()

#b = Personalinfo(person_firststname='Elizabeth', person_lastname='Komarova', person_age = 19, person_passport = 234467, person_itin = 3334444, person_cityzenship = 'Ukraine', insurer_log=a)
#session.add(b)
#session.flush()

#session.add(Policy(b.get_id(), ['basic']))
#.commit()
#session.flush()
#session.close()
Binary file added workshop3/WorkShop 2 Flask.pdf
Binary file not shown.
64 changes: 64 additions & 0 deletions workshop3/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
from flask import Flask, render_template, request, redirect, url_for

app = Flask(__name__)


@app.route('/api/<action>', methods=['GET'])
def apiget(action):
if action == "info":
return render_template("insured_person_info.html", info=a_insured)
elif action == "insurer":
return render_template("insurer.html", insurer=a_insurer)

elif action == "all":
return render_template("all.html", info=a_insured, insurer=a_insurer)

else:
return render_template("404.html", info=a_insured, insurer=a_insurer, action_value=action)

@app.route('/api/', methods=['POST'])
def apipost(action):
if request.form["action"] == 'info_update':
a_insured["person_id"] = request.form["id"]
a_insured["person_firststname"] = request.form["firststname"]
a_insured["person_lastname"] = request.form["lastname"]
a_insured["person_d_birth"] = request.form["d_birth"]
a_insured["person_passport"] = request.form["passport"]
a_insured["person_itin"] = request.form["itin"]
a_insured["user_cityzenship"] = request.form["cityzenship"]

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

if request.form["action"] == 'insurer_update':
a_insurer["insurer_id"] = request.form["id"]
a_insurer["insurer_name"] = request.form["name"]
a_insurer["insurer_password"] = request.form["password"]
a_insurer["insurer_email"] = request.form["email"]


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


if __name__ == '__main__':

a_insured = {
"person_id": 1,
"person_firstname": "Elena",
"person_lastname": "Komarova",
"person_d_birth": 16072000,
"person_passport": 433444,
"person_itin": 23344455,
"person_cityzenship": "Ukraine",

}

a_insurer= {
"insurer_id": 1,
"insurer_name": "Lena",
"insurer_password": 1234,
"insurer_email": "lena@gmail.com",


}

app.run(debug=True)
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> Not correct action value: {{action_value}} </h2>
</body>
</html>
47 changes: 47 additions & 0 deletions workshop3/templates/all.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>all</title>
</head>
<body>
<table>
<tr>
<th>person_id</th>
<th>person_firstname</th>
<th>person_person_lastname</th>
<th>person_d_birth</th>
<th>person_passport</th>
<th>person_itin</th>
<th>person_cityzenship</th>


</tr>
<tr>
<td>{{info.get("person_id")}}</td>
<td>{{info.get("person_firstname")}}</td>
<td>{{info.get("person_lastname")}}</td>
<td>{{info.get("person_d_birth")}}</td>
<td>{{info.get("person_passport")}}</td>
<td>{{info.get("person_itin")}}</td>
<td>{{info.get("person_cityzenship")}}</td>
</tr>
</table>
<br/>
<table>
<tr>
<th>insurer_id</th>
<th>insurer_name</th>
<th>insurer_password</th>
<th>insurer_email</th>
</tr>
<tr>
<td>{{insurer.get("insurer_id")}}</td>
<td>{{insurer.get("insurer_name")}}</td>
<td>{{insurer.get("insurer_password")}}</td>
<td>{{insurer.get("insurer_email")}}</td>

</tr>
</table>
</body>
</html>
17 changes: 17 additions & 0 deletions workshop3/templates/insured_person_info.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Personal information</title>
</head>
<body>
<form action="/api" method="Post" id="person_id">
<p>Firstname: <input type = "text" name = "firstname" value="{{info.get('person_firstname')}}"/> </p>
<p>Lastname: <input type = "text" name = "lastname" value="{{info.get('person_lastname')}}"/> </p>
<p>Date of birth: <input type = "text" name = "d_birth" value="{{info.get('person_d_birth')}}"/> </p>
<p>Passport id: <input type = "text" name = "passport" value="{{info.get('person_passport')}}"/> </p>
<p>ITIN: <input type = "text" name = "itin" value="{{info.get('person_itin')}}"/> </p>
<p>Cityzenship: <input type = "text" name = "cityzenship" value="{{info.get('person_cityzenship')}}"/> </p>
<button type="submit" form="personal_info" name="action" value="user_update">Submit</button>
</body>
</html>
16 changes: 16 additions & 0 deletions workshop3/templates/insurer.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>Login form</title>
</head>
<body>
<form action="/api" method="Post" id="insurer_id">
<p>Name: <input type = "text" name = "name" value="{{insurer.get('insurer_name')}}"/> </p>
<p>Password: <input type = "text" name = "password" value="{{insurer.get('isurer_password')}}"/> </p>
<p>Email: <input type = "text" name = "email" value="{{insurer.get('isurer_email')}}"/> </p>

</form>
<button type="submit" form="insurer_form" name="action" value="insurer_update">Submit</button>
</body>
</html>