Commits

Anonymous committed e33e81e

fix view creation.

Comments (0)

Files changed (3)

friendpaste/application.py

 from werkzeug.exceptions import HTTPException, BadRequest, Forbidden, \
      NotFound
 from jinja import Environment
-from couchdb import Server
+from couchdb import Server, ServerError
 
 from friendpaste import settings
 from friendpaste.urls import map, all_views
 
 def init_views(db):
     paste_view={
-        'language': 'text/javascript',
-        'views': {
-            'by_id': 'function(doc) { if (doc.type == "snippet") { map([doc._id, 0], doc); } else if (doc.type == "revision") { map([doc.parent, 1, doc.updated], doc); }}'
+            'by_id': 'function(doc) { if (doc.type == "snippet") { map([doc._id, 0], doc); } else if (doc.type == "revision") { map([doc.parent, 1, doc.updated], doc); }}',
+            'by_revision': 'function(doc) { if (doc.type == "revision") { map([doc.parent,doc.revid], doc); }}'
+
+    }
+    try:
+        db['_design/paste'] = {
+            'language': 'text/javascript',
+            'views': paste_view
         }
-    }
-
-    id=db.resource.put(content=paste_view, path='/_design/paste')
-
-
+    except ServerError:
+        v = db['_design/paste']
+        v['views'] = paste_view
+        db['_design/paste'] = v
 
 class Friendpaste(object):
     def __init__(self):
         except:
             db = couchdb_server[settings.DATABASE_NAME]
 
-        try:
-            init_views(db) 
-        except:
-            pass
-
+        init_views(db)
         self.initialized = True
 
     def bind_to_thread(self):

friendpaste/dbsession.py

         self.session_factory = session_factory
         self.registry = ScopedRegistry(session_factory, scopefunc)
 
-        print self.session_factory
-
     def __call__(self, **kwargs):
         print "called"
         if kwargs:

friendpaste/paste/views.py

     # set revisions
     if len(res) > 1:
         revisions = res[1:]
+        # reorder revisions
+        revisions.sort(lambda a,b: cmp(a.key[1], b.key[1]))
         revisions.reverse()
 
 
         })
 
     rev = request.values.get('rev', None)
-    s, revisions = get_snippet(id, rev)
+    #s, revisions = get_snippet(id, rev)
+    if rev is None:
+        s = couchdb_proxy.load(Snippet, id)
 
     if 'application/json' in mimetypes:
         if request.method == 'GET':
                 'revid': s.revid,
                 'title': s.title,
                 'snippet': s.snippet,
-                'language': str(s.language),
-                'revisions': revisions and [rev.value['revid'] for rev in revisions] or []
+                'language': str(s.language)
          }
             return send_json(snippet_hash)
     
 
     # get theme
     theme = _get_theme(request)
-    return render_response('paste/view.html', snippet=s, theme=theme, form=form, revisions=revisions)
+    return render_response('paste/view.html', snippet=s, theme=theme, form=form)