Browse Source

render archive properly

Oz N Tiram 9 years ago
parent
commit
7799ffadc7
1 changed files with 14 additions and 12 deletions
  1. 14 12
      blogit/blogit2.py

+ 14 - 12
blogit/blogit2.py

@@ -40,7 +40,6 @@ import datetime
 import argparse
 import argparse
 import sys
 import sys
 import operator
 import operator
-from distutils import dir_util
 import shutil
 import shutil
 from StringIO import StringIO
 from StringIO import StringIO
 import codecs
 import codecs
@@ -181,9 +180,13 @@ class Tag(object):
 
 
 class Entry(object):
 class Entry(object):
 
 
+    @classmethod
+    def entry_from_db(kls, filename):
+        f=os.path.join(os.path.join(CONFIG['content_root'], filename))
+        return kls(f)
+
     def __init__(self, path):
     def __init__(self, path):
-        super(Entry, self).__init__()
+        path = os.path.basename(path)
-        path = path.split('content/')[-1]
         self.path = path
         self.path = path
         self.entry_template = jinja_env.get_template("entry.html")
         self.entry_template = jinja_env.get_template("entry.html")
         self.prepare()
         self.prepare()
@@ -329,9 +332,6 @@ class Entry(object):
         destination.write(html)
         destination.write(html)
         destination.close()
         destination.close()
 
 
-        # before returning write log to csv
-        # file name, date first seen, date rendered
-        # self.path , date-first-seen, if rendered datetime.now
         return True
         return True
 
 
 
 
@@ -350,7 +350,7 @@ def _sort_entries(entries):
     return list(reversed(sorted(entries, key=operator.attrgetter('date'))))
     return list(reversed(sorted(entries, key=operator.attrgetter('date'))))
 
 
 
 
-def render_archive(entries, render_to=None):
+def render_archive(entries):
     """
     """
     This function creates the archive page
     This function creates the archive page
 
 
@@ -363,15 +363,16 @@ def render_archive(entries, render_to=None):
     Until now, this was parsed from each entry YAML...
     Until now, this was parsed from each entry YAML...
     It would be more convinient to read this from the DB.
     It would be more convinient to read this from the DB.
 
 
-    This requires changes for the database
+    This requires changes for the database.
     """
     """
     context = GLOBAL_TEMPLATE_CONTEXT.copy()
     context = GLOBAL_TEMPLATE_CONTEXT.copy()
     context['entries'] = entries[ARCHIVE_SIZE:]
     context['entries'] = entries[ARCHIVE_SIZE:]
     template = jinja_env.get_template('archive_index.html')
     template = jinja_env.get_template('archive_index.html')
     html = template.render(context)
     html = template.render(context)
-    if not render_to:
+    try:
-        render_to = "%s/archive/index.html" % CONFIG['output_to']
+        os.makedirs(os.path.join(CONFIG['output_to'], 'archive'))
-        dir_util.mkpath("%s/archive" % CONFIG['output_to'])
+    except OSError:
+        pass
 
 
     destination = codecs.open("%s/archive/index.html" % CONFIG[
     destination = codecs.open("%s/archive/index.html" % CONFIG[
                               'output_to'], 'w', CONFIG['content_encoding'])
                               'output_to'], 'w', CONFIG['content_encoding'])
@@ -465,7 +466,8 @@ def new_build():
 
 
     # update archive
     # update archive
     print "updating archive"
     print "updating archive"
-    # TODO
+    render_archive(_sort_entries([Entry(p['filename'])
+                                  for p in DB.posts.all()]))