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

Merge branch 'master' into 'main'

Master

See merge request !5
parents 4944a3e0 94dc5ea5
No related branches found
No related tags found
1 merge request!5Master
Showing
with 206 additions and 17 deletions
Access token
Access token for cmt120_3
SkDKs2q-zBLHzn_bj-fN
6vJqLP1vu_gQW1YyCAFp
old one: TXoj4fY2FNam2Liresky
\ No newline at end of file
File added
File deleted
File added
No preview for this file type
No preview for this file type
......@@ -2,11 +2,14 @@ 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, SubmitField
app = Flask('cmt120_2', static_folder='static')
app = Flask(__name__, static_folder='static')
app.config['SEND_FILE_MAX_AGE_DEFAULT'] = 0
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///site.db'
app.config['SECRET_KEY'] = secrets.token_hex(16)
app.config['WTF_CSRF_ENABLED'] = True
db = SQLAlchemy(app)
......@@ -15,6 +18,11 @@ class Project(db.Model):
title = db.Column(db.String(100), nullable=False)
description = db.Column(db.Text, nullable=False)
class AddProjectForm(FlaskForm):
title = StringField('Title')
description = StringField('Description')
submit = SubmitField('Submit')
@app.route('/')
def home():
try:
......@@ -24,46 +32,52 @@ def home():
print(f"Error fetching projects: {str(e)}")
return render_template('error.html')
# New route for the 'about' page
@app.route('/about')
def about():
return render_template('about.html')
# New route for the Experience page
# New route for the 'experience' page
@app.route('/experience')
def experience():
# Add logic to fetch data related to the Experience section if needed
return render_template('experience.html')
# New route for the Portfolio page
# New route for the 'portfolio' page
@app.route('/portfolio')
def portfolio():
# Add logic to fetch data related to the Portfolio section if needed
return render_template('portfolio.html')
# New route for the contact page
# New route for the 'contact' page
@app.route('/contact')
def contact():
return render_template('contact.html')
# New route for adding a project
# Updated route for adding a project with Flask-WTF form
@app.route('/add_project', methods=['GET', 'POST'])
def add_project():
if request.method == 'POST':
title = request.form['title']
description = request.form['description']
new_project = Project(title=title, description=description)
form = AddProjectForm()
if form.validate_on_submit():
# Print or log the form data to check if it's received
print(f"Received form data - Title: {form.title.data}, Description: {form.description.data}")
new_project = Project(title=form.title.data, description=form.description.data)
db.session.add(new_project)
db.session.commit()
return redirect(url_for('home'))
return render_template('add_project.html')
# New route for serving the my-cv.docx file
return render_template('add_project.html', form=form)
# Updated route for serving the 'my-cv.docx' file
@app.route('/download_cv')
def download_cv():
file_path = 'static/my-cv.docx'
print(f"Attempting to serve file: {file_path}")
return send_from_directory('static', 'my-cv.docx', as_attachment=True, mimetype='application/docx')
# Updated route for serving assessment files
@app.route('/download_assessment/<filename>')
def download_assessment(filename):
try:
......@@ -79,7 +93,4 @@ def download_assessment(filename):
abort(500)
if __name__ == '__main__':
with app.app_context():
db.create_all()
app.run(debug=True, host='0.0.0.0')
\ No newline at end of file
app.run(debug=True, port=int(os.environ.get('PORT', 5000)))
\ No newline at end of file
# gunicorn_config.py
from waitress import serve
from app import app # Assuming your Flask app instance is named 'app'
serve(app, host='0.0.0.0', port=8080)
No preview for this file type
......@@ -15,6 +15,7 @@
<li><a href="{{ url_for('about') }}">About Me</a></li>
<li><a href="{{ url_for('experience') }}">Experience</a></li>
<li><a href="{{ url_for('portfolio') }}">Portfolio</a></li>
<li><a href="{{ url_for('add_project') }}">Add Project</a></li>
<li><a href="{{ url_for('contact') }}">Contact</a></li>
</ul>
</nav>
......
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Add Project - Personal Portfolio Website</title>
<link rel="stylesheet" href="{{ url_for('static', filename='style.css') }}">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jszip/3.1.5/jszip.min.js"></script>
<script src="https://kit.fontawesome.com/221d185582.js" crossorigin="anonymous"></script>
</head>
<body>
<h2>Add Project</h2>
<form method="POST" action="{{ url_for('add_project') }}">
{{ form.csrf_token }}
<div class="form-group">
{{ form.title.label }}
{{ form.title(class="form-control", placeholder="Enter project title") }}
</div>
<div class="form-group">
{{ form.description.label }}
{{ form.description(class="form-control", placeholder="Enter project description") }}
</div>
<div class="form-group">
{{ form.submit(class="btn btn-primary") }}
</div>
</form>
</body>
</html>
......@@ -69,6 +69,7 @@
<li><a href="{{ url_for('about') }}">About Me</a></li>
<li><a href="{{ url_for('experience') }}">Experience</a></li>
<li><a href="{{ url_for('portfolio') }}">Portfolio</a></li>
<li><a href="{{ url_for('add_project') }}">Add Project</a></li>
<li><a href="{{ url_for('contact') }}">Contact</a></li>
</ul>
</nav>
......
......@@ -23,6 +23,7 @@
<li><a href="{{ url_for('about') }}">About Me</a></li>
<li><a href="{{ url_for('experience') }}">Experience</a></li>
<li><a href="{{ url_for('portfolio') }}">Portfolio</a></li>
<li><a href="{{ url_for('add_project') }}">Add Project</a></li>
<li><a href="{{ url_for('contact') }}">Contact</a></li>
</ul>
</nav>
......
......@@ -32,6 +32,7 @@
<li><a href="{{ url_for('about') }}">About Me</a></li>
<li><a href="{{ url_for('experience') }}">Experience</a></li>
<li><a href="{{ url_for('portfolio') }}">Portfolio</a></li>
<li><a href="{{ url_for('add_project') }}">Add Project</a></li>
<li><a href="{{ url_for('contact') }}">Contact</a></li>
</ul>
</nav>
......
......@@ -28,6 +28,7 @@
<li><a href="{{ url_for('about') }}">About Me</a></li>
<li><a href="{{ url_for('experience') }}">Experience</a></li>
<li><a href="{{ url_for('portfolio') }}">Portfolio</a></li>
<li><a href="{{ url_for('add_project') }}">Add Project</a></li>
<li><a href="{{ url_for('contact') }}">Contact</a></li>
</ul>
</nav>
......
pip
The MIT License (MIT)
Copyright (c) 2013 Miguel Grinberg
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Metadata-Version: 2.1
Name: Flask-Migrate
Version: 4.0.5
Summary: SQLAlchemy database migrations for Flask applications using Alembic.
Home-page: https://github.com/miguelgrinberg/flask-migrate
Author: Miguel Grinberg
Author-email: miguel.grinberg@gmail.com
License: MIT
Project-URL: Bug Tracker, https://github.com/miguelgrinberg/flask-migrate/issues
Classifier: Environment :: Web Environment
Classifier: Intended Audience :: Developers
Classifier: Programming Language :: Python :: 3
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Requires-Python: >=3.6
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: Flask >=0.9
Requires-Dist: Flask-SQLAlchemy >=1.0
Requires-Dist: alembic >=1.9.0
Flask-Migrate
=============
[![Build status](https://github.com/miguelgrinberg/flask-migrate/workflows/build/badge.svg)](https://github.com/miguelgrinberg/flask-migrate/actions)
Flask-Migrate is an extension that handles SQLAlchemy database migrations for Flask applications using Alembic. The database operations are provided as command-line arguments under the `flask db` command.
Installation
------------
Install Flask-Migrate with `pip`:
pip install Flask-Migrate
Example
-------
This is an example application that handles database migrations through Flask-Migrate:
```python
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
from flask_migrate import Migrate
app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///app.db'
db = SQLAlchemy(app)
migrate = Migrate(app, db)
class User(db.Model):
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String(128))
```
With the above application you can create the database or enable migrations if the database already exists with the following command:
$ flask db init
Note that the `FLASK_APP` environment variable must be set according to the Flask documentation for this command to work. This will add a `migrations` folder to your application. The contents of this folder need to be added to version control along with your other source files.
You can then generate an initial migration:
$ flask db migrate
The migration script needs to be reviewed and edited, as Alembic currently does not detect every change you make to your models. In particular, Alembic is currently unable to detect indexes. Once finalized, the migration script also needs to be added to version control.
Then you can apply the migration to the database:
$ flask db upgrade
Then each time the database models change repeat the `migrate` and `upgrade` commands.
To sync the database in another system just refresh the `migrations` folder from source control and run the `upgrade` command.
To see all the commands that are available run this command:
$ flask db --help
Resources
---------
- [Documentation](http://flask-migrate.readthedocs.io/en/latest/)
- [pypi](https://pypi.python.org/pypi/Flask-Migrate)
- [Change Log](https://github.com/miguelgrinberg/Flask-Migrate/blob/master/CHANGES.md)
Flask_Migrate-4.0.5.dist-info/INSTALLER,sha256=zuuue4knoyJ-UwPPXg8fezS7VCrXJQrAP7zeNuwvFQg,4
Flask_Migrate-4.0.5.dist-info/LICENSE,sha256=kfkXGlJQvKy3Y__6tAJ8ynIp1HQfeROXhL8jZU1d-DI,1082
Flask_Migrate-4.0.5.dist-info/METADATA,sha256=d-EcnhZa_vyVAph2u84OpGIteJaBmqLQxO5Rf6wUI7Y,3095
Flask_Migrate-4.0.5.dist-info/RECORD,,
Flask_Migrate-4.0.5.dist-info/REQUESTED,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
Flask_Migrate-4.0.5.dist-info/WHEEL,sha256=yQN5g4mg4AybRjkgi-9yy4iQEFibGQmlz78Pik5Or-A,92
Flask_Migrate-4.0.5.dist-info/top_level.txt,sha256=jLoPgiMG6oR4ugNteXn3IHskVVIyIXVStZOVq-AWLdU,14
flask_migrate/__init__.py,sha256=-JFdExGtr7UrwCpmjYvTfzFHqMjE7AmP0Rr3T53tBNU,10037
flask_migrate/__pycache__/__init__.cpython-311.pyc,,
flask_migrate/__pycache__/cli.cpython-311.pyc,,
flask_migrate/cli.py,sha256=H-N4NNS5HyEB61HpUADLU8pW3naejyDPgeEbzEqG5-w,10298
flask_migrate/templates/aioflask-multidb/README,sha256=Ek4cJqTaxneVjtkue--BXMlfpfp3MmJRjqoZvnSizww,43
flask_migrate/templates/aioflask-multidb/__pycache__/env.cpython-311.pyc,,
flask_migrate/templates/aioflask-multidb/alembic.ini.mako,sha256=SjYEmJKzz6K8QfuZWtLJAJWcCKOdRbfUhsVlpgv8ock,857
flask_migrate/templates/aioflask-multidb/env.py,sha256=UcjeqkAbyUjTkuQFmCFPG7QOvqhco8-uGp8QEbto0T8,6573
flask_migrate/templates/aioflask-multidb/script.py.mako,sha256=198VPxVEN3NZ3vHcRuCxSoI4XnOYirGWt01qkbPKoJw,1246
flask_migrate/templates/aioflask/README,sha256=KKqWGl4YC2RqdOdq-y6quTDW0b7D_UZNHuM8glM1L-c,44
flask_migrate/templates/aioflask/__pycache__/env.cpython-311.pyc,,
flask_migrate/templates/aioflask/alembic.ini.mako,sha256=SjYEmJKzz6K8QfuZWtLJAJWcCKOdRbfUhsVlpgv8ock,857
flask_migrate/templates/aioflask/env.py,sha256=m6ZtBhdpwuq89vVeLTWmNT-1NfJZqarC_hsquCdR9bw,3478
flask_migrate/templates/aioflask/script.py.mako,sha256=8_xgA-gm_OhehnO7CiIijWgnm00ZlszEHtIHrAYFJl0,494
flask_migrate/templates/flask-multidb/README,sha256=AfiP5foaV2odZxXxuUuSIS6YhkIpR7CsOo2mpuxwHdc,40
flask_migrate/templates/flask-multidb/__pycache__/env.cpython-311.pyc,,
flask_migrate/templates/flask-multidb/alembic.ini.mako,sha256=SjYEmJKzz6K8QfuZWtLJAJWcCKOdRbfUhsVlpgv8ock,857
flask_migrate/templates/flask-multidb/env.py,sha256=F44iqsAxLTVBN_zD8CMUkdE7Aub4niHMmo5wl9mY4Uw,6190
flask_migrate/templates/flask-multidb/script.py.mako,sha256=198VPxVEN3NZ3vHcRuCxSoI4XnOYirGWt01qkbPKoJw,1246
flask_migrate/templates/flask/README,sha256=JL0NrjOrscPcKgRmQh1R3hlv1_rohDot0TvpmdM27Jk,41
flask_migrate/templates/flask/__pycache__/env.cpython-311.pyc,,
flask_migrate/templates/flask/alembic.ini.mako,sha256=SjYEmJKzz6K8QfuZWtLJAJWcCKOdRbfUhsVlpgv8ock,857
flask_migrate/templates/flask/env.py,sha256=ibK1hsdOsOBzXNU2yQoAIza7f_EFzaVSWwON_NSpNzQ,3344
flask_migrate/templates/flask/script.py.mako,sha256=8_xgA-gm_OhehnO7CiIijWgnm00ZlszEHtIHrAYFJl0,494
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment