author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Mon, 10 May 2010 15:14:47 +0200 | |
branch | stable |
changeset 5504 | 97ed78b54956 |
parent 5424 | 8ecbcbff9777 |
permissions | -rw-r--r-- |
0 | 1 |
# custom application views |
5421
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4466
diff
changeset
|
2 |
# copyright 2003-2010 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4466
diff
changeset
|
3 |
# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4466
diff
changeset
|
4 |
# |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4466
diff
changeset
|
5 |
# This file is part of CubicWeb. |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4466
diff
changeset
|
6 |
# |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4466
diff
changeset
|
7 |
# CubicWeb is free software: you can redistribute it and/or modify it under the |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4466
diff
changeset
|
8 |
# terms of the GNU Lesser General Public License as published by the Free |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4466
diff
changeset
|
9 |
# Software Foundation, either version 2.1 of the License, or (at your option) |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4466
diff
changeset
|
10 |
# any later version. |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4466
diff
changeset
|
11 |
# |
5424
8ecbcbff9777
replace logilab-common by CubicWeb in disclaimer
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5421
diff
changeset
|
12 |
# CubicWeb is distributed in the hope that it will be useful, but WITHOUT |
5421
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4466
diff
changeset
|
13 |
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4466
diff
changeset
|
14 |
# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4466
diff
changeset
|
15 |
# details. |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4466
diff
changeset
|
16 |
# |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4466
diff
changeset
|
17 |
# You should have received a copy of the GNU Lesser General Public License along |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4466
diff
changeset
|
18 |
# with CubicWeb. If not, see <http://www.gnu.org/licenses/>. |
1977
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1620
diff
changeset
|
19 |
""" |
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1620
diff
changeset
|
20 |
|
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1620
diff
changeset
|
21 |
""" |
1546 | 22 |
from datetime import date |
0 | 23 |
|
4466
8b0ca7904820
moved generic datetime manipulation function to lgc
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
24 |
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
|
25 |
|
1546 | 26 |
from cubicweb.web.views import baseviews, boxes, calendar |
0 | 27 |
from cubicweb.web.htmlwidgets import BoxLink, BoxWidget |
28 |
||
29 |
_ = unicode |
|
30 |
||
31 |
||
32 |
class BlogEntryPrimaryView(baseviews.PrimaryView): |
|
33 |
accepts = ('BlogEntry',) |
|
1546 | 34 |
|
0 | 35 |
def cell_call(self, row, col): |
2789
39712da6f397
R propagate deprecation of AppObject.entity()
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
1977
diff
changeset
|
36 |
entity = self.rset.get_entity(row, col) |
0 | 37 |
self.w(u'<h1>%s</h1>' % entity.dc_title()) |
38 |
entity.view('metadata', w=self.w) |
|
39 |
self.w(entity.printable_value('text')) |
|
1546 | 40 |
|
0 | 41 |
|
1546 | 42 |
class BlogArchiveBox(boxes.BoxTemplate): |
0 | 43 |
"""side box usually displaying some related entities in a primary view""" |
44 |
id = 'blog_archives_box' |
|
45 |
title = _('blog archives') |
|
46 |
||
47 |
def call(self, **kwargs): |
|
48 |
"""display a list of entities by calling their <item_vid> view |
|
49 |
""" |
|
50 |
_ = self.req._ |
|
51 |
rset = self.req.execute('Any CD ORDERBY CD DESC WHERE B is Blog, B creation_date CD') |
|
52 |
blogmonths = [] |
|
53 |
for (blogdate,) in rset: |
|
54 |
year, month = blogdate.year, blogdate.month |
|
55 |
if (year, month) not in blogmonths: |
|
56 |
blogmonths.append( (year, month) ) |
|
57 |
box = BoxWidget(_('Blog archives'), id=self.id) |
|
58 |
for year, month in blogmonths: |
|
1546 | 59 |
firstday = date(year, month, 1) |
1620 | 60 |
lastday = last_day(firstday) |
0 | 61 |
rql = ('Any B WHERE B is BlogEntry, B creation_date >= "%s", B creation_date <= "%s"' |
62 |
% (firstday.strftime('%Y-%m-%d'), lastday.strftime('%Y-%m-%d'))) |
|
63 |
url = self.build_url(rql=rql) |
|
1546 | 64 |
label = u'%s %s' % (_(calendar.MONTHNAMES[month-1]), year) |
0 | 65 |
box.append( BoxLink(url, label) ) |
66 |
box.render(self.w) |
|
67 |
||
68 |
||
69 |
||
70 |