author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Fri, 19 Jun 2009 15:54:55 +0200 | |
changeset 2127 | bc86aa68cc43 |
parent 1977 | 606923dff11b |
child 2789 | 39712da6f397 |
child 4212 | ab6573088b4a |
permissions | -rw-r--r-- |
0 | 1 |
# custom application views |
1977
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1620
diff
changeset
|
2 |
""" |
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1620
diff
changeset
|
3 |
|
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1620
diff
changeset
|
4 |
:organization: Logilab |
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1620
diff
changeset
|
5 |
:copyright: 2001-2009 LOGILAB S.A. (Paris, FRANCE), license is LGPL v2. |
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1620
diff
changeset
|
6 |
:contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr |
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1620
diff
changeset
|
7 |
:license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses |
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1620
diff
changeset
|
8 |
""" |
1546 | 9 |
from datetime import date |
0 | 10 |
|
1620 | 11 |
from cubicweb.utils import last_day |
1546 | 12 |
from cubicweb.web.views import baseviews, boxes, calendar |
0 | 13 |
from cubicweb.web.htmlwidgets import BoxLink, BoxWidget |
14 |
||
15 |
_ = unicode |
|
16 |
||
17 |
||
18 |
class BlogEntryPrimaryView(baseviews.PrimaryView): |
|
19 |
accepts = ('BlogEntry',) |
|
1546 | 20 |
|
0 | 21 |
def cell_call(self, row, col): |
22 |
entity = self.entity(row, col) |
|
23 |
self.w(u'<h1>%s</h1>' % entity.dc_title()) |
|
24 |
entity.view('metadata', w=self.w) |
|
25 |
self.w(entity.printable_value('text')) |
|
1546 | 26 |
|
0 | 27 |
|
1546 | 28 |
class BlogArchiveBox(boxes.BoxTemplate): |
0 | 29 |
"""side box usually displaying some related entities in a primary view""" |
30 |
id = 'blog_archives_box' |
|
31 |
title = _('blog archives') |
|
32 |
||
33 |
def call(self, **kwargs): |
|
34 |
"""display a list of entities by calling their <item_vid> view |
|
35 |
""" |
|
36 |
_ = self.req._ |
|
37 |
rset = self.req.execute('Any CD ORDERBY CD DESC WHERE B is Blog, B creation_date CD') |
|
38 |
blogmonths = [] |
|
39 |
for (blogdate,) in rset: |
|
40 |
year, month = blogdate.year, blogdate.month |
|
41 |
if (year, month) not in blogmonths: |
|
42 |
blogmonths.append( (year, month) ) |
|
43 |
box = BoxWidget(_('Blog archives'), id=self.id) |
|
44 |
for year, month in blogmonths: |
|
1546 | 45 |
firstday = date(year, month, 1) |
1620 | 46 |
lastday = last_day(firstday) |
0 | 47 |
rql = ('Any B WHERE B is BlogEntry, B creation_date >= "%s", B creation_date <= "%s"' |
48 |
% (firstday.strftime('%Y-%m-%d'), lastday.strftime('%Y-%m-%d'))) |
|
49 |
url = self.build_url(rql=rql) |
|
1546 | 50 |
label = u'%s %s' % (_(calendar.MONTHNAMES[month-1]), year) |
0 | 51 |
box.append( BoxLink(url, label) ) |
52 |
box.render(self.w) |
|
53 |
||
54 |
||
55 |
||
56 |