2008年4月12日土曜日

Google App Engine 入門3



  helloworld のプログラムのソースを読む


APIs

Users API を利用している
 まず、 from google.appengine.api import users してから

     author = db.UserProperty()      author.nickname()

 Instance Methods として ncikname() と email() が用意されている。
 http://code.google.com/appengine/docs/users/userclass.html

Functions として以下がある
  • create_login_url(dest_url)
  • create_logout_url(dest_url)
  • get_current_user()
  • is_current_user_admin()
  http://code.google.com/appengine/docs/users/functions.html

Datastore API

Overview
The App Engine datastore is not a relational database
いわゆる RDBMS ではない。

An entity can be created by calling the constructor of the class,

class Pet(db.Model):
name = db.StringProperty(required=True) 
pet
= Pet(name="Fluffy",
のように Entiy を定義し、値をセットして

then stored by calling the put() method.

pet.Put()
のようにデータベース( datastore ) に保存する。

The datastore API provides two interfaces for queries:
a query object interface, and a SQL-like query language called GQL.
2種類のインターフェイスを用意していて、1つはSQLみたいなものでGQLといいます。

A query returns entities in the form of instances of the model classes that can be modified and put back into the datastore.
検索した値の更新もできます
構造を把握したところで、テンプレートに以下

{{ greeting.datedate:"Y/m/d H:m:s" }}
を追加して、時間を表示するようにしたところ自動的に登録される時間がJST(日本標準時)でなくUTCとなっているのをなんとかしたい。

DateTimeProperty のところのauto_now_add=True
で時刻が自動設定されています。


author = db.UserProperty()
content = db.StringProperty(multiline=True)
date = db.DateTimeProperty(auto_now_add=True)
テンプレートで対応できれば、ベストなのですが
http://www.djangoproject.com/documentation/0.96/templates/#now
時間表示の書式設定ではフォーマットはいろいろ設定できても、計算まではできないようです。
時刻でなく、数値の加減は filter 機能で対応していました。
{{gdateadd:"-2"}}
このような感じでテンプレート側で対応できますが・・・ 日付の場合、どうするかは次回の検討事項とします。


---- memo
「Google App Engine」のメリットとデメリット

Unityでドアの開閉はAnimatorそれともiTween?

Mac Mini M2 の Unity で Sketchup のデータを復元したつづき。 以前、苦労して作成したドアの開閉が動作しないので修復する。 どうやって動かしていたのか、また忘れそうなので記録しておく。             Animator 左右のドア PlaneL,...