Commits

Alexander Solovyov committed 11a55c8

add dates to configparser

Comments (0)

Files changed (2)

   key: value
   key: [list, of, values]
   key: {key: value, key: value}
+  key: date: yyyy-mm-dd HH:MM:SS
 
 Any line without a ":" is simply skipped.
 '''
 
+from datetime import datetime
 
 def parse(data):
     result = {}
     if s('[') and e(']'):
         value = strip(value[1:-1].split(','))
     elif s('{') and e('}'):
-        value = dict(strip(x.split(':')) for x in value.split(','))
+        value = dict(strip(x.split(':')) for x in value[1:-1].split(','))
+    elif s('date:'):
+        value = datetime.strptime(value[len('date:'):].strip(),
+                                  '%Y-%m-%d %H:%M:%S')
     return key, value
 
 

cyraxlib/models.py

 
 DATE_RE = re.compile(r'(.*?)(\d+)[/-](\d+)[/-](\d+)[/-](.*)$')
 
+def postcmp(x, y):
+    xd = x.settings.get('updated', x.settings.date)
+    yd = y.settings.get('updated', y.settings.date)
+    return -1 if xd < yd else 1 if xd > yd else 0
 
 class Post(object):
     @staticmethod
 
     def __init__(self):
         base, Y, M, D, slug = DATE_RE.search(self.path).groups()
-        self.settings.date = datetime.date(int(Y), int(M), int(D))
+        self.settings.date = datetime.datetime(int(Y), int(M), int(D))
         self.settings.base = base
         self.settings.slug = op.splitext(slug)[0]
 
         if not hasattr(self.site, 'posts'):
             self.site.posts = []
         self.site.posts.append(self)
-        self.site.posts.sort(key=lambda x: x.date, reverse=True)
+        self.site.posts.sort(cmp=postcmp, reverse=True)
         self.site.latest_post = self.site.posts[0]
 
         for tag in self.settings.get('tags', []):
             tagentries = self.site.tags.setdefault(tag, [])
             if self not in tagentries:
                 tagentries.append(self)
-                self.site.tags[tag].sort(key=lambda x: x.date, reverse=True)
+                self.site.tags[tag].sort(cmp=postcmp, reverse=True)
 
     def __str__(self):
         return self.slug