author | Alexandre Fayolle <alexandre.fayolle@logilab.fr> |
Tue, 06 Apr 2010 20:54:35 +0200 | |
branch | stable |
changeset 5207 | 3ea2858e591d |
parent 4466 | 8b0ca7904820 |
child 5421 | 8167de96c523 |
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 |
4212
ab6573088b4a
update copyright: welcome 2010
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1977
diff
changeset
|
5 |
:copyright: 2001-2010 LOGILAB S.A. (Paris, FRANCE), license is LGPL v2. |
1977
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 |
|
4466
8b0ca7904820
moved generic datetime manipulation function to lgc
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
11 |
from logilab.common.date import last_day |
8b0ca7904820
moved generic datetime manipulation function to lgc
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
12 |
|
1546 | 13 |
from cubicweb.web.views import baseviews, boxes, calendar |
0 | 14 |
from cubicweb.web.htmlwidgets import BoxLink, BoxWidget |
15 |
||
16 |
_ = unicode |
|
17 |
||
18 |
||
19 |
class BlogEntryPrimaryView(baseviews.PrimaryView): |
|
20 |
accepts = ('BlogEntry',) |
|
1546 | 21 |
|
0 | 22 |
def cell_call(self, row, col): |
2789
39712da6f397
R propagate deprecation of AppObject.entity()
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
1977
diff
changeset
|
23 |
entity = self.rset.get_entity(row, col) |
0 | 24 |
self.w(u'<h1>%s</h1>' % entity.dc_title()) |
25 |
entity.view('metadata', w=self.w) |
|
26 |
self.w(entity.printable_value('text')) |
|
1546 | 27 |
|
0 | 28 |
|
1546 | 29 |
class BlogArchiveBox(boxes.BoxTemplate): |
0 | 30 |
"""side box usually displaying some related entities in a primary view""" |
31 |
id = 'blog_archives_box' |
|
32 |
title = _('blog archives') |
|
33 |
||
34 |
def call(self, **kwargs): |
|
35 |
"""display a list of entities by calling their <item_vid> view |
|
36 |
""" |
|
37 |
_ = self.req._ |
|
38 |
rset = self.req.execute('Any CD ORDERBY CD DESC WHERE B is Blog, B creation_date CD') |
|
39 |
blogmonths = [] |
|
40 |
for (blogdate,) in rset: |
|
41 |
year, month = blogdate.year, blogdate.month |
|
42 |
if (year, month) not in blogmonths: |
|
43 |
blogmonths.append( (year, month) ) |
|
44 |
box = BoxWidget(_('Blog archives'), id=self.id) |
|
45 |
for year, month in blogmonths: |
|
1546 | 46 |
firstday = date(year, month, 1) |
1620 | 47 |
lastday = last_day(firstday) |
0 | 48 |
rql = ('Any B WHERE B is BlogEntry, B creation_date >= "%s", B creation_date <= "%s"' |
49 |
% (firstday.strftime('%Y-%m-%d'), lastday.strftime('%Y-%m-%d'))) |
|
50 |
url = self.build_url(rql=rql) |
|
1546 | 51 |
label = u'%s %s' % (_(calendar.MONTHNAMES[month-1]), year) |
0 | 52 |
box.append( BoxLink(url, label) ) |
53 |
box.render(self.w) |
|
54 |
||
55 |
||
56 |
||
57 |