Skip to content

Commit

Permalink
more re-organization of the webapp and associated classes
Browse files Browse the repository at this point in the history
  • Loading branch information
dcolish committed Jan 17, 2011
1 parent 498258a commit 231f373
Show file tree
Hide file tree
Showing 33 changed files with 87 additions and 75 deletions.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
7 changes: 3 additions & 4 deletions cockerel/models/__init__.py
@@ -1,6 +1,5 @@
# #
# from flaskext.sqlalchemy import SQLAlchemy
from flaskext.sqlalchemy import SQLAlchemy

# from webapp import
db = SQLAlchemy()

# db = SQLAlchemy(app)
__all__ = ['db']
3 changes: 2 additions & 1 deletion cockerel/models/schema.py
@@ -1,5 +1,6 @@
from werkzeug import generate_password_hash, check_password_hash
from cockerel.webapp import db

from . import db


user_classes = db.Table('user_classes', db.Model.metadata,
Expand Down
3 changes: 3 additions & 0 deletions cockerel/utilities/__init__.py
@@ -0,0 +1,3 @@
from base import new_app

__all__ = ['new_app']
52 changes: 52 additions & 0 deletions cockerel/utilities/base.py
@@ -0,0 +1,52 @@
"""
cockerel.webapp
---------------
Main instance of the webapp. All modules will be loaded from this file. To
add a new module you must import it here and register it.
"""
import logging
import os

from flask import g

from flaskext.markdown import Markdown

from cockerel.models import db

from cockerel.webapp import (
admin,
classes,
frontend,
lessons,
prover,
)
from cockerel.webapp.prover import ProverExtension


def update_config(app):
"""syncronizes the config with the g global request object"""
g.config = app.config


def register_modules(app, mod_list):
for x in mod_list:
app.register_module(x)


def new_app(app, serialize=False):
logging.basicConfig(level=logging.DEBUG)
md = Markdown(app, extensions=['tables'])
md.register_extension(ProverExtension)
register_modules(app, [admin, classes, frontend, lessons, prover])
app.secret_key = os.urandom(24)
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:////tmp/test.db'
app.config['COQD_HOST'] = 'localhost'
app.config['COQD_PORT'] = 8003
if serialize:
app.config['serialize'] = serialize

# XXX:dc: kind of a hack but I want to keep the db and the app seperate
db.init_app(app)
db.app = app

return app
56 changes: 8 additions & 48 deletions cockerel/webapp/__init__.py
@@ -1,52 +1,12 @@
"""
cockerel.webapp
---------------
Main instance of the webapp. All modules will be loaded from this file. To
add a new module you must import it here and register it.
"""
import logging
import os
#
from flask import Flask

from flask import Flask, g
from flaskext.sqlalchemy import SQLAlchemy
from flaskext.markdown import Markdown
from admin import admin
from frontend import frontend
from classes import classes
from lessons import lessons
from prover import prover

logging.basicConfig(level=logging.DEBUG)

HOST = "localhost"
app = Flask(__name__)
db = SQLAlchemy(app)
md = Markdown(app, extensions=['tables'])

from .views.prover.mdx_prover import ProverExtension
md.register_extension(ProverExtension)

from .views import admin
from .views import classes
from .views import frontend
from .views import lessons
from .views import prover
from .utils import register_modules

register_modules(app, [admin, classes, frontend, lessons, prover])

app.secret_key = os.urandom(24)

app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:////tmp/test.db'
app.config['COQD_HOST'] = 'localhost'
app.config['COQD_PORT'] = 8003

# see if the db exists, if not make it and initialize
if not os.path.exists(app.config.get('SQLALCHEMY_DATABASE_URI')):
db.create_all()


def update_config():
"""syncronizes the config with the g global request object"""
g.config = app.config


def new_app(serialize):
if serialize:
app.config['serialize'] = serialize
return app
__all__ = ['admin', 'app', 'frontend', 'classes', 'lessons', 'prover']
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Expand Up @@ -17,7 +17,7 @@
from flatland.out.markup import Generator

from cockerel.models.schema import db, Classes
from cockerel.webapp.auth import login_required
from cockerel.auth import login_required
from cockerel.webapp.forms import AddEditClassForm

classes = Module(__name__)
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Expand Up @@ -8,7 +8,7 @@
)
from flatland.out.markup import Generator

from cockerel.webapp.auth import login_required
from cockerel.auth import login_required
from cockerel.webapp.forms import EditLessonForm
from cockerel.models.schema import db, Classes, Lesson

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 4 additions & 0 deletions cockerel/webapp/prover/__init__.py
@@ -0,0 +1,4 @@
from prover import prover
from mdx_prover import ProverExtension

__all__ = ['prover', 'ProverExtension']
Expand Up @@ -16,7 +16,7 @@

from sqlalchemy.orm.exc import NoResultFound

from cockerel.webapp import db
from cockerel.models import db
from cockerel.models.schema import Theorem
from .prover import hash_theorem

Expand Down
Expand Up @@ -14,7 +14,7 @@
)

from cockerel.models.schema import Proof, Theorem
from cockerel.webapp.views.util import login_required
from cockerel.auth import login_required

prover = Module(__name__)

Expand Down
3 changes: 0 additions & 3 deletions cockerel/webapp/utils/__init__.py

This file was deleted.

Empty file removed cockerel/webapp/utils/base.py
Empty file.
6 changes: 0 additions & 6 deletions cockerel/webapp/views/__init__.py

This file was deleted.

3 changes: 0 additions & 3 deletions cockerel/webapp/views/prover/__init__.py

This file was deleted.

17 changes: 11 additions & 6 deletions manager.py
@@ -1,15 +1,18 @@
from functools import partial
from flaskext.script import Manager, Server, Shell
from werkzeug import create_environ

from coqd.runner import main as coqd_main
from cockerel.webapp import app, new_app, db
from cockerel.models import schema
from cockerel.webapp import app
from cockerel.utilities import new_app
from cockerel.models import db, schema


def _make_context():
return dict(app=app, db=db, models=schema)
return dict(app=new_app(app), db=db, models=schema)


manager = Manager(new_app)
manager = Manager(partial(new_app, app))
manager.add_command("shell", Shell(make_context=_make_context))
manager.add_command("runserver", Server())
manager.add_option('--serialize', action="store_true",
Expand All @@ -18,8 +21,10 @@ def _make_context():

@manager.command
def initdb():
db.drop_all()
db.create_all()
# A request_context is required to use these helper functions
with new_app(app).request_context(create_environ()):
db.drop_all()
db.create_all()


@manager.option('--serialize', action="store_true",
Expand Down

0 comments on commit 231f373

Please sign in to comment.