1 # custom application views |
1 # custom application views |
2 from calendar import monthrange |
|
3 from datetime import date |
2 from datetime import date |
4 |
3 |
|
4 from cubicweb.utils import last_day |
5 from cubicweb.web.views import baseviews, boxes, calendar |
5 from cubicweb.web.views import baseviews, boxes, calendar |
6 from cubicweb.web.htmlwidgets import BoxLink, BoxWidget |
6 from cubicweb.web.htmlwidgets import BoxLink, BoxWidget |
7 |
7 |
8 _ = unicode |
8 _ = unicode |
9 |
9 |
34 if (year, month) not in blogmonths: |
34 if (year, month) not in blogmonths: |
35 blogmonths.append( (year, month) ) |
35 blogmonths.append( (year, month) ) |
36 box = BoxWidget(_('Blog archives'), id=self.id) |
36 box = BoxWidget(_('Blog archives'), id=self.id) |
37 for year, month in blogmonths: |
37 for year, month in blogmonths: |
38 firstday = date(year, month, 1) |
38 firstday = date(year, month, 1) |
39 lastday = date(year, month, monthrange(year, month)[1]) |
39 lastday = last_day(firstday) |
40 rql = ('Any B WHERE B is BlogEntry, B creation_date >= "%s", B creation_date <= "%s"' |
40 rql = ('Any B WHERE B is BlogEntry, B creation_date >= "%s", B creation_date <= "%s"' |
41 % (firstday.strftime('%Y-%m-%d'), lastday.strftime('%Y-%m-%d'))) |
41 % (firstday.strftime('%Y-%m-%d'), lastday.strftime('%Y-%m-%d'))) |
42 url = self.build_url(rql=rql) |
42 url = self.build_url(rql=rql) |
43 label = u'%s %s' % (_(calendar.MONTHNAMES[month-1]), year) |
43 label = u'%s %s' % (_(calendar.MONTHNAMES[month-1]), year) |
44 box.append( BoxLink(url, label) ) |
44 box.append( BoxLink(url, label) ) |