Commits

Anonymous committed 423a8dd

fix timestamp, rss

  • Participants
  • Parent commits fce06dd

Comments (0)

Files changed (5)

friendpaste/feeds.py

                 yield u'  <dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">%s</dc:creator>\n' % author['name']
 
         if self.published:
+            print self.published
             yield u'  ' + simple_tag(u'pubDate', rfc2822_date(self.published))
 
         if self.enclosure is not None:

friendpaste/paste/models.py

             self._data = db.get(docid)
         else:
             old_data = db.get(self._data.id)
+            self.created = datetime.now()
             old_hash = hash(old_data['snippet']+old_data['title']+old_data['language'], '')
             new_hash = hash(self.snippet+self.title+self.language, '')
             if old_hash != new_hash:

friendpaste/paste/views.py

 
 import simplejson as json
 
+
 from friendpaste.settings import SHARED_DATA, SITE_URI
-from friendpaste.utils import local
+from friendpaste.utils import local, datetimestr_topython, strptime
 from friendpaste.http import Response
 from friendpaste.template import render_response, highlighter
 from friendpaste.paste.models import Snippet
     return render_response('paste/view.html', snippet=s, theme=theme, form=form, revisions=revisions)
 
 
+
 def view_rss(request, id):
     revisions = None
     res = _get_snippet_revisions(id)
     # set revisions
     if len(res) > 1:
         revisions = res[1:]
+        # reorder revisions
+        revisions.sort(lambda a,b: cmp(a.key[1], b.key[1]))
         revisions.reverse()
 
 
         title=s.title and s.title or "snippet #%s" % s.id,
         description = s.snippet,
         link = "%s/%s" % (SITE_URI, s.id)
+    
     )
+    s2, rev, old_rev, unidiff = get_changeset(id, s.revid)
+    feed.add_entry(RssFeedEntry(
+        title="%s revision %s" % (s.title,s.revid),
+        link= "%s/%s?rev=%s" % (SITE_URI, s.id, s.revid),
+        description="\n%s\n" %unidiff,
+        **{ 
+                'published': s.created,
+                'updated':s.updated
+        }    
+    ))
+    
     for revision in revisions:
-        print revision.value['revid']
         s2, rev, old_rev, unidiff = get_changeset(id, rev=revision.value['revid'])
         feed.add_entry(RssFeedEntry(
-            title="revision %s" % revision.value['revid'],
+            title="%s revision %s" % (revision.value['title'], revision.value['revid']),
             link= "%s/%s?rev=%s" % (SITE_URI, s.id, revision.value['revid']),
-            description="\n%s\n" %unidiff
-            ))
-    s2, rev, old_rev, unidiff = get_changeset(id, s.revid)
-    print s.revid
-    feed.add_entry(RssFeedEntry(
-        title="revision %s" % s.revid,
-        link= "%s/%s?rev=%s" % (SITE_URI, s.id, s.revid),
-        description="\n%s\n" %unidiff
+            description="\n%s\n" %unidiff,
+            **{ 
+                'published': datetimestr_topython(revision.value['created']),
+                'updated': datetimestr_topython(revision.value['updated'])
+            }
         ))
+        
     
     return feed.get_response()
 

friendpaste/template.py

 # limitations under the License.
 
 
+from calendar import timegm
 import codecs
 import os
-from datetime import datetime
+from time import strptime, localtime
 
 from jinja.loaders import BaseLoader
 from jinja.exceptions import TemplateNotFound
 from pygments.styles import get_all_styles
 
 from friendpaste.http import Request, Response
-from friendpaste.utils import local, timesince
-
-# python 2.4 compatibility
-try:
-    strptime = datetime.strptime
-except:
-    def strptime(date_string, format):
-        import time
-        return datetime(*(time.strptime(date_string, format)[0:6]))
-
-
+from friendpaste.utils import local, timesince, datetimestr_topython
 
 class TemplateLoader(BaseLoader):
 
     """
     def wrapped(env, ctx, value):
         # need conversion here .
-        value=strptime(value,'%Y-%m-%dT%H:%M:%SZ')
+        value = datetimestr_topython(value)
         return timesince(value)
     return wrapped
 
     datetime filter for the template
     """
     def wrapped(env, ctx, value):
-        value=strptime(value,'%Y-%m-%dT%H:%M:%SZ')
+        value=datetimestr_topython(value)
         return value.strftime('%c')
     return wrapped
 

friendpaste/utils.py

 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-
-import datetime
-import time
+from calendar import timegm
+from datetime import datetime, timedelta, time
+from time import strptime, localtime
 from gettext import gettext, ngettext
 
 from werkzeug import Local, LocalManager
 
+
 local = Local()
 local_manager = LocalManager([local])
 
       (60, lambda n: ungettext('minute', 'minutes', n))
     )
     # Convert datetime.date to datetime.datetime for comparison
-    if d.__class__ is not datetime.datetime:
+    if d.__class__ is not datetime:
         type= d.__class__
-        raise blah
-        d = datetime.datetime(d.year, d.month, d.day)
+        d = datetime(d.year, d.month, d.day)
     if now:
         t = now.timetuple()
     else:
-        t = time.localtime()
+        t = localtime()
     #if d.tzinfo:
     #    tz = LocalTimezone(d)
     #else:
     #    tz = None
     tz = None
-    now = datetime.datetime(t[0], t[1], t[2], t[3], t[4], t[5], tzinfo=tz)
+    now = datetime(t[0], t[1], t[2], t[3], t[4], t[5], tzinfo=tz)
 
     # ignore microsecond part of 'd' since we removed it from 'now'
-    delta = now - (d - datetime.timedelta(0, 0, d.microsecond))
+    delta = now - (d - timedelta(0, 0, d.microsecond))
     since = delta.days * 24 * 60 * 60 + delta.seconds
     if since <= 0:
         # d is in the future compared to now, stop processing.
     else:
         return s
 
-def to_unicode(text):
-    """
-    return an unicode object
-    """
-    if not isinstance(s, basestring):
-        if hasattr(s, '__unicode__'):
-             s = unicode(s)
-        else:
-            s= unicode(str(s), 'utf-8', 'strict')
-    elif not isinstance(s, unicode):
-        s = s.decode('utf-8', 'strict')
-    return s
 
 def iri_to_uri(iri):
     """
         return iri
 
     return urllib.quote(to_str(iri), safe='/#%[]=:;$&()+,!?*')
+
+def datetimestr_topython(value):
+    if isinstance(value, basestring):
+        try:
+            value = value.split('.', 1)[0] # strip out microseconds
+            value = value.rstrip('Z') # remove timezone separator
+                
+            timestamp = timegm(strptime(value, '%Y-%m-%dT%H:%M:%S'))
+            value = datetime.utcfromtimestamp(timestamp)
+        except ValueError, e:
+            raise ValueError('Invalid ISO date/time %r' % value)
+        return value