Skip to content
This repository has been archived by the owner on Sep 18, 2019. It is now read-only.

Commit

Permalink
init flask app
Browse files Browse the repository at this point in the history
  • Loading branch information
grewn0uille committed Feb 9, 2018
1 parent e6ea859 commit 840eb75
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
14 changes: 8 additions & 6 deletions sherlog/__init__.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
import locale
import os

from flask import Flask
from urllib.parse import urlparse

from sqlalchemy import create_engine
from .sherlog import *


locale.setlocale(locale.LC_ALL, 'fr_FR')

app = Flask(__name__)
app = Sherlog(__name__)
app.config.from_envvar('FLASK_CONFIG')

engine = create_engine(app.config['DB'])
app.initialize()

# engine = create_engine(app.config['DB'])

@app.cli.command()
def drop_db():
filename = urlparse(app.config['DB']).path
if os.path.isfile(filename):
os.remove(filename)


from .sherlog import *
15 changes: 15 additions & 0 deletions sherlog/sherlog.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from flask import Flask
from flask import g
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker


class Sherlog(Flask):
def create_session(self):
return sessionmaker(bind=create_engine(self.config['DB']))()

def before(self):
g.session = self.create_session()

def initialize(self):
self.before_request(self.before)

0 comments on commit 840eb75

Please sign in to comment.