Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
c21070120_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
Kacper Polczynski
c21070120_cmt120_cw2
Commits
77975300
Commit
77975300
authored
4 months ago
by
Kacper Polczynski
Browse files
Options
Downloads
Patches
Plain Diff
references
parent
f3997117
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
init.py
+12
-4
12 additions, 4 deletions
init.py
static/javascript/add_proj.js
+6
-2
6 additions, 2 deletions
static/javascript/add_proj.js
templates/projects.html
+3
-0
3 additions, 0 deletions
templates/projects.html
with
21 additions
and
6 deletions
init.py
+
12
−
4
View file @
77975300
...
@@ -18,7 +18,10 @@ db = SQLAlchemy(app)
...
@@ -18,7 +18,10 @@ db = SQLAlchemy(app)
login_manager
=
LoginManager
()
login_manager
=
LoginManager
()
login_manager
.
init_app
(
app
)
login_manager
.
init_app
(
app
)
#End of models definition
#Code snippets from:https://www.geeksforgeeks.org/how-to-add-authentication-to-your-app-with-flask-login/
#accessed on 22nd decemeber
#Used base login and register feature to add authentication to the app to allow other features
@login_manager.user_loader
@login_manager.user_loader
def
loader_user
(
user_id
):
def
loader_user
(
user_id
):
return
Users
.
query
.
get
(
user_id
)
return
Users
.
query
.
get
(
user_id
)
...
@@ -52,8 +55,7 @@ class Comments(db.Model):
...
@@ -52,8 +55,7 @@ class Comments(db.Model):
with
app
.
app_context
():
with
app
.
app_context
():
db
.
create_all
()
db
.
create_all
()
#End of models definition
#https://www.geeksforgeeks.org/how-to-add-authentication-to-your-app-with-flask-login/
UPLOAD_FOLDER
=
os
.
path
.
join
(
basedir
,
'
static/uploads
'
)
UPLOAD_FOLDER
=
os
.
path
.
join
(
basedir
,
'
static/uploads
'
)
ALLOWED_EXTENSIONS
=
{
'
png
'
,
'
jpg
'
,
'
jpeg
'
,
'
gif
'
}
ALLOWED_EXTENSIONS
=
{
'
png
'
,
'
jpg
'
,
'
jpeg
'
,
'
gif
'
}
...
@@ -105,6 +107,9 @@ def projects():
...
@@ -105,6 +107,9 @@ def projects():
return
render_template
(
'
projects.html
'
,
projects
=
projects
,
comments
=
comments_dict
)
return
render_template
(
'
projects.html
'
,
projects
=
projects
,
comments
=
comments_dict
)
#Section for uploading photo
#Section for uploading photo
#Code adapted from: https://openjavascript.info/2022/06/08/how-to-upload-a-file-using-the-fetch-api/
# Accessed on 12/12/2024
# This code allowed me to upload a photo file to the server which has been adapted to link to other projects
@app.route
(
'
/upload
'
,
methods
=
[
'
POST
'
])
#Photo upload
@app.route
(
'
/upload
'
,
methods
=
[
'
POST
'
])
#Photo upload
def
upload_photo
():
def
upload_photo
():
if
request
.
method
==
'
POST
'
:
if
request
.
method
==
'
POST
'
:
...
@@ -188,7 +193,10 @@ def register():
...
@@ -188,7 +193,10 @@ def register():
flash
(
'
User registered successfully!
'
,
'
success
'
)
flash
(
'
User registered successfully!
'
,
'
success
'
)
return
redirect
(
url_for
(
'
login
'
))
return
redirect
(
url_for
(
'
login
'
))
return
render_template
(
'
register.html
'
)
return
render_template
(
'
register.html
'
)
#End of models definition
#Code snippets from:https://www.geeksforgeeks.org/how-to-add-authentication-to-your-app-with-flask-login/
#accessed on 22nd decemeber
#Used base login and register feature to add authentication to the app to allow other features
@app.route
(
'
/login
'
,
methods
=
[
"
GET
"
,
"
POST
"
])
@app.route
(
'
/login
'
,
methods
=
[
"
GET
"
,
"
POST
"
])
def
login
():
def
login
():
if
request
.
method
==
"
POST
"
:
if
request
.
method
==
"
POST
"
:
...
...
This diff is collapsed.
Click to expand it.
static/javascript/add_proj.js
+
6
−
2
View file @
77975300
/*code adapted from: https://www.w3schools.com/howto/howto_css_modals.asp*/
/*Accessed on 12/12/2024*/
/*modal pop up allowed me to implement a form to add a project*/
var
modal
=
document
.
getElementById
(
"
myModal
"
);
var
modal
=
document
.
getElementById
(
"
myModal
"
);
var
btn
=
document
.
getElementById
(
"
add-proj-btn
"
);
var
btn
=
document
.
getElementById
(
"
add-proj-btn
"
);
var
span
=
document
.
getElementsByClassName
(
"
close
"
)[
0
];
var
span
=
document
.
getElementsByClassName
(
"
close
"
)[
0
];
...
@@ -37,7 +39,9 @@ form.addEventListener('submit', async (e) => {
...
@@ -37,7 +39,9 @@ form.addEventListener('submit', async (e) => {
const
payload
=
new
FormData
();
const
payload
=
new
FormData
();
payload
.
append
(
"
photo_url
"
,
file
);
payload
.
append
(
"
photo_url
"
,
file
);
/*https://openjavascript.info/2022/06/08/how-to-upload-a-file-using-the-fetch-api/*/
/* Code adapted from: https://openjavascript.info/2022/06/08/how-to-upload-a-file-using-the-fetch-api/ */
/*Accessed on 12/12/2024*/
/*This code allowed me to upload a file to the server*/
try
{
try
{
const
photoupload
=
await
fetch
(
'
/upload
'
,
{
const
photoupload
=
await
fetch
(
'
/upload
'
,
{
method
:
'
POST
'
,
method
:
'
POST
'
,
...
...
This diff is collapsed.
Click to expand it.
templates/projects.html
+
3
−
0
View file @
77975300
...
@@ -32,6 +32,9 @@
...
@@ -32,6 +32,9 @@
</div>
</div>
{% endif %}
{% endif %}
<!-- Pop Up to Add Projects-->
<!-- Pop Up to Add Projects-->
<!--code adapted from: https://www.w3schools.com/howto/howto_css_modals.asp*/
Accessed on 12/12/2024*/
modal pop up allowed me to implement a form to add a project-->
<div
id =
"myModal"
class=
"modal"
>
<div
id =
"myModal"
class=
"modal"
>
<div
class =
"modal-content"
>
<div
class =
"modal-content"
>
<span
class=
"close"
>
×
</span>
<span
class=
"close"
>
×
</span>
...
...
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