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