Commits

sirex  committed 8391320

Docutils elements support, implemented partially.

  • Participants
  • Parent commits e619c2e

Comments (0)

Files changed (4)

File apps/devblog/devblog/__init__.py

 from datetime import datetime
 
 from docutils import io
-from docutils.core import publish_parts
+from docutils.core import publish_parts, publish_doctree
+
+import lxml.etree
 
 from devblog.models import Page
 import devblog.directives.pygments
+from pprint import pprint
 
 PAGES_ROOT = '/home/sirex/Dokumentai/blog/'
 
 def sync():
     params = {
         'source_class': io.FileInput,
-        'writer_name': 'html',
         'settings_overrides': {
             'output_encoding': 'unicode',
         },
     }
+
+    fields = ('author', 'date')
     Page.objects.all().delete()
     for filename in get_files(PAGES_ROOT):
         params['source'] = open(filename, 'r')
-        parts = publish_parts(**params)
+        tree = publish_doctree(**params)
+        etree = lxml.etree.XML(tree.asdom().toxml())
+        docinfo = {}
+        for element in etree.findall('docinfo/*'):
+            if element.tag in fields:
+                docinfo[element.tag] = element.text
+
+        params['source'] = open(filename, 'r')
+        parts = publish_parts(**dict(params, writer_name='html'))
+        updated = get_mtime(filename)
         page = Page(title = parts['title'],
                     page=get_page(filename),
-                    updated=get_mtime(filename),
+                    created=docinfo.get('date', updated),
+                    updated=updated,
                     body = parts['html_body'])
         page.save()

File apps/devblog/devblog/models.py

 class Page(models.Model):
     page = models.CharField(max_length=255, blank=True)
     title = models.CharField(max_length=255)
+    created = models.DateTimeField()
     updated = models.DateTimeField(auto_now=True)
     body = models.TextField()
 

File apps/devblog/devblog/templates/devblog/index.html

 {% block content %}
 <ul>
 {% for page in pages %}
-    <li><a href="{% url devblog-page page.page %}">{{ page }}</a></li>
+    <li>
+        [{{ page.created|date:"SHORT_DATE_FORMAT" }}]
+        <a href="{% url devblog-page page.page %}">{{ page }}</a>
+    </li>
 {% endfor %}
 </ul>
 {% endblock %}

File buildout.cfg

     docutils
     Sphinx
     Pygments
+    lxml
 
 extra-paths =
     ${buildout:directory}