Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
c22021052_cmt120_cw2
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
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
Ying Tung Lau
c22021052_cmt120_cw2
Commits
2f22143e
Commit
2f22143e
authored
2 years ago
by
Ying Tung Lau
Browse files
Options
Downloads
Patches
Plain Diff
Upload New File
parent
7238596e
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
portfolio/__init__.py
+128
-0
128 additions, 0 deletions
portfolio/__init__.py
with
128 additions
and
0 deletions
portfolio/__init__.py
0 → 100644
+
128
−
0
View file @
2f22143e
from
flask
import
Flask
,
render_template
,
request
,
redirect
,
flash
,
url_for
from
flask_sqlalchemy
import
SQLAlchemy
from
flask_wtf
import
FlaskForm
from
wtforms
import
StringField
,
SubmitField
,
RadioField
from
wtforms.validators
import
DataRequired
from
datetime
import
datetime
import
os
app
=
Flask
(
__name__
)
basedir
=
os
.
path
.
abspath
(
os
.
path
.
dirname
(
__file__
))
app
.
config
[
'
SQLALCHEMY_DATABASE_URI
'
]
=
'
sqlite:///
'
+
os
.
path
.
join
(
basedir
,
'
cw2.db
'
)
app
.
config
[
'
SECRET_KEY
'
]
=
'
(34879*&378^83hehj3349837rjkhekjfn)
'
app
.
config
[
'
SRF_ENABLED
'
]
=
True
app
.
config
[
'
SQLALCHEMY_TRACK_MODIFICATIONS
'
]
=
True
db
=
SQLAlchemy
(
app
)
class
CommentForm
(
FlaskForm
):
name
=
StringField
(
'
Name
'
,
validators
=
[
DataRequired
()])
comment
=
StringField
(
'
Comment
'
,
validators
=
[
DataRequired
()])
submit
=
SubmitField
(
'
Post Comment
'
)
class
PasswordForm
(
FlaskForm
):
password
=
StringField
(
'
Name
'
,
validators
=
[
DataRequired
()])
submit
=
SubmitField
(
'
Submit Password
'
)
class
FilterForm
(
FlaskForm
):
option
=
RadioField
(
"
Label
"
,
choices
=
[(
'
asc
'
,
'
Ascending
'
),(
'
desc
'
,
'
Descending
'
)])
submit
=
SubmitField
(
"
Filter
"
)
class
Comment
(
db
.
Model
):
id
=
db
.
Column
(
db
.
Integer
,
primary_key
=
True
)
date
=
db
.
Column
(
db
.
DateTime
,
nullable
=
False
,
default
=
datetime
.
utcnow
)
name
=
db
.
Column
(
db
.
String
,
nullable
=
False
)
comment
=
db
.
Column
(
db
.
Text
,
nullable
=
False
)
class
Password
(
db
.
Model
):
id
=
db
.
Column
(
db
.
Integer
,
primary_key
=
True
)
date
=
db
.
Column
(
db
.
DateTime
,
nullable
=
False
,
default
=
datetime
.
utcnow
)
password
=
db
.
Column
(
db
.
String
,
nullable
=
False
)
class
Project
(
db
.
Model
):
id
=
db
.
Column
(
db
.
Integer
,
primary_key
=
True
)
year
=
db
.
Column
(
db
.
String
,
nullable
=
False
)
project_category
=
db
.
Column
(
db
.
String
,
nullable
=
False
)
project_name
=
db
.
Column
(
db
.
String
,
nullable
=
False
)
project_description
=
db
.
Column
(
db
.
String
,
nullable
=
False
)
def
__repr__
(
self
):
return
f
"
Comment(
'
{
self
.
name
}
'
,
'
{
self
.
comment
}
'
)
"
@app.route
(
"
/
"
)
@app.route
(
"
/index
"
)
def
index
():
password
=
PasswordForm
()
return
render_template
(
'
index.html
'
,
title
=
'
Index
'
,
form
=
password
)
@app.route
(
"
/
"
,
methods
=
[
'
GET
'
,
'
POST
'
])
@app.route
(
"
/index
"
,
methods
=
[
'
GET
'
,
'
POST
'
])
def
passwordSubmit
():
password
=
PasswordForm
()
inputPassword
=
password
.
password
.
data
if
(
inputPassword
==
"
admin
"
):
flash
(
'
Welcome!
'
)
return
redirect
(
url_for
(
"
home
"
))
else
:
flash
(
'
Wrong password
'
)
return
redirect
(
url_for
(
"
index
"
))
@app.route
(
"
/home
"
)
def
home
():
return
render_template
(
'
home.html
'
,
title
=
'
Home
'
)
@app.route
(
"
/about
"
)
def
about
():
projects
=
Project
.
query
.
all
()
return
render_template
(
'
about.html
'
,
title
=
'
About
'
,
projects
=
projects
)
@app.route
(
"
/about
"
,
methods
=
[
'
GET
'
,
'
POST
'
])
def
about_project
():
year
=
request
.
form
.
get
(
'
year
'
)
category
=
request
.
form
.
get
(
'
category
'
)
projects
=
Project
.
query
if
year
:
projects
=
projects
.
filter
(
Project
.
year
==
year
)
if
category
:
projects
=
projects
.
filter
(
Project
.
project_category
==
category
)
return
render_template
(
'
about.html
'
,
projects
=
projects
)
@app.route
(
"
/comment
"
)
def
comment
():
comment
=
CommentForm
()
filter
=
FilterForm
()
recentcomments
=
Comment
.
query
.
order_by
(
Comment
.
date
.
desc
()).
all
()
return
render_template
(
'
comment.html
'
,
title
=
'
Comment
'
,
comment
=
comment
,
recentcomments
=
recentcomments
,
filter
=
filter
)
@app.route
(
"
/comment
"
,
methods
=
[
'
GET
'
,
'
POST
'
])
def
commentposted
():
print
(
'
test
'
)
comment
=
CommentForm
()
name
=
comment
.
name
.
data
iscomment
=
comment
.
comment
.
data
new_comment
=
Comment
()
new_comment
.
name
=
name
new_comment
.
comment
=
iscomment
db
.
session
.
add
(
new_comment
)
db
.
session
.
commit
()
flash
(
'
Comment posted!
'
)
return
redirect
(
url_for
(
'
comment
'
))
@app.route
(
"
/comment_filter
"
,
methods
=
[
'
GET
'
,
'
POST
'
])
def
comment_order
():
comment
=
CommentForm
()
filter
=
FilterForm
()
order
=
filter
.
option
.
data
if
order
==
"
asc
"
:
recentcomments
=
Comment
.
query
.
order_by
(
Comment
.
date
).
all
()
elif
order
==
"
desc
"
:
recentcomments
=
Comment
.
query
.
order_by
(
Comment
.
date
.
desc
()).
all
()
else
:
recentcomments
=
Comment
.
query
.
order_by
(
Comment
.
date
.
desc
()).
all
()
return
render_template
(
'
comment.html
'
,
title
=
'
Comment
'
,
filter
=
filter
,
comment
=
comment
,
recentcomments
=
recentcomments
)
with
app
.
app_context
():
db
.
create_all
()
\ No newline at end of file
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