Commits

Anonymous committed 5c2895d

[all][m]: wire in annotator library.

* Much of this done last monday.
* controllers/annotation.py: Set up annotation store at /annotation
* controllers/home.py: Configure annotate action on home to use JsAnnotateMiddleware
* model: set up annotator model Annotation object

  • Participants
  • Parent commits 8d7cb88

Comments (0)

Files changed (7)

commentonit/config/routing.py

 
     map.connect('home', '/', controller='home', action='index')
     map.connect('annotate', '/annotate', controller='home', action='annotate')
-    map.connect('/{controller}/{action}/')
-    map.connect('/{controller}/{action}/{id}/')
+    map.connect('/{controller}/')
+    map.connect('/{controller}/{action}')
+    map.connect('/{controller}/{action}/{id}')
 
     return map

commentonit/controllers/annotation.py

+import logging
+
+from pylons import request, response, session, tmpl_context as c
+from pylons.controllers.util import abort, redirect_to
+
+from commentonit.lib.base import BaseController, render
+
+log = logging.getLogger(__name__)
+
+from annotator.store import AnnotatorStore
+
+# mounting it at annotation in pylons is a bit 'clever'
+# we're not stripping off script_name at the moment from path
+# and annotation is the offset within Store for annotation objects
+AnnotationController = AnnotatorStore
+

commentonit/controllers/home.py

 
 log = logging.getLogger(__name__)
 
+import annotator.middleware
+media_mount_path = '.js-annotate'
+server_api = '/'
+anno_middleware = annotator.middleware.JsAnnotateMiddleware(None,
+        media_mount_path, server_api)
+
 class HomeController(BaseController):
 
     def index(self):
         # TODO: create text in the backend ...
         text = request.params.get('text', '')
         c.content = '<pre>%s</pre>' % text
-        return render('annotate.html')
+        out = render('annotate.html')
+        out = anno_middleware.modify_html(out)
+        return out
 

commentonit/model/__init__.py

     #
     meta.Session.configure(bind=engine)
     meta.engine = engine
+    assert engine is not None
 
+import annotator.model
+annotation_table = annotator.model.make_annotation_table(meta.metadata)
+annotator.model.map_annotation_object(meta.Session.mapper, annotation_table)
+
+class Repository(object):
+
+    def create_db(self):
+        '''Create the tables if they don't already exist'''
+        meta.metadata.create_all(bind=meta.engine)
+
+    def init_db(self):
+        pass
+
+repo = Repository()
 
 ## Non-reflected tables may be defined and mapped at module level
 #foo_table = sa.Table("Foo", meta.metadata,

commentonit/tests/functional/test_annotation.py

+from commentonit.tests import *
+
+class TestAnnotationController(TestController):
+
+    def test_index(self):
+        response = self.app.get(url(controller='annotation', action='index'))
+        # Test response...

commentonit/websetup.py

 import logging
 
 from commentonit.config.environment import load_environment
-from commentonit.model import meta
+import commentonit.model as model
 
 log = logging.getLogger(__name__)
 
     """Place any commands to setup commentonit here"""
     load_environment(conf.global_conf, conf.local_conf)
 
-    # Create the tables if they don't already exist
-    meta.metadata.create_all(bind=meta.engine)
+    model.repo.create_db()
+
         "Pylons>=0.9.7",
         "SQLAlchemy>=0.5",
         "Genshi>=0.4",
+        "annotator>=0.3"
     ],
     setup_requires=["PasteScript>=1.6.3"],
     packages=find_packages(exclude=['ez_setup']),