diff --git a/init.py b/init.py index 401b512ea3f21c21c4182a907daffece19a73a2f..0a22a8257685e8007c673654de7f234cba441448 100644 --- a/init.py +++ b/init.py @@ -18,7 +18,10 @@ db = SQLAlchemy(app) login_manager = LoginManager() 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 def loader_user(user_id): return Users.query.get(user_id) @@ -52,8 +55,7 @@ class Comments(db.Model): with app.app_context(): 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') ALLOWED_EXTENSIONS = {'png', 'jpg', 'jpeg', 'gif'} @@ -105,6 +107,9 @@ def projects(): return render_template('projects.html' , projects=projects,comments=comments_dict) #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 def upload_photo(): if request.method =='POST': @@ -188,7 +193,10 @@ def register(): flash('User registered successfully!', 'success') return redirect(url_for('login')) 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"]) def login(): if request.method == "POST": diff --git a/static/javascript/add_proj.js b/static/javascript/add_proj.js index f61dc0a2a691385cdefaedd4125ae9a5a4ab4389..d35377b43cee8b1d697b36ed25b164e247c638c0 100644 --- a/static/javascript/add_proj.js +++ b/static/javascript/add_proj.js @@ -1,4 +1,6 @@ - +/*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 btn = document.getElementById("add-proj-btn"); var span = document.getElementsByClassName("close")[0]; @@ -37,7 +39,9 @@ form.addEventListener('submit', async (e) => { const payload = new FormData(); 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 { const photoupload = await fetch('/upload', { method : 'POST', diff --git a/templates/projects.html b/templates/projects.html index f9a9fe16e95f5fb243871455885b79f945e7487b..a40b482dbfd640477321dc01f3840e0c36a4bdf1 100644 --- a/templates/projects.html +++ b/templates/projects.html @@ -32,6 +32,9 @@ </div> {% endif %} <!-- 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 class = "modal-content"> <span class="close">×</span>