1 # custom application views |
1 # custom application views |
|
2 from calendar import monthrange |
|
3 from datetime import date |
2 |
4 |
3 from mx.DateTime import DateTime |
5 from cubicweb.web.views import baseviews, boxes, calendar |
4 |
|
5 from cubicweb.web.views import baseviews |
|
6 from cubicweb.web.views.boxes import BoxTemplate |
|
7 from cubicweb.web.views.calendar import MONTHNAMES |
|
8 from cubicweb.web.htmlwidgets import BoxLink, BoxWidget |
6 from cubicweb.web.htmlwidgets import BoxLink, BoxWidget |
9 |
7 |
10 _ = unicode |
8 _ = unicode |
11 |
9 |
12 |
10 |
13 class BlogEntryPrimaryView(baseviews.PrimaryView): |
11 class BlogEntryPrimaryView(baseviews.PrimaryView): |
14 accepts = ('BlogEntry',) |
12 accepts = ('BlogEntry',) |
15 |
13 |
16 def cell_call(self, row, col): |
14 def cell_call(self, row, col): |
17 entity = self.entity(row, col) |
15 entity = self.entity(row, col) |
18 self.w(u'<h1>%s</h1>' % entity.dc_title()) |
16 self.w(u'<h1>%s</h1>' % entity.dc_title()) |
19 entity.view('metadata', w=self.w) |
17 entity.view('metadata', w=self.w) |
20 self.w(entity.printable_value('text')) |
18 self.w(entity.printable_value('text')) |
21 |
|
22 |
19 |
23 class BlogArchiveBox(BoxTemplate): |
20 |
|
21 class BlogArchiveBox(boxes.BoxTemplate): |
24 """side box usually displaying some related entities in a primary view""" |
22 """side box usually displaying some related entities in a primary view""" |
25 id = 'blog_archives_box' |
23 id = 'blog_archives_box' |
26 title = _('blog archives') |
24 title = _('blog archives') |
27 |
25 |
28 def call(self, **kwargs): |
26 def call(self, **kwargs): |
35 year, month = blogdate.year, blogdate.month |
33 year, month = blogdate.year, blogdate.month |
36 if (year, month) not in blogmonths: |
34 if (year, month) not in blogmonths: |
37 blogmonths.append( (year, month) ) |
35 blogmonths.append( (year, month) ) |
38 box = BoxWidget(_('Blog archives'), id=self.id) |
36 box = BoxWidget(_('Blog archives'), id=self.id) |
39 for year, month in blogmonths: |
37 for year, month in blogmonths: |
40 firstday = DateTime(year, month, 1) |
38 firstday = date(year, month, 1) |
41 lastday = DateTime(year, month, firstday.days_in_month) |
39 lastday = date(year, month, monthrange(year, month)[1]) |
42 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"' |
43 % (firstday.strftime('%Y-%m-%d'), lastday.strftime('%Y-%m-%d'))) |
41 % (firstday.strftime('%Y-%m-%d'), lastday.strftime('%Y-%m-%d'))) |
44 url = self.build_url(rql=rql) |
42 url = self.build_url(rql=rql) |
45 label = u'%s %s' % (_(MONTHNAMES[month-1]), year) |
43 label = u'%s %s' % (_(calendar.MONTHNAMES[month-1]), year) |
46 box.append( BoxLink(url, label) ) |
44 box.append( BoxLink(url, label) ) |
47 box.render(self.w) |
45 box.render(self.w) |
48 |
46 |
49 |
47 |
50 |
48 |