Commits

John Mulligan committed dc06256

add initial created/modified time support

  • Participants
  • Parent commits 21c4fd9

Comments (0)

Files changed (5)

File muyhomepage2/page.py

         else:
             return []
 
+    def created(self):
+        if self.headers.get('created'):
+            return util.When.parse(self.headers['created'])
+        else:
+            return util.When(self._ctime())
+
+    def modified(self):
+        if self.headers.get('modified'):
+            return util.When.parse(self.headers['modified'])
+        else:
+            return util.When(self._mtime())
+
+    def _ctime(self):
+        return os.path.getctime(self.filename)
+
+    def _mtime(self):
+        return os.path.getmtime(self.filename)
+
 
 class PseduoPage(object):
     def __init__(self, filename, contentcode, title, action):

File muyhomepage2/pagehandlers/handler.py

     def tags(self):
         return sorted(self.page.tags)
 
+    @property
+    def createdon(self):
+        return self.page.created()
+
+    @property
+    def modifiedon(self):
+        return self.page.modified()
+
     def finalname(self):
         if 'x-force-file-name' in self.page.headers:
             return self.page.headers['x-force-file-name']

File muyhomepage2/pagehandlers/software.py

 
     @property
     def sources(self):
-    # Software-RCS: Hg
-    # Software-RCS-Url: http://hg.asynchrono.us/scrob-ws
         rcs = self.page.headers.get('software-rcs')
         if not rcs:
             return []

File muyhomepage2/util.py

 """
 
 import string
+import time, calendar
 from hashlib import md5
 
+TIME_FMT_MUY    = '%Y-%m-%d %H:%M %Z'
+TIME_FMT_822    = '%a, %d %b %Y %H:%M:%S %Z'
+TIME_FMT_3339   = '%Y-%m-%dT%H:%M:%SZ'
+TIME_FMT_ATOMID = '%Y-%m-%d'
+
 
 def encodetitle(title):
     """Create a simplified title string.
     finally:
         fp.close()
     return csum.hexdigest()
+
+
+class When(object):
+    def __init__(self, wtime):
+        self._time = wtime
+
+    def local(self):
+        return time.localtime(self._time)
+
+    def utc(self):
+        return time.gmtime(self._time)
+
+    def __str__(self):
+        return time.strftime(TIME_FMT_MUY, self.local())
+
+    def storefmt(self):
+        return time.strftime(TIME_FMT_MUY, self.utc())
+
+    @classmethod
+    def parse(cls, txt):
+        utc = True
+        if not txt.endswith("UTC"):
+            utc = False
+        tm = time.strptime(txt, TIME_FMT_MUY)
+        if utc:
+            etime = calendar.timegm(tm) 
+        else:
+            etime = time.mktime(tm)
+        return cls(etime)
+
+    @classmethod
+    def now(cls):
+        return cls(time.time())
+

File skins/default/base.html

   <!-- begin main content section -->
   <div id="page-main">
   {% block main %}
-  {% macro tidbits(_current) %}
-    <ul class="tidbits">
-      <li>
-          <a href="mailto:phglogistonjohn+web@gmail.com?={{_current.page.title}}">
-              Comment on {{_current.page.title}}
-          </a>
-      </li>
-      <li>
-          <!-- repeat tidbits -->
-      </li>
-    </ul>
-  {% endmacro %}
   {% endblock %}
   </div>
   <!-- end main content section -->