Permalink
Browse files

Refactor annotator.annotator into annotator.store

--HG--
extra : convert_revision : 514abbe3a9bae82b51be5a219eccd5c6eeffa946
  • Loading branch information...
1 parent 2718285 commit 4b94184a78e3b18389a548402b458f2cb89bdac5 @nickstenning nickstenning committed Dec 10, 2010
Showing with 24 additions and 27 deletions.
  1. +0 −17 annotator/annotator.py
  2. +15 −1 annotator/store.py
  3. +8 −8 run.py
  4. +1 −1 tests/annotator/test_store.py
@@ -1,17 +0,0 @@
-from flask import Flask
-from flask import g, json, request
-
-from .store import store
-
-app = Flask(__name__)
-
-@store.after_request
-def after_request(response):
- response.headers['Access-Control-Allow-Origin'] = '*'
- response.headers['Access-Control-Expose-Headers'] = 'Location'
- response.headers['Access-Control-Allow-Methods'] = 'GET, POST, PUT, DELETE'
- response.headers['Access-Control-Max-Age'] = '86400'
- return response
-
-def setup_app():
- app.register_module(store, url_prefix=app.config['MOUNTPOINT'])
View
@@ -1,10 +1,16 @@
from flask import Flask, Module
-from flask import abort, current_app, g, json, redirect, request, url_for
+from flask import abort, current_app, json, redirect, request, url_for
from .model import Annotation, Range, session
+__all__ = ["app", "store", "setup_app"]
+
+app = Flask(__name__)
store = Module(__name__)
+def setup_app():
+ app.register_module(store, url_prefix=app.config['MOUNTPOINT'])
+
# We define our own jsonify rather than using flask.jsonify because we wish
# to jsonify arbitrary objects (e.g. index returns a list) rather than kwargs.
def jsonify(obj):
@@ -14,6 +20,14 @@ def jsonify(obj):
def unjsonify(str):
return json.loads(str)
+@store.after_request
+def after_request(response):
+ response.headers['Access-Control-Allow-Origin'] = '*'
+ response.headers['Access-Control-Expose-Headers'] = 'Location'
+ response.headers['Access-Control-Allow-Methods'] = 'GET, POST, PUT, DELETE'
+ response.headers['Access-Control-Max-Age'] = '86400'
+ return response
+
# INDEX
@store.route('')
def index():
View
@@ -1,21 +1,21 @@
import os
-from annotator.annotator import app, setup_app
-from annotator.model import *
+import annotator.store as store
+import annotator.model as model
if __name__ == '__main__':
here = os.path.dirname(os.path.abspath( __file__ ))
if 'ANNOTATOR_CONFIG' in os.environ:
- app.config.from_envvar('ANNOTATOR_CONFIG')
+ store.app.config.from_envvar('ANNOTATOR_CONFIG')
else:
- app.config.from_pyfile(here + '/annotator.cfg')
+ store.app.config.from_pyfile(here + '/annotator.cfg')
- metadata.bind = app.config['DB']
+ model.metadata.bind = store.app.config['DB']
# Create tables
- setup_all(True)
+ model.setup_all(True)
# Setup app
- setup_app()
+ store.setup_app()
- app.run()
+ store.app.run()
@@ -1,6 +1,6 @@
from flask import json, url_for
-from annotator.annotator import app, setup_app
+from annotator.store import app, setup_app
from annotator.model import Annotation, Range
from annotator.model import create_all, drop_all, session

0 comments on commit 4b94184

Please sign in to comment.