Skip to content
Snippets Groups Projects
Commit 975a4490 authored by Felix Chadwick-Smith's avatar Felix Chadwick-Smith
Browse files

changed back to original

parent 940312f9
No related branches found
No related tags found
1 merge request!18changed back to original
...@@ -2,9 +2,7 @@ import os ...@@ -2,9 +2,7 @@ import os
import secrets import secrets
from flask import Flask, render_template, request, redirect, url_for, send_from_directory, abort from flask import Flask, render_template, request, redirect, url_for, send_from_directory, abort
from flask_sqlalchemy import SQLAlchemy from flask_sqlalchemy import SQLAlchemy
from flask_wtf import FlaskForm from models import db, Project
from wtforms import StringField, TextAreaField, SubmitField
from wtforms.validators import DataRequired
app = Flask(__name__, static_folder='static') app = Flask(__name__, static_folder='static')
app.config['SEND_FILE_MAX_AGE_DEFAULT'] = 0 app.config['SEND_FILE_MAX_AGE_DEFAULT'] = 0
...@@ -12,17 +10,11 @@ app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///' + os.path.abspath(os.path.j ...@@ -12,17 +10,11 @@ app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///' + os.path.abspath(os.path.j
app.config['SECRET_KEY'] = secrets.token_hex(16) app.config['SECRET_KEY'] = secrets.token_hex(16)
db = SQLAlchemy(app) db = SQLAlchemy(app)
class Project(db.Model): class Project(db.Model):
id = db.Column(db.Integer, primary_key=True) id = db.Column(db.Integer, primary_key=True)
title = db.Column(db.String(100), nullable=False) title = db.Column(db.String(100), nullable=False)
description = db.Column(db.Text, nullable=False) description = db.Column(db.Text, nullable=False)
class ProjectForm(FlaskForm):
title = StringField('Title', validators=[DataRequired()])
description = TextAreaField('Description', validators=[DataRequired()])
submit = SubmitField('Submit')
@app.route('/') @app.route('/')
def home(): def home():
try: try:
...@@ -54,20 +46,23 @@ def portfolio(): ...@@ -54,20 +46,23 @@ def portfolio():
def contact(): def contact():
return render_template('contact.html') return render_template('contact.html')
# Updated route for adding a project with Flask-WTF form # Updated route for adding a project without Flask-WTF form
@app.route('/add_project', methods=['GET', 'POST']) @app.route('/add_project', methods=['GET', 'POST'])
def add_project(): def add_project():
form = ProjectForm() if request.method == 'POST':
if form.validate_on_submit(): # Retrieve form data directly from request
title = form.title.data title = request.form.get('title')
description = form.description.data description = request.form.get('description')
# Print or log the form data to check if it's received
print(f"Received form data - Title: {title}, Description: {description}")
new_project = Project(title=title, description=description) new_project = Project(title=title, description=description)
db.session.add(new_project) db.session.add(new_project)
db.session.commit() db.session.commit()
return redirect(url_for('home')) return redirect(url_for('home'))
return render_template('add_project.html', form=form) return render_template('add_project.html')
# Updated route for serving the 'my-cv.docx' file # Updated route for serving the 'my-cv.docx' file
@app.route('/download_cv') @app.route('/download_cv')
...@@ -80,15 +75,16 @@ def download_cv(): ...@@ -80,15 +75,16 @@ def download_cv():
@app.route('/download_assessment/<filename>') @app.route('/download_assessment/<filename>')
def download_assessment(filename): def download_assessment(filename):
try: try:
file_path = os.path.join('static', filename) file_path = f'static/{filename}'
app.logger.debug(f"Attempting to serve file: {file_path}") print(f"Attempting to serve file: {file_path}")
return send_from_directory('static', filename, as_attachment=True) return send_from_directory('static', filename, as_attachment=True)
except FileNotFoundError: except FileNotFoundError:
app.logger.error(f"File not found: {file_path}") print(f"File not found: {file_path}")
abort(404) # Return a 404 Not Found error abort(404) # Return a 404 Not Found error
except Exception as e: except Exception as e:
app.logger.error(f"Error serving assessment file: {str(e)}") print(f"Error serving assessment file: {str(e)}")
abort(500) app.logger.exception(f"Error serving assessment file: {str(e)}")
abort(500)
if __name__ == '__main__': if __name__ == '__main__':
with app.app_context(): with app.app_context():
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment