Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
mellamocarloss
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Valencia Vargas, Carlos
mellamocarloss
Commits
a62db460
Commit
a62db460
authored
3 years ago
by
Michael Kyriakou
Browse files
Options
Downloads
Patches
Plain Diff
Refactored adding "Person" and getting all persons.
parent
69cd22c9
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
app.py
+0
-17
0 additions, 17 deletions
app.py
blueprints/home.py
+5
-9
5 additions, 9 deletions
blueprints/home.py
models/first_db_models/person.py
+11
-1
11 additions, 1 deletion
models/first_db_models/person.py
with
16 additions
and
27 deletions
app.py
+
0
−
17
View file @
a62db460
...
...
@@ -92,23 +92,6 @@ def serve_static_files(path):
return
send_from_directory
(
'
static
'
,
path
)
# @app.route('/test-db')
# def test_db():
# try:
# rows = ""
# for user in db.session.query(User).all():
# rows += str(user) + " "
# for e in db.session.query(Entity).all():
# rows += str(e) + " "
# print("All rows:", rows)
# return rows
# except:
# return "App database error"
# Force secure connection
@app.before_request
def
before_request
():
...
...
This diff is collapsed.
Click to expand it.
blueprints/home.py
+
5
−
9
View file @
a62db460
from
flask
import
Blueprint
,
render_template
,
request
,
redirect
from
config
import
url_for2
,
FIRST_DB_BIND_NAME
from
database.db
import
lookup_db_for_binding
from
config
import
url_for2
from
models
import
Person
db
=
lookup_db_for_binding
(
FIRST_DB_BIND_NAME
)
home_blueprint
=
Blueprint
(
'
home
'
,
__name__
,
url_prefix
=
'
/
'
)
...
...
@@ -25,19 +22,18 @@ def persons():
if
request
.
method
==
"
GET
"
:
try
:
rows
=
""
for
e
in
db
.
session
.
query
(
Person
)
.
all
():
for
e
in
Person
.
get_
all
():
rows
+=
str
(
e
)
+
"
<br>
"
return
rows
except
:
return
"
App database error
"
except
Exception
as
e
:
return
f
"
App database error
:
{
e
}
"
else
:
firstname
=
request
.
form
.
get
(
'
firstname
'
)
age
=
request
.
form
.
get
(
'
age
'
)
try
:
db
.
session
.
add
(
Person
(
firstname
=
firstname
,
age
=
int
(
age
)))
db
.
session
.
commit
()
Person
.
add
(
firstname
,
int
(
age
))
return
redirect
(
url_for2
(
'
.persons
'
))
except
Exception
as
e
:
return
f
"
Could not add entity:
{
e
}
"
This diff is collapsed.
Click to expand it.
models/first_db_models/person.py
+
11
−
1
View file @
a62db460
...
...
@@ -15,5 +15,15 @@ class Person(db.Model):
age
=
db
.
Column
(
db
.
Integer
,
unique
=
False
,
nullable
=
False
)
# surname = db.Column(db.String(40))
@classmethod
def
add
(
cls
,
firstname
,
age
):
db
.
session
.
add
(
Person
(
firstname
=
firstname
,
age
=
int
(
age
)))
db
.
session
.
commit
()
@classmethod
def
get_all
(
cls
):
return
cls
.
query
.
all
()
def
__repr__
(
self
):
return
f
'
Person(
{
self
.
id
}
,
{
self
.
firstname
}
,
{
self
.
surname
}
,
{
self
.
age
}
)
'
# The string representation of this object
return
f
'
Person(
{
self
.
id
}
,
{
self
.
firstname
}
,
{
self
.
age
}
)
'
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment