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

Merge branch 'master' into 'main'

changed back to original

See merge request !18
parents 8f31fa8b 975a4490
No related branches found
No related tags found
1 merge request!18changed back to original
......@@ -2,9 +2,7 @@ import os
import secrets
from flask import Flask, render_template, request, redirect, url_for, send_from_directory, abort
from flask_sqlalchemy import SQLAlchemy
from flask_wtf import FlaskForm
from wtforms import StringField, TextAreaField, SubmitField
from wtforms.validators import DataRequired
from models import db, Project
app = Flask(__name__, static_folder='static')
app.config['SEND_FILE_MAX_AGE_DEFAULT'] = 0
......@@ -12,17 +10,11 @@ app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///' + os.path.abspath(os.path.j
app.config['SECRET_KEY'] = secrets.token_hex(16)
db = SQLAlchemy(app)
class Project(db.Model):
id = db.Column(db.Integer, primary_key=True)
title = db.Column(db.String(100), 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('/')
def home():
try:
......@@ -54,20 +46,23 @@ def portfolio():
def contact():
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'])
def add_project():
form = ProjectForm()
if form.validate_on_submit():
title = form.title.data
description = form.description.data
if request.method == 'POST':
# Retrieve form data directly from request
title = request.form.get('title')
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)
db.session.add(new_project)
db.session.commit()
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
@app.route('/download_cv')
......@@ -80,15 +75,16 @@ def download_cv():
@app.route('/download_assessment/<filename>')
def download_assessment(filename):
try:
file_path = os.path.join('static', filename)
app.logger.debug(f"Attempting to serve file: {file_path}")
file_path = f'static/{filename}'
print(f"Attempting to serve file: {file_path}")
return send_from_directory('static', filename, as_attachment=True)
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
except Exception as e:
app.logger.error(f"Error serving assessment file: {str(e)}")
abort(500)
print(f"Error serving assessment file: {str(e)}")
app.logger.exception(f"Error serving assessment file: {str(e)}")
abort(500)
if __name__ == '__main__':
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