plugin_wiki
□未翻訳
□翻訳中
□翻訳完了(Yota Ichino)
■レビュー(Omi Chiba)
plugin_wiki
plugin_wiki
wiki
免責条項: plugin_wikiはまだかなり頻繁に開発を行っており、従って、web2pyのコア関数と同じレベルの後方互換性を約束しません。
DISCLAIMER: plugin_wiki is still very much under development and therefore we do not promise backward compatibility to the same level as for web2py core functions.
plugin_wikiは強化されたプラグインです。この意味は複数の役立つコンポーネントを定義しアプリケーションの開発方法を変えるかもしれないということです:
plugin_wiki is a plugin on steroids. What we mean is that it defines multiple useful components and it may change the way you develop your applications:
plugin_wikiはここからダウンロードできます:
You can download it from
http://web2py.com/examples/static/web2py.plugin.wiki.w2p
plugin_wikiの背景には、ほとんどのアプリケーションがセミスタティックなページを含んでいるということです。これらは複雑なカスタムロジックを含んでいないページです。それらは構造化テキスト(ヘルプページを彷彿させるもの)、画像、音楽、ビデオ、crudフォームや標準コンポーネントのセット(コメント、タグ、図、案内図)、などを含んでいます。これらのページは公開されているか、ログインや他の認証制限を必要とします。これらのページはメニューでリンクされるかもしれませんし、ウィザードフォームを通じて辿りつけるだけかもしれません。plugin_wikiはあなたがよく利用するweb2pyアプリケーションへこの様なページを追加する簡単な方法を提供します。
The idea behind plugin_wiki is that most applications include pages that are semi-static. These are pages that do not include complex custom logic. They contain structured text (think of a help page), images, audio, video, crud forms, or a set of standard components (comments, tags, charts, maps), etc. These pages may be public, require login or have other authorization restrictions. These pages may be linked by a menu or only be reachable via wizard form.plugin_wiki provides an easy way to add pages that fit in this category to your regular web2py applications.
具体的にplugin_wikiが提供するのは:
In particular plugin_wiki provides:
plugin_wikiのウィジェット
widget in plugin_wiki
あなたのアプリケーションにページを追加したりスラグによって参照を許可するwikiの様なインターフェイス。これらのページ(wikiページとして参照される)はバージョンを持っておりデータベースに保存されます。
公開と非公開ページ(ログインを要求)。ページがログインを要求するなら、ユーザが特別なグループメンバーシップを持つことを要求するでしょう。
3段階:1,2,3. レベル1はテキスト、画像、音楽と動画だけを含むページです。レベル2はウィジェット(wikiページに組み込められる前述で定義されたコンポーネント)を含むページです。レベル3はweb2pyのテンプレートコードも含めることができるページです。
markmin構文かWYSIWYGエディタを選択してHTMLを編集できます。
ウィジェットコレクション: コンポーネントとして実装されていて、セルフドキュメント化されおり、普通のweb2pyビューに通常のコンポーネントとして埋め込まれたり、単純な構文でwikiページに埋め込まれたりできます。
プラグイン(例えば、実行するべきプラグインコードの定義、カスタマイズメニュー、他)のカスタマイズに使われる特別なページ(meta-code、meta-menu、他.)の設定。
A wiki-like interface that allows to add pages to your app and reference them by a slug. These pages (which we will refer to as wiki pages) have versions and are stored in the database.
Public and private pages (require login). If a page requires login, it may also require that the user have a particular group membership.
Three levels: 1,2,3. At level 1, pages can only include text, images, audio and video. At level 2, pages can also include widgets (these are components as defined in the previous section that can be embedded in wiki pages). At level 3, pages can also include web2py template code.
A choice of editing pages with the markmin syntax or in HTML using a WYSIWYG editor.
A collection of widgets: implemented as components, they are self-documenting and can be embedded as regular components in normal web2py views or, using a simplified syntax, into wiki pages.
A set of special pages (meta-code, meta-menu, etc.) that can be used to customize the plugin (for example define code the plugin should run, customize the menu, etc.)
plugin_wikiを加えたwelcomeアプリケーションはブログのような簡単なWebアプリケーションを構築するための適切な開発環境と考えることができます。
The welcome app plus the plugin_wiki can be thought of as a development environment in itself that is suitable for building simple web applications such as a blog.
ここからはplugin_wikiをwelcome雛形アプリケーションのコピーへ適用します。
From here on we will assume the plugin_wiki is applied to a copy of the welcomescaffolding app.
始めに、プラグインをインストールするとpagesと呼ばれる新しいメニューアイテムが追加されることに注意してください。
The first thing you notice after installing the plugin is that it adds a new menu item calledpages.
メニューアイテムpagesをクリックするとプラグインアクションにリダイレクトされます:
Click on the pages menu item and you will be redirected to the plugin action:
プラグインのインデックスページはプラグイン自身を使い作成されたページ一覧を表示し、slugを選択することで新規ページを作成することができます。homeページを作ってみましょう。ここにリダイレクトされます。
The plugin index page lists the pages created using the plugin itself and allows you to create new ones by choosing a slug. Try creating a home page. You will be redirected to
http://127.0.0.1:8000/myapp/plugin_wiki/page/home
create pageをクリックし内容を編集します。
Click on create page to edit its content.
デフォルトで、プラグインはレベル3になっており、ページのコードと同等にウィジェットの挿入もできることを意味しています。デフォルトではページ内容を表現するためにmarkmin構文を使用しています。
By default, the plugin is at level 3, which means you can insert widgets as well as code in pages. By default it uses the markmin syntax to describe the page content.
Markmin構文
markmin構文の代表的なものを示します:
Here is a primer for the markmin syntax:
このように書くことで他のページへのリンクを追加できます。
You can add links to other pages with
1.
[[mylink name page:slug]]
もしページが存在していない場合、そのページを作成するかを尋ねられます。
If the page does not exist, you will be asked to create one.
編集ページはページに添付ファイル(つまり静的ファイル)を追加できます。
The edit page allows you to add attachments to pages (i.e. static files)
このように書くことで静的ファイルへリンクできます。
and you can link to them as
1.
[[mylink name attachment:3.png]]
またはページに埋め込むこともできます。
or embed them with
1.
[[myimage attachment:3.png center 200px]]
画像サイズ(200px)はオプションです。centerはオプションではありませんがleftやrightで置き換えられます。
The size (200px) is optional. center is not optional but it may be replaced by left or right.
引用テキストを組込めます。
You can embed blockquoted text with
1.
2.
3.
-----
this is blockquoted
-----
テーブルも同様に組込めます
as well as tables
1.
2.
3.
4.
5.
-----
0 | 0 | X
0 | X | 0
X | 0 | 0
-----
そして逐語的なテキスト
and verbatim text
1.
2.
3.
``
verbatim text
``
オプションで-----か``の一番最後に:クラスを追加ることもできます。引用テキストやテーブルでは、タグのクラスクラスに変換されます。例えば:
You can also prepend a optional :class to the final ----- or the final ``. For blockquoted text and tables it will be translated in the class of the tag, for example:
1.
2.
3.
-----
test
-----:abc
この様に反映されます
renders as
1.
<blockquote class="abc">test</blockquote>
逐語的なテキストのためクラスは異なるタイプの組込みコンテンツとして使用されます。
For verbatim text the class can be used to embed content of different types.
例えば、code_languageで言語を明確にすることでシンタックスハイライトされたコードを組込めます。
You can, for example, embed code with syntax highlighting by specifying the language with:code_language
1.
2.
3.
``
def index(): return 'hello world'
``:code_python
ウィジェットを組み込めます:
You can embed widgets:
1.
2.
3.
4.
5.
``
name: widget_name
attribute1: value1
attribute2: value2
``:widget
編集ページから、"widget builder"をクリックし、リストからウィジェットフォームを対話的に追加できます:
From the edit page you can click on "widget builder" to insert widgets from a list, interactively:
(ウィジェットのリストについては次のサブセクションを見てください)。
(for a list of widgets see the next subsection).
web2pyテンプレート言語のコードを組み込むこともできます:
You can also embed web2py template language code:
1.
2.
3.
``
{{for i in range(10):}}<h1>{{=i}}</h1>{{pass}}
``:template
ページの権限
ページを編集するときは次のフィールドを使用します:
When editing a page you will find the following fields:
active(デフォルトはTrue)。もしページが有効でないなら、訪問者にアクセスさせません(たとえパブリックでも)。
public(デフォルトはTrue)。ページが有効なら、ログイン無しで訪問者はアクセスできます。
Role(デフォルトはNone)。ページにロールがあれば、ページはログインやロールに対応するグループメンバーの訪問者がアクセス可能となります。
active (defaults to True). If a page is not active, it will not be accessible to visitors (even if public).
public (defaults to True). If a page is public, it can be accessed by visitors without logging in.
Role (defaults to None). If a page has a role, the page can be accessed only by visitors who are logged in and are members of the group with the corresponding role.
スペシャルページ
plugin_wikiのメニュー
menu in plugin_wiki
meta-menuはメニューを含みます。ページが存在していなかったら、web2pyは"models/menu.py"のresponse.menudefined定義を使用します。meta-menuページの内容はメニューを上書きします。構文は次のようになります:
:meta-menu contains the menu. If this page does not exist, web2py uses the response.menudefined in "models/menu.py". The content of the meta-menu page overrides the menu. The syntax is the following:
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
Item 1 Name http://link1.com
Submenu Item 11 Name http://link11.com
Submenu Item 12 Name http://link12.com
Submenu Item 13 Name http://link13.com
Item 2 Name http://link1.com
Submenu Item 21 Name http://link21.com
Submenu Item 211 Name http://link211.com
Submenu Item 212 Name http://link212.com
Submenu Item 22 Name http://link22.com
Submenu Item 23 Name http://link23.com
インデントはサブメニュー構造化させるためです。それぞれのアイテムはテキスト、その後にリンクで構成されます。リンクはpage:slugにできます。Noneリンクはどのページにもリンクしません。余計なスペースは無視されます。
where the indentation determines the submenu structure. Each item is composed of the text of the menu item followed by a link. A link can be page:slug. A link None does not link to any page. Extra spaces are ignored.
他の例です:
Here is another example:
1.
2.
3.
4.
5.
6.
Home page:home
Search Engines None
Yahoo http://yahoo.com
Google http://google.com
Bing http://bing.com
Help page:help
次のように表示されます:
This renders as follows:
meta-menu
meta-codeinxx
meta-header
meta-sidebar
meta-footer
meta-codeは別のスペシャルページであり、web2pyのコードを含まなくてはなりません。これはあなたのモデルを拡張したもので、実際ここにモデルコードも書けます。"models/plugin_wiki.py"コードが実行されるときにそれが実行されます。
meta-code is another special page and it must contain web2py code. This is an extension of your models, and in fact you can put model code here. It is executed when "models/plugin_wiki.py" code is executed.
meta-codeでテーブルを定義できます。
You can define tables in meta-code.
例えば、meta-codeにこのコードを書くことで単純な"friends"テーブルを定義できます:
For example, you can create a simple table "friends" by placing this in meta-code:
そして、 次のコードを選択するページに組み込むことでfriend-managementインターフェイスを製作できます:
and you can create a friend-management interface with by embedding in a page of your choice the following code:
jqGrid
CRUD
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
# List of friends
``
name: jqgrid
table: friend
``:widget
# New friend
``
name: create
table: friend
``:widget
"List of fiends"と"New friend"という2つのヘッダーページ(#で開始) があります。ページはfriendsの一覧を表示するjqgridウィジェットと新たなfriendを追加するウィジェットを生成するcrudという2つのウィジェット(ヘッダーに対応する) を持ちます。
The page has two headers (starting with #): "List of friends" and "New friend". The page contains two widgets (under the corresponding headers): a jqgrid widget that lists friends and a crud create widget to add a new friend.
meta-header, meta-footer, meta-sidebarは"welcome/views/layout.html"のデフォルトレイアウトでは使用されません。これらを使用したい場合、adminを使い"layout.html"を編集し適当な場所に次のタグを置きましょう:
meta-header, meta-footer, meta-sidebar are not used by the default layout in "welcome/views/layout.html". If you want to use them, edit "layout.html" using admin (or the shell) and place the following tags in the appropriate places:
1.
2.
3.
{{=plugin_wiki.embed_page('meta-header') or ''}}
{{=plugin_wiki.embed_page('meta-sidebar') or ''}}
{{=plugin_wiki.embed_page('meta-footer') or ''}}
この方法で、これらのページの内容はレイアウトのヘッダー、サイドバーやフッターに書かれます。
In this way, the content of those pages will show up in the header, sidebar and footer in the layout.
plugin_wikiの設定
"models/db.py"の他のプラグインと同様で下記のように書けます。
As with any other plugins in "models/db.py" you can do
1.
2.
3.
4.
5.
6.
from gluon.tools import PluginManager
plugins = PluginManager()
plugins.wiki.editor = auth.user.email == mail.settings.sender
plugins.wiki.level = 3
plugins.wiki.mode = 'markmin' or 'html'
plugins.wiki.theme = 'ui-darkness'
それぞれ
where
editorがtrueの場合、現在のログインユーザがplugin_wikiページを編集するために認証されます
level権限: ページ編集は1を、ウィジェットをページに埋め込むには2を、コードの埋め込みには3を指定してください
modeは"markmin"エディタかWYSIWYG"html"エディタのどちらを使用するかを決定します
WYSIWYG
themeはjQuery UIテーマの名前を指定します。デフォルトで"ui-darkness"のみがインストールされています
editor is true if the current logged-in user is authorized to edit plugin_wiki pages
level is the permission: 1 to edit regular pages, 2 to embed widgets in pages, 3 to embed code
mode determines whether to use a "markmin" editor or a WYSIWYG "html" editor.
WYSIWYG
theme is the name of the required jQuery UI Theme. By default only the color-neutral "ui-darkness" is installed.
ここにテーマを追加してください。
You can add themes here:
1.
static/plugin_wiki/ui/%(theme)s/jquery-ui-1.8.1.custom.css
現行のウィジェット
どのウィジェットもplugin_wikiページや普段使用するweb2pyテンプレートに組込むことができます。
Each widget can be embedded both in plugin_wiki pages and in normal web2py templates.
例えば、plugin_wikiにYouTubeビデオを組み込めます。
For example, to embed a YouTube video in a plugin_wiki page, you can do
`` name: youtube code: l7AWnfFRc7g ``:widget
同じことをweb2pyビューでも可能です:
or to embed the same widget in a web2py view, you can do:
1.
{{=plugin_wiki.widget('youtube',code='l7AWnfFRc7g')}}
どちらの場合でも、この様な結果になります:
In either case, this is the output:
デフォルト値が無いウィジェットの引数が必要です。
Widget arguments that do not have a default value are required.
全ての現行ウィジェットのリストです:
Here is a list of all current widgets:
1.
read(table,record_id=None)
レコードを読み込み、表示します
Reads and displays a record
table is the name of a table
record_id is a record number
1.
2.
create(table,message='',next='',readonly_fields='',
hidden_fields='',default_fields='')
レコード生成フォームとして表示
Displays a record create form
tableはテーブル名
messageレコードが生成された後に表示するためのメッセージ
nextはリダイレクトする場所で、例として"page/index/[id]"
readonly_fieldsはフィールドをカンマで区切ったリスト
hidden_fieldsはフィールドをカンマで区切ったリスト
default_fieldsは"fieldname=value"をカンマで区切ったリスト
table is the name of a table
message is a the message to be displayed after record is created
next is where to redirect, example "page/index/[id]"
readonly_fields is a list of comma separated fields
hidden_fields is a list of comma separated fields
default_fields is a list of comma separated "fieldname=value"
1.
2.
update(table,record_id='',message='',next='',
readonly_fields='',hidden_fields='',default_fields='')
レコードアップデートフォームを表示
Displays a record update form
tableはテーブル名
record_idはアップデートされるレコードか{{=request.args(-1)}}
messageはレコードが生成された後に表示されるメッセージ
nextはリダイレクトする場所で、例として"page/index/[id]"
readonly_fieldsはフィールドをカンマで区切ったリスト
hidden_fieldsはフィールドをカンマで区切ったリスト
default_fieldsは"fieldname=value"をカンマで区切ったリスト
table is the name of a table
record_id is he record to be updated or {{=request.args(-1)}}
message is a the message to be displayed after record is created
next is where to redirect, example "page/index/[id]"
readonly_fields is a list of comma separated fields
hidden_fields is a list of comma separated fields
default_fields is a list of comma separated "fieldname=value"
1.
select(table,query_field='',query_value='',fields='')
テーブルに全レコードをリスト
Lists all records in the table
tableはテーブル名
query_fieldとquery_valueについて、クエリquery_field == query_valueによりレコードをフィルタリングします。
fieldsは提示されたカンマで区切ったフィールドのリスト
table is the name of a table
query_field and query_value if present will filter records by according to the queryquery_field == query_value
fields is a list of comma separate fields to be displayed
1.
search(table,fields='')
レコードを選択するためのウィジェット
Widgets for selecting records
tableはテーブル名
fieldsは提示されたカンマで区切ったフィールドのリスト
table is the name of a table
fields is a list of comma separated fields to be displayed
jqGrid
1.
2.
jqgrid(table,fieldname=None,fieldvalue=None,col_widths='',
colnames=None,_id=None,fields='',col_width=80,width=700,height=300)
jqGridプラグインの組込み
Embeds a jqGrid plugin
tableはテーブル名
fieldname, fieldvalueaはオプションフィルター(fieldname==fieldvalue)
col_widthsはカラムの幅
colnamesは表示されたコラム名のリスト
_idはjqGridを含むDIVタグの"id"
fieldsは表示されたカラムのリスト
col_widthはカラムの幅のデフォルト値
heightはjqGridの高さ
widthはjqGridの幅
table is the table name
fieldname, fieldvalue are an optional filter (fieldname==fieldvalue)
col_widths is the width of each column
colnames is a list of column names that are displayed
_id is the "id" of the DIV that contains the jqGrid
fields is a list of columns to be displayed
col_width is the default width of columns
height is the height of the jqGrid
width is the width of the jqGrid
一度plugin_wikiをインストールしたら、他のビューにもjqGridを簡単に使用できます。使用例(fk_id==47でyrtableをフィルタリングしたものを表示します)
Once you have the plugin_wiki installed, you can easily use the jqGrid in your other views too. Example usage (displays yrtable filtered by fk_id==47):
1.
2.
{{=plugin_wiki.widget('jqgrid','yrtable','fk_id',47,'70,150',
'Id,Comments',None,'id,notes',80,300,200)}}
latex
1.
latex(expression)
LaTeXを組込むためにGoogle charting APIを使用します
Uses Google charting API to embed LaTeX
pie chart
1.
pie_chart(data='1,2,3',names='a,b,c',width=300,height=150,align='center')
円グラフを組込みます
Embed a pie chart
dataはコンマで区切られた値のリスト
namesはラベルをカンマで区切ったリスト(データアイテム内の1つ)
widthは画像の幅
heightは画像の高さ
alignは画像の位置を決定
data is a list of comma separated values
names is a list of comma separated labels (one for data item)
width is the width of the image
height is the height of the image
align determines the alignment of the image
bar chart
1.
bar_chart(data='1,2,3',names='a,b,c',width=300,height=150,align='center')
棒グラフを組み込むためにGoogle charting APIを使用します
Uses Google charting API to embed a bar chart
dataは値をカンマで区切ったリスト
namesはラベルをカンマで区切ったリスト(データアイテム内の1つ)
widthは画像の幅
heightは画像の高さ
alignは画像の位置を決定
data is a list of comma separated values
names is a list of comma separated labels (one for data item)
width is the width of the image
height is the height of the image
align determines the alignment of the image
slideshow
1.
slideshow(table, field='image', transition='fade', width=200, height=200)
スライドショーを組込みます。テーブルから画像を取得します。
Embeds a slideshow. It gets the images from a table.
tableはテーブル名
fieldはフィールドを画像を含むテーブルにアップロード
transitionは画像が移り変わる際のエフェクトを決定、(例, フェード、他)
widthは画像の幅
heightは画像の高さ
table is the table name
field is the upload field in the table that contains images
transition determines the type of transition, e.g. fade, etc.
width is the width of the image
height is the height of the image
YouTube
1.
youtube(code, width=400, height=250)
YouTubeビデオの組込み(コードで)
Embeds a YouTube video (by code)
codeはビデオのコード
widthはビデオの幅
heightはビデオの高さ
code is the code of the video
width is the width of the image
height is the height of the image
Vimeo
1.
vimeo(code, width=400, height=250)
Vimeoビデオの組込み(コードで)
Embeds a Vimeo video (by code)
codeはビデオのコード
widthはビデオの幅
heightはビデオの高さ
code is the code of the video
width is the width of the image
height is the height of the image
flash mediaplayer
1.
mediaplayer(src, width=400, height=250)
メディアファイル(Flashビデオやmp3ファイルなど)を組込みます
Embeds a media file (such as Flash video or an mp3 file)
srcはビデオのソース
widthは画像の幅
heightは画像の高さ
src is the src of the video
width is the width of the image
height is the height of the image
comments
1.
comments(table='None', record_id=None)
Commentsページにテーブル/レコードへリンクされたコメントを組み込みます
Embeds comments in the page Comments can be linked to a table and/or a record
tableはテーブル名
record_idはレコードのid
table is the table name
record_id is the id of the record
tags
1.
tags(table='None', record_id=None)
tagsページにテーブル/レコードへリンクされたタグを組込みます
Embeds tags in the page tags can be linked to a table and/or a record
tableはテーブル名
record_idはレコードのid
table is the table name
record_id is the id of the record
tag cloud
1.
tag_cloud()
タグクラウドを組込みます
Embeds a tag cloud
Google map
1.
map(key='....', table='auth_user', width=400, height=200)
テーブルからGoogle map上に位置取得したものを組込みます
Embeds a Google map Gets points on the map from a table
keyiはgoogle map apiキー(127.0.0.1でデフォルト動作)
tableはテーブル名
widthは地図の幅
heightは地図の高さ
key is the google map api key (default works for 127.0.0.1)
table is the table name
width is the map width
height is the map height
1.
2.
1.
The table must have columns: latitude, longitude and map_popup.
When clicking on a dot, the map_popup message will appear.
iframe(src, width=400, height=300)
<iframe></iframe>にページを組込みます
Embeds a page in an <iframe></iframe>
1.
load_url(src)
LOAD関数を使ってURLの内容を読み込みます
Loads the content of the url using the LOAD function
1.
load_action(action, controller='', ajax=True)
LOAD関数を使うURL(request.application, controller, action)の内容を読み込みます
Loads the content of URL(request.application, controller, action) using the LOAD function
ウィジェットの拡張
Extending Widgets
"models/plugin_wiki_"の後に任意の名前をつけたファイルを新しく生成することでplugin_wikiへのウィジェットを追加でき、それは以下のようなコードを含んだファイルです:
Widgets to plugin_wiki can be added by creating a new model file called "models/plugin_wiki_"name where name is arbitrary and the file contains something like:
1.
2.
3.
4.
5.
6.
7.
class PluginWikiWidgets(PluginWikiWidgets):
@staticmethod
def my_new_widget(arg1, arg2='value', arg3='value'):
"""
document the widget
"""
return "body of the widget"
1行目はウィジェットのリストを拡張することを示します。クラスの中に、必要なだけ関数を定義できます。アンダースコアで始まる関数は除き、それぞれの静的関数は新しいウィジェットです。関数はデフォルト値の有無に関わらない任意の数を取ります。Markmin構文を使い関数のドキュメントを書きましょう。
The first line states that you are extending the list of widgets. Inside the class, you can define as many functions as needed. Each static function is a new widget, except for functions that start with underscores. The function can take an arbitrary number of arguments which may or not have default values. The docstring of the function must document the function using the markmin syntax itself.
plugin_wikiページにウィジェットが組込みまれる場合、引数は文字列でウィジェットに渡されます。これが意味するのは、ウィジェット関数はどの引数も文字列で受け取り、最終的には必要な形式に変換できるようにしなくてはなりません。どの形式に変換する必要があるかはdocstringでドキュメントしておくようにしてください。
When widgets are embedded into plugin_wiki pages, arguments will be passed to the widget as strings. This means the widget function must be able to accept strings for every argument and eventually convert them into the required representation. You can decide what the string representation must be - just make sure this is documented in the docstring.
ウィジェットはweb2pyヘルパーの文字列を返すことができます。後述する場合は、それらは.xml()でシリアライズされています。
The widget can return a string of web2py helpers. In this latter case they will be serialized using .xml().
新しいウィジェットはグローバル名前空間で他の宣言済み変数にアクセスできることに注意してください。
Notice how the new widget can access any variable declared in the global namespace.
例として、このチャプターの始めに製作した"contact/ask"フォームを表示する新しいウィジェットを製作しましょう。これは以下のコードが書かれた"models/plugin_wiki_contact"ファイルを生成することで可能です。
As an example, we are going to create a new widget that display the "contact/ask" form created at the beginning of this chapter. This can be done by creating a file "models/plugin_wiki_contact" that contains:
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.
class PluginWikiWidgets(PluginWikiWidgets):
@staticmethod
def ask(email_label='Your email', question_label='question'):
"""
This plugin will display a contact us form that allows
the visitor to ask a question.
The question will be emailed to you and the widget will
disappear from the page.
The arguments are
- email_label: the label of the visitor email field
- question_label: the label of the question field
"""
form=SQLFORM.factory(
Field('your_email', requires=IS_EMAIL(), label=email_label),
Field('question', requires=IS_NOT_EMPTY()), label=question_label)
if form.accepts(request.vars,session):
if mail.send(to='admin@example.com',
subject='from %s' % form.vars.your_email,
message = form.vars.question):
command="jQuery('#%s').hide()" % div_id
response.flash = 'Thank you'
response.js = "jQuery('#%s').hide()" % request.cid
else:
form.errors.your_email="Unable to send the email"
return form.xml()
response.render(...)関数がウィジェットにより明示的に呼ばれない限り、plugin_wikiウィジェットはレンダリングされません。
plugin_wiki widgets are not rendered by a view unless theresponse.render(...) function is called explicitly by the widget.