Skip to content

Commit

Permalink
removed need for config file
Browse files Browse the repository at this point in the history
  • Loading branch information
Mole1424 committed Jul 6, 2023
1 parent 49b8ecd commit e402a36
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 106 deletions.
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
.vscode/
instance/
config.yaml
instance/
1 change: 0 additions & 1 deletion Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ gunicorn = "*"
flask-sqlalchemy = "*"
markdown = "*"
werkzeug = "*"
pyyaml = "*"

[dev-packages]

Expand Down
132 changes: 43 additions & 89 deletions Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 8 additions & 11 deletions app.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
from flask import Flask, render_template, redirect, url_for, request
from flask import Flask, render_template, redirect, request
from db_schema import db, Projects
from markdown import markdown
from werkzeug.security import generate_password_hash, check_password_hash
import yaml
from werkzeug.security import check_password_hash
from os import getenv

app = Flask(__name__)

with open("config.yaml", "r") as f:
config = yaml.safe_load(f).get("config")

app.config['SQLALCHEMY_DATABASE_URI'] = config.get("database_uri")
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///db.sqlite'
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
db.init_app(app)
resetdb = False
resetdb = True
if resetdb:
with app.app_context():
db.drop_all()
Expand Down Expand Up @@ -46,7 +43,7 @@ def edit_project(project_id):

@app.route("/projects/<int:project_id>/editing", methods=["POST"])
def editing_project(project_id):
if check_password_hash(config.get("password"), request.form['password']):
if check_password_hash(getenv("DB_PASSWORD"), request.form['password']):
project = Projects.query.filter_by(id=project_id).first()
project.title = request.form['title']
project.description = request.form['description']
Expand All @@ -62,7 +59,7 @@ def new_project():

@app.route("/projects/creatingnewproject", methods=["POST"])
def creating_new_project():
if check_password_hash(config.get("password"), request.form['password']):
if check_password_hash(getenv("DB_PASSWORD"), request.form['password']):
project = Projects(request.form['title'], request.form['description'], request.form['image'], request.form['blog'])
db.session.add(project)
db.session.commit()
Expand All @@ -75,7 +72,7 @@ def delete_project_page(project_id):

@app.route("/projects/<int:project_id>/deleting", methods=["POST"])
def delete_project(project_id):
if check_password_hash(config.get("password"), request.form['password']):
if check_password_hash(getenv("DB_PASSWORD"), request.form['password']):
project = Projects.query.filter_by(id=project_id).first()
db.session.delete(project)
db.session.commit()
Expand Down
3 changes: 0 additions & 3 deletions exampleconfig.yaml

This file was deleted.

0 comments on commit e402a36

Please sign in to comment.