Personal tools
You are here: Home 清水川記 COREBlog2をPlone3で動かすための修正: portletのカレンダー
Document Actions

COREBlog2をPlone3で動かすための修正: portletのカレンダー


Plone-3.3.2 にアップグレードして公開 したときの課題として、 "COREBlog2のカレンダー表示が月変更出来ない" というものがありました。これを修正する方法が分かりました。

対象:COREBlog2_nightly.tgz (2008/10時点)
Plone:Plone-3.3.2

まず原因ですが、COREBlog2のポートレット表示用カレンダーは skins/COREBlog2/portlet_coreblogcalendar.pt というテンプレートで表示されます。ここで表示対象月を決めている変数が year, month なのですが、この変数の初期化時に options/year に年が設定されていないため、現在の日付を元にカレンダー表示されてしまっているようです。ここで使われている options 変数は skins/COREBlog2/archives.py の最終行で cbarchive_view.pt に渡されていますが、これがどうやらportletには渡ってこないようです。(どこかにこの仕様変更について情報がないか探してみたのですが、見あたりませんでした)

この問題の修正の方針は3つあります。

  1. Plone3向けのportletを書く
  2. portlet_coreblogcalendar.pt 内でoptionsに頼らずにyear,monthを取得する
  3. archives.py でrequest変数にyear,monthを設定しておいてportlet_coreblogcalendar.ptで使う

今回は2の方法で対応してみます。

2. portlet_coreblogcalendar.pt 内でoptionsに頼らずにyear,monthを取得する

まず、 portlet_coreblogcalendar.pt をカスタマイズフォルダ(portal_skins/custom)に複製します。そして以下のように修正します:

 tal:define="DateTime python:modules['DateTime'].DateTime;
             current python:DateTime();
-            yearmonth here/getYearAndMonthToDisplay;
-            year options/year | python:yearmonth[0];
-            month options/month | python:yearmonth[1];
+            yearmonth python:here.cbcalendar_date() or here.getYearAndMonthToDisplay();
+            year python:yearmonth[0];
+            month python:yearmonth[1];
             prevMonthTime python:here.getPreviousMonth(month, year);
             nextMonthTime python:here.getNextMonth(month, year);

次に、上記の書き換えで呼び出されることになった cbcalendar_date はまだどこにも存在していないので、このスクリプトを用意します。portal_skins/customフォルダで "Script(Python)" を新規追加して、名前を 'cbcalendar_date' として以下の内容を記載します。

request = container.REQUEST
sub_traverse = request.ACTUAL_URL[len(request.URL):].strip('/').split('/')
isArchive = request.URL.split('/')[-1] == 'archives' and sub_traverse

if isArchive:
    
yearmonth = [
        
int(sub_traverse[0]),
        
int(sub_traverse[1]),
    
]
    
return yearmonth

else:
    
return None

これでカレンダーを次月、前月に遷移できるようになると思います。

Plone-3.3.2 にアップグレードして公開 Plone-3.3.2 にアップグレードして公開
Size 15548 - File type text/x-rst
Category(s)
Plone Plone
The URL to Trackback this entry is:
http://www.freia.jp/taka/blog/687/tbping

Re:COREBlog2をPlone3で動かすための修正: portletのカレンダー

Posted by akiko at Dec 03, 2009 09:48 AM

コメントを書いた後に発見しました。
(すごい!)
ありがとうございます、早速自分のサイトでも試してみます!

Re:COREBlog2をPlone3で動かすための修正: portletのカレンダー

Posted by akiko at Jun 30, 2010 02:19 PM

Plone3.3.5にしたら、WARNINGが出て、カレンダーポートレットの描画もうまくできませんでした。

yearmonth python:here.cbcalendar_date() or here.getYearAndMonthToDisplay();
を、
yearmonth python:here.cbcalendar_date() or context.restrictedTraverse('@@calendar_view').getYearAndMonthToDisplay();
に変えてみたら、動くようになりました。

また、前後の月は、下記のようにしてみました。
prevMonthTime python:context.restrictedTraverse('@@calendar_view').getPreviousMonth(month, year);
nextMonthTime python:context.restrictedTraverse('@@calendar_view').getNextMonth(month, year);

正しいのかどうかは判らないのですが...。

Add comment

You can add a comment by filling out the form below. Plain text formatting.

(Required)
(Required)
(Required)

« July 2010 »
Mo Tu We Th Fr Sa Su
      1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31  
About this blog
Zope, Python, FreeBSD, その他色々について。つまり日記か。
Categories
Agile(XP) (0)
Event (10)
Pattern (0)
その他 (10)
Zope (11)
Memo (0)
(3)
python (17)
Programming (0)
Game (0)
OO (0)
Unix (0)
WZ (0)
work (0)
Plone (11)
Windows (1)
IT-PC (4)
自転車 (0)
TurboGears (0)
ダーツ (0)
JavaScript (0)
旅行 (0)
Web (3)
セキュリティー (1)
Django (0)
LDAP (0)
データベース (0)
vi/vim/gvim (0)
C/C++ (0)
ボドゲ (0)
RoR (2)
pyspa (1)
スタトレ (0)