adminの追加情報

□未翻訳

□翻訳中

□翻訳完了(細田謙二)

■レビュー(中垣健志)

adminの追加情報

管理インターフェイスはさらなる機能を提供します。ここではそれを簡単に見ていきます。

The administrative interface provides additional functionality that we briefly review here.

site

このページはインストールされたすべてのアプリケーションを列挙します。下部には2つのフォームがあります。

This page lists all installed applications. There are two forms at the bottom.

1つ目のフォームでは、名前を指定して新しいアプリケーションを作成することができます。

The first of them allows creating a new application by specifying its name.

2つ目のフォームでは、ローカルファイルまたはリモートURLから、既存のアプリケーションをアップロードすることができます。アプリケーションをアップロードする場合は、その名前を指定する必要があります。元の名前と同じにすることができますが、同じである必要はありません。これにより、同じアプリケーションの複数のコピーをインストールすることができます。たとえば、KPAXコンテンツ管理システムを次のURLからアップロードすることができます:

The second form allows uploading an existing application from either a local file or a remote URL. When you upload an application, you need to specify a name for it. This can be its original name, but does not need to be. This allows installing multiple copies of the same application. You can try, for example, to upload the KPAX content management system from:

http://web2py.com/appliances/default/download/app.source.221663266939....

アップロード可能なアプリケーションは、.tarファイル(古い形式)か.w2pファイル(新しい形式)です。後者は、tarファイルをgzip圧縮したものです。これらは、tar zxvf [ファイル名]として、手動で解凍することができます。ただし、その必要は全くありません。

Uploaded applications can be .tar files (old convention) and .w2p files (new convention). The latter ones are gzipped tar files. They can be uncompressed manually with tar zxvf [filename] although this is never necessary.

アップロードに成功すると、 web2pyはアップロードしたファイルのMD5チェックサムを表示します。これにより、ファイルがアップロード中に破損していないことを確認することができます。KPAXの名前がインストールされたアプリケーションのリストに表示されます。

Upon successful upload, web2py displays the MD5 checksum of the uploaded file. You can use it to verify that the file was not corrupted during upload. The KPAX name will appear in the list of installed applications.

adminにあるKPAXの名前をクリックすると、起動して稼働します。

Click on the KPAX name on admin to get it up and running.

アプリケーションファイルは、w2pファイル(gzip圧縮されたtar)として保存されます。しかし手動でtarやuntarを行う必要はありません。web2pyが代わりに行います。

Application files are stored as w2p files (tar gzipped), but you are not intended to tar or untar them manually; web2py does it for you.

各アプリケーションにおいて、siteページは次のことを可能にします:

For each application the site page allows you to:

  • アプリケーションのアンインストール

    • Uninstall the application.

  • aboutページ(下で説明します)への遷移

    • Jump to the about page (read below).

  • editページ(下で説明します)への遷移

    • Jump to the edit page (read below).

  • errorsページ(下で説明します)への遷移

    • Jump to the errors page (read below).

  • 一時ファイル(セッション、エラー、cache.diskファイル)のクリーンアップ。

    • Clean up temporary files (sessions, errors, and cache.disk files).

  • すべてのパック。これは、アプリケーションの完全なコピーを保持するtarファイルを返します。アプリケーションをパックする前に、一時ファイルをクリーンアップするべきです。

  • Pack all. This returns a tar file containing a complete copy of the application. We suggest that you clean up temporary files before packing an application.

  • アプリケーションをコンパイルします。エラーがない場合は、このオプションはすべてのコントローラ、ビュー、モデルをバイトコードとしてコンパイルします。ビューは木のように他のビューの中で拡張や組み込みができるため、バイトコンパイルする前に、すべてのコントローラに対するビューの木構造は1つのファイルに折りたたまれます。この実質的な効果としてバイトコンパイルされたアプリケーションは、テンプレートの解析や文字列の置換が実行時に行われなくなるため、より高速に動作します。

  • Compile the application. If there are no errors, this option will bytecode-compile all models, controllers and views. Because views can extend and include other views in a tree, before bytecode compilation, the view tree for every controller is collapsed into a single file. The net effect is that a bytecode-compiled application is faster, because there is no more parsing of templates or string substitutions occurring at runtime.

  • コンパイル結果のパック。このオプションは、バイトコードでコンパイルしたアプリケーションにのみ提示されます。これは、クローズドソースとしてソースコードを含まない状態でアプリケーションをパックできるようにします。ただし、Pythonは(他のプログラミング言語と同様に)技術的には逆コンパイルすることができます。そのためコンパイル結果では、ソースコードの完全な保護は行えません。しかし、逆コンパイルは難しく、違法行為です。

  • Pack compiled. This option is only present for bytecode-compiled applications. It allows packing the application without source code for distribution as closed source. Note that Python (as any other programming language) can technically be decompiled; therefore compilation does not provide complete protection of the source code. Nevertheless, decompilation can be difficult and can be illegal.

  • コンパイル結果の削除。これは単に、アプリケーションからバイトコードでコンパイルされた、モデル、ビュー、コントローラを削除します。アプリケーションがソースコードとともにパックされているか、ローカルで動くようになっている場合、バイトコードでコンパイルされたファイルを削除することはなんら弊害はなく、アプリケーションは動作し続けます。アプリケーションがコンパイル結果をパックしたファイルからインストールされた場合は、安全ではありません。元に戻すためのソースコードがないためで、アプリケーションはもはや動作しなくなります。

  • Remove compiled. It simply removes the byte-code compiled models, views and controllers from the application. If the application was packaged with source code or designed locally, there is no harm in removing the bytecode-compiled files, and the application will continue to work. If the application was installed form a packed compiled file, then this is not safe, because there is no source code to revert to, and the application will no longer work.

web2pyのadminサイトのページで利用できるすべての機能はまた、gluon/admin.pyモジュールで定義されているAPIを介してプログラム的にアクセスできます。単にPythonのシェルを開いて、このモジュールをインポートしてください。

All the functionality available from the web2py admin site page is also accessible programmatically via the API defined in the modulegluon/admin.py. Simply open a python shell and import this module.

about

aboutタブから、アプリケーションの説明とライセンス条項を編集することができます。これらは、それぞれに、applicationフォルダにあるABOUTとLICENCEファイルに書き込まれます。

The about tab allows editing the description of the application and its license. These are written respectively in the ABOUT and LICENSE files in the application folder.

これらのファイルに対してMARKMINかgluon.contrib.markdown.WIKIの構文を使用することができます。これは参照に説明されているとおりです。

You can use MARKMIN, or gluon.contrib.markdown.WIKI syntax for these files as described in ref.29 .

edit

本章では、すでにeditページを使用しています。ここでは、editページのさらなる数個の機能に注目します。

You have used the edit page already in this chapter. Here we want to point out a few more functionalities of the edit page.

  • 任意のファイル名をクリックすると、構文が強調表示された状態でファイルの内容を見ることができます。

    • If you click on any file name, you can see the contents of the file with syntax highlighting.

  • editをクリックすると、Webインタフェースを介してファイルを編集することができます。

    • If you click on edit, you can edit the file via a web interface.

  • deleteをクリックすると、ファイルを(完全に)削除することができます。

    • If you click on delete, you can delete the file (permanently).

  • testをクリックすると、web2pyはテストを走らせます。テストはPythonのdoctestを使って書かれます。そして、各関数は自分自身のテストを持ちます。

  • If you click on test, web2py will run tests. Tests are written by the developer using Python doctests, and each function should have its own tests.

  • Webインターフェースを介して、言語ファイルを追加し、全ての文字列を見いだすためにアプリをスキャンし、翻訳文字列を編集することができます。

    • You can add language files, scan the app to discover all strings, and edit string translations via the web interface.

  • 静的ファイルがフォルダとサブフォルダで構成されている場合、フォルダ階層はフォルダ名をクリックして切り替えることができます。

    • If the static files are organized in folders and subfolders, the folder hierarchy can be toggled by clicking on a folder name.

下の画像はwelcomeアプリケーションのテストページの出力を示しています。

The image below shows the output of the test page for the welcome application.

下の画像はwelcomeアプリケーションのlanguagesタブを示しています。

The image below show the languages tab for the welcome application.

下の画像は、どのように言語ファイルを編集するかを示しています。この場合、welcomeアプリケーションに対する"it"(イタリア)語のファイルです。

The image below shows how to edit a language file, in this case the "it" (Italian) language for the welcome application.

shell

editのコントローラタブの下にある"shell"リンクをクリックすると、web2pyはWebベースのPythonのシェルを開き、現在のアプリケーションに対するモデルを実行します。これにより対話的にアプリケーションを実行することができます。

If you click on the "shell" link under the controllers tab in edit, web2py will open a web based Python shell and will execute the models for the current application. This allows you to interactively talk to your application.

crontab

editのコントローラタブの下にはまた、"crontab"のリンクがあります。このリンクをクリックすると、web2pyのcrontabファイルを編集することができます。これはunixのcrontabと同じ構文に従いますが、unixには依存していません。実際、この機能はweb2pyだけを必要とし、Windows上でも動作します。これにより、スケジュールされた時間にバックグラウンドで起動する必要のあるアクションを登録することができます。詳細は、次章を参照してください。

Also under the controllers tab in edit there is a "crontab" link. By clicking on this link you will be able to edit the web2py crontab file. This follows the same syntax as the unix crontab but does not rely on unix. In fact, it only requires web2py, and it works on Windows. It allows you to register actions that need to be executed in background at scheduled times. For more information about this, see the next chapter.

errors

web2pyをプログラムするときは、ミスを犯すことやバグを取り込むことは避けられません。web2pyは2つの方法で支援します。1)すべての関数に対して、editページからブラウザで実行できるテストを作成することができます。2)エラーが明示されるとき、チケットが訪問者に発行され、エラーがログとして記録されます。

When programming web2py, you will inevitably make mistakes and introduce bugs. web2py helps in two ways: 1) it allows you to create tests for every function that can be run in the browser from the edit page; and 2) when an error manifests itself, a ticket is issued to the visitor and the error is logged.

以下のように、故意に画像アプリケーションにエラーを挿入します:

Intentionally introduce an error in the images application as shown below:

1.

2.

3.

4.

def index():

images = db().select(db.image.ALL,orderby=db.image.title)

1/0

return dict(images=images)

indexアクションにアクセスすると、次のようなチケットが表示されます:

When you access the index action, you get the following ticket:

管理者だけがこのチケットにアクセスすることができます:

Only the administrator can access the ticket:

チケットは、トレースバック、および、問題の原因となったファイルの内容を示します。エラーがビューの中で発生した場合は、web2pyはビューをHTMLからPythonコードに変換して表示します。これにより、簡単にファイルの論理構造を確認することができます。

The ticket shows the traceback, and the content of the file that caused the problem. If the error occurs in a view, web2py shows the view converted from HTML into Python code. This allows to easily identify the logical structure of the file.

なお、adminは、すべての場所で、構文がハイライトされたコードを表示します(たとえば、エラーレポートでは、web2pyのキーワードはオレンジ色で表示されます)。web2pyのキーワードをクリックすると、キーワードに関するドキュメントページにリダイレクトされます。

Notice that everywhere admin shows syntax-highlighted code (for example, in error reports, web2py keywords are shown in orange). If you click on a web2py keyword, you are redirected to a documentation page about the keyword.

アクションにある1/0というバグを修正し、そのバグをindexビューの中に埋め込んでみます:

If you fix the divide-by-zero bug in the index action and introduce one in the index view:

1.

2.

3.

4.

5.

6.

7.

8.

9.

{{extend 'layout.html'}}

<h1>Current Images</h1>

<ul>

{{for image in images:}}

{{1/0}}

{{=LI(A(image.title, _href=URL("show", args=image.id)))}}

{{pass}}

</ul>

すると、次のようなチケットを得ます:

you get the following ticket:

ここで、web2pyはHTMLのビューをPythonファイルに変換し、チケットに記述されるエラーは、元のビューファイルではなく、生成されたPythonコードを参照することに注意してください。

Note that web2py has converted the view from HTML into a Python file, and the error described in the ticket refers to the generated Python code and NOT to the original view file.

次のようなチケットを得ます:

you get the following ticket:

最初は混乱するかもしれません。しかし、実践的にはこれはデバッグを容易にします。なぜなら、Pythonのインデントがビューに埋め込まれた論理構造を強調するからです。

This may seem confusing at first, but in practice it makes debugging easier, because the Python indentation highlights the logical structure of the code that you embedded in the views.

コー​​ドは、同じページの下部に表示されます。

The code is shown at the bottom of the same page.

すべてのチケットは、各アプリケーションのerrorページにおいてadminの下に列挙されます:

All tickets are listed under admin in the errors page for each application:

Mercurial

ソースコードから実行していて、Mercurialのバージョン・コントロールのライブラリをインストールしている場合:

If you are running from source and you have the Mercurial version control libraries installed:

1.

easy_install mercurial

管理インターフェースは"mercurial"というメニュー項目を追加で表示します。これは、自動的にアプリケーションに対するローカルのMercurialリポジトリを作成します。そのページにある"commit"ボタンを押すと、現在のアプリケーションがコミットされます。

then the administrative interface shows one more menu item called "mercurial". It automatically creates a local Mercurial repository for the application. Pressing the "commit" button in the page will commit the current application.

この機能は実験的なもので、将来的に改善する予定です。

This feature is experimental and will be improved in the future.