Switch to side-by-side view

--- a/ForgeWiki/forgewiki/model/wiki.py
+++ b/ForgeWiki/forgewiki/model/wiki.py
@@ -7,7 +7,9 @@
 from pymongo.errors import OperationFailure
 
 from ming import schema
-from ming import Field
+from ming.orm.base import state, session
+from ming.orm.mapped_class import MappedClass
+from ming.orm.property import FieldProperty
 
 from pyforge.model import VersionedArtifact, Snapshot, Message
 
@@ -30,7 +32,7 @@
         name='page_history'
 
     def original(self):
-        return Page.m.get(_id=self.artifact_id)
+        return Page.query.get(_id=self.artifact_id)
         
     def shorthand_id(self):
         return '%s#%s' % (self.original().shorthand_id(), self.version)
@@ -52,11 +54,11 @@
         name='page'
         history_class = PageHistory
 
-    title=Field(str)
-    text=Field(schema.String, if_missing='')
+    title=FieldProperty(str)
+    text=FieldProperty(schema.String, if_missing='')
 
     def url(self):
-        return context.app.script_name + '/' + self.title + '/'
+        return self.app_config.script_name() + '/' + self.title + '/'
 
     def shorthand_id(self):
         return self.title
@@ -78,20 +80,19 @@
                 project_id=context.project._id,
                 title=title)
             #Check for existing page object    
-            obj = cls.m.get(
+            obj = cls.query.get(
                 app_config_id=context.app.config._id,
                 title=title)
             if obj is None:
-                obj = cls.make(dict(
-                        title=title,
-                        app_config_id=context.app.config._id,
-                        ))
-            new_obj = dict(obj, version=obj.version + 1)
-            return cls.make(new_obj)
+                obj = cls(
+                    title=title,
+                    app_config_id=context.app.config._id,
+                    )
+            return obj
         else:
             pg = cls.upsert(title)
             HC = cls.__mongometa__.history_class
-            ss = HC.m.find({'artifact_id':pg._id, 'version':int(version)}).one()
+            ss = HC.query.find({'artifact_id':pg._id, 'version':int(version)}).one()
             new_obj = dict(ss.data, version=version+1)
             return cls.make(new_obj)
 
@@ -104,7 +105,6 @@
         while True:
             try:
                 c = Comment.make(dict(page_id=self._id))
-                c.m.insert()
                 return c
             except OperationFailure:
                 sleep(0.1)
@@ -112,14 +112,14 @@
 
     def root_comments(self):
         if '_id' in self:
-            return Comment.m.find(dict(page_id=self._id, parent_id=None))
+            return Comment.query.find(dict(page_id=self._id, parent_id=None))
         else:
             return []
 
 class Comment(Message):
     class __mongometa__:
         name='comment'
-    page_id=Field(schema.ObjectId)
+    page_id=FieldProperty(schema.ObjectId)
 
     def index(self):
         result = Message.index(self)
@@ -134,7 +134,7 @@
     @property
     def page(self):
         """The page this comment connects too"""
-        return Page.m.get(_id=self.page_id)
+        return Page.query.get(_id=self.page_id)
 
     def url(self):
         """The URL for the page for this comment"""
@@ -142,3 +142,5 @@
 
     def shorthand_id(self):
         return '%s-%s' % (self.page.title, self._id)
+
+MappedClass.compile_all()