use datetime tls-sprint
authorsylvain.thenault@logilab.fr
Thu, 30 Apr 2009 00:35:37 +0200
branchtls-sprint
changeset 1546 68c69980f6a1
parent 1545 53d3d783370f
child 1547 cb8c15a1e140
use datetime
goa/skel/views.py
--- a/goa/skel/views.py	Wed Apr 29 18:56:53 2009 +0200
+++ b/goa/skel/views.py	Thu Apr 30 00:35:37 2009 +0200
@@ -1,10 +1,8 @@
 # custom application views
-
-from mx.DateTime import DateTime
+from calendar import monthrange
+from datetime import date
 
-from cubicweb.web.views import baseviews
-from cubicweb.web.views.boxes import BoxTemplate
-from cubicweb.web.views.calendar import MONTHNAMES
+from cubicweb.web.views import baseviews, boxes, calendar
 from cubicweb.web.htmlwidgets import BoxLink, BoxWidget
 
 _ = unicode
@@ -12,15 +10,15 @@
 
 class BlogEntryPrimaryView(baseviews.PrimaryView):
     accepts = ('BlogEntry',)
-    
+
     def cell_call(self, row, col):
         entity = self.entity(row, col)
         self.w(u'<h1>%s</h1>' % entity.dc_title())
         entity.view('metadata', w=self.w)
         self.w(entity.printable_value('text'))
-        
+
 
-class BlogArchiveBox(BoxTemplate):
+class BlogArchiveBox(boxes.BoxTemplate):
     """side box usually displaying some related entities in a primary view"""
     id = 'blog_archives_box'
     title = _('blog archives')
@@ -37,12 +35,12 @@
                 blogmonths.append( (year, month) )
         box = BoxWidget(_('Blog archives'), id=self.id)
         for year, month in blogmonths:
-            firstday = DateTime(year, month, 1)
-            lastday = DateTime(year, month, firstday.days_in_month)
+            firstday = date(year, month, 1)
+            lastday = date(year, month, monthrange(year, month)[1])
             rql = ('Any B WHERE B is BlogEntry, B creation_date >= "%s", B creation_date <= "%s"'
                    % (firstday.strftime('%Y-%m-%d'), lastday.strftime('%Y-%m-%d')))
             url = self.build_url(rql=rql)
-            label = u'%s %s' % (_(MONTHNAMES[month-1]), year)
+            label = u'%s %s' % (_(calendar.MONTHNAMES[month-1]), year)
             box.append( BoxLink(url, label) )
         box.render(self.w)