Răsfoiți Sursa

compat: Update eid to post_id for newer TinyDB

Boudhayan Gupta 6 ani în urmă
părinte
comite
9e2d814050
2 a modificat fișierele cu 19 adăugiri și 18 ștergeri
  1. 16 15
      blogit/blogit.py
  2. 3 3
      tests/test_all.py

+ 16 - 15
blogit/blogit.py

@@ -14,6 +14,7 @@
 # ============================================================================
 # Copyright (C) 2013-2016 Oz Nahum Tiram <nahumoz@gmail.com>
 # ============================================================================
+
 import os
 import re
 import datetime
@@ -164,7 +165,7 @@ class Tag(object):
         new = set(post_ids) - set(tag['post_ids'])
 
         tag['post_ids'].extend(list(new))
-        self.table.update({'post_ids': tag['post_ids']}, eids=[tag.eid])
+        self.table.update({'post_ids': tag['post_ids']}, doc_ids=[tag.doc_id])
 
     posts = property(fget=None, fset=set_posts)
 
@@ -176,9 +177,9 @@ class Tag(object):
         posts = tag['post_ids']
 
         for id in posts:
-            post = self.db.posts.get(eid=id)
+            post = self.db.posts.get(doc_id=id)
             if not post:  # pragma: no coverage
-                raise ValueError("No post found for eid %s" % id)
+                raise ValueError("No post found for doc_id %s" % id)
             yield Entry(os.path.join(CONFIG['content_root'], post['filename']), id)  # noqa
 
     def render(self):
@@ -247,14 +248,14 @@ class Entry(object):
     db = DB
 
     @classmethod
-    def entry_from_db(kls, filename, eid=None):
+    def entry_from_db(kls, filename, doc_id=None):
         f = os.path.join(filename)
-        return kls(f, eid)
+        return kls(f, doc_id)
 
-    def __init__(self, path, eid=None):
+    def __init__(self, path, doc_id=None):
         self._path = path
         self.path = path.split(CONFIG['content_root'])[-1].lstrip('/')
-        self.id = eid  # this is set inside prepare()
+        self.id = doc_id  # this is set inside prepare()
         try:
             self.prepare()
         except KeyError:  # pragma: no coverage
@@ -401,8 +402,8 @@ def find_new_posts_and_pages(db):
                 if item:
                     if new_mtime > item['mtime']:
                         db[collection].update({'mtime': new_mtime},
-                                              eids=[item.eid])
-                        e = Entry(fullpath, eid=item.eid)
+                                              doc_ids=[item.doc_id])
+                        e = Entry(fullpath, doc_id=item.doc_id)
                     break
 
             if not item:
@@ -413,13 +414,13 @@ def find_new_posts_and_pages(db):
 
 def _get_last_entries(db, qty):
     """get all entries and the last qty entries"""
-    eids = [post.eid for post in db.posts.all()]
-    eids = sorted(eids, reverse=True)
-    # bug: here we shoud only render eids[:qty]
+    doc_ids = [post.doc_id for post in db.posts.all()]
+    doc_ids = sorted(doc_ids, reverse=True)
+    # bug: here we shoud only render doc_ids[:qty]
     # but we can't use mtimes for sorting. We'll need to add ptime for the
     # database (publish time)
     entries = [Entry(os.path.join(CONFIG['content_root'],
-                     db.posts.get(eid=eid)['filename']), eid) for eid in eids]
+                     db.posts.get(doc_id=doc_id)['filename']), doc_id) for doc_id in doc_ids]
     # return _sort_entries(entries)[:qty]
     entries.sort(key=operator.attrgetter('date'), reverse=True)
     return entries[:qty], entries
@@ -428,7 +429,7 @@ def _get_last_entries(db, qty):
 def update_index(entries):
     """find the last 10 entries in the database and create the main
     page.
-    Each entry in has an eid, so we only get the last 10 eids.
+    Each entry in has an doc_id, so we only get the last 10 doc_ids.
 
     This method also updates the ATOM feed.
     """
@@ -486,7 +487,7 @@ def build(config):
 
     entries = [Entry.entry_from_db(
                os.path.join(CONFIG['content_root'],
-                            e.get('filename')), e.eid) for e in
+                            e.get('filename')), e.doc_id) for e in
                DB.posts.all()]
     all_entries = list(_filter_none_public(all_entries))
     all_entries.sort(key=operator.attrgetter('date'), reverse=True)

+ 3 - 3
tests/test_all.py

@@ -140,7 +140,7 @@ def test_find_new_posts_and_pages():
 def test_tags():
     entries = [
         Entry.entry_from_db(os.path.join(CONFIG['content_root'],
-                                         e.get('filename')), e.eid)
+                                         e.get('filename')), e.doc_id)
         for e in DB.posts.all()]
     tags = DB.tags.all()  # noqa
 
@@ -232,7 +232,7 @@ summary: This is a summary
 
 
 def test_tag_render():
-    p = DB.posts.get(eid=1)
+    p = DB.posts.get(doc_id=1)
     entry = Entry.entry_from_db(
         os.path.join(CONFIG['content_root'], p.get('filename')), 1)
 
@@ -256,7 +256,7 @@ def test_get_last_entries():
 def test_render_archive():
 
     entries = [Entry.entry_from_db(
-        os.path.join(CONFIG['content_root'], e.get('filename')), e.eid) for e in
+        os.path.join(CONFIG['content_root'], e.get('filename')), e.doc_id) for e in
         DB.posts.all()]
 
     render_archive(entries[ARCHIVE_SIZE:])