Skip to content

Commit cc12f19

Browse files
author
Muhammad Shafaf
committed
update
1 parent c130a8e commit cc12f19

5 files changed

Lines changed: 49 additions & 5 deletions

File tree

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
env
2+
__pycache__/
3+
.env
4+
migrations/

app.py

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
from flask_sqlalchemy import SQLAlchemy
33
from flask_migrate import Migrate
44
from werkzeug.security import generate_password_hash, check_password_hash
5+
from sqlalchemy_utils import UUIDType
56
import os
7+
import uuid
68

79
# SQLAlchemy.
810
pg_user = os.getenv("POSTGRES_USER", "postgres")
@@ -24,15 +26,35 @@
2426
db = SQLAlchemy(app)
2527
migrate = Migrate(app, db)
2628

29+
# Base model class for all models
30+
class BaseModel(db.Model):
31+
"""
32+
Base model of the mapping class inheritace
33+
34+
https://docs.sqlalchemy.org/en/14/orm/inheritance.html
35+
"""
36+
37+
__abstract__ = True
38+
39+
STATUS_CHOICES = ["Active", "Disabled", "Deleted"]
40+
41+
id = db.Column(UUIDType(binary=False), primary_key=True, default=uuid.uuid4)
42+
name = db.Column(db.String(255), nullable=False)
43+
extra = db.Column(db.JSON(), nullable=True)
44+
status = db.Column(
45+
db.Enum(*STATUS_CHOICES, name="status", native_enum=False),
46+
nullable=False,
47+
default="active"
48+
)
2749

2850
# User Model
29-
class User(db.Model):
51+
class User(BaseModel):
3052
id = db.Column(db.Integer, primary_key=True)
3153
username = db.Column(db.String(80), unique=True, nullable=False)
3254
password = db.Column(db.String(520), nullable=False)
3355

3456

35-
class Student(db.Model):
57+
class Student(BaseModel):
3658
id = db.Column(db.Integer, primary_key=True)
3759
student_name = db.Column(db.String(200), nullable=False)
3860
student_age = db.Column(db.Integer, nullable=True)
@@ -78,7 +100,8 @@ def register():
78100
# create a new user
79101
new_user = User(
80102
username=username,
81-
password=generate_password_hash(password),
103+
password=password,
104+
name=username,
82105
)
83106
db.session.add(new_user)
84107
db.session.commit()

requirements.txt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
alembic==1.13.1
2+
blinker==1.7.0
3+
click==8.1.7
4+
Flask==3.0.2
5+
Flask-Migrate==4.0.5
6+
Flask-SQLAlchemy==3.1.1
7+
importlib-metadata==7.0.1
8+
itsdangerous==2.1.2
9+
Jinja2==3.1.3
10+
Mako==1.3.2
11+
MarkupSafe==2.1.5
12+
psycopg2==2.9.9
13+
SQLAlchemy==2.0.25
14+
SQLAlchemy-Utils==0.41.1
15+
typing_extensions==4.9.0
16+
Werkzeug==3.0.1
17+
zipp==3.17.0

templates/login.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<meta name="viewport" content="width=device-width, initial-scale=1.0">
77
<title>Login</title>
88
</head>
9-
<body>
9+
<body style="background: black; color: aliceblue;">
1010
<h2>Login</h2>
1111
{% with messages = get_flashed_messages() %}
1212
{% if messages %}

templates/register.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<meta name="viewport" content="width=device-width, initial-scale=1.0">
77
<title>Register</title>
88
</head>
9-
<body>
9+
<body style="background: black; color: aliceblue;">
1010
<h2>Register</h2>
1111
{% with messages = get_flashed_messages() %}
1212
{% if messages %}

0 commit comments

Comments
 (0)