$ sudo ln -s /some/whare/google_appengine /usr/local/google_appengine
$ hg clone http://bitbucket.org/tmatsuo/kay/
$ python kay/manage.py startproject myproject
$ cd myproject
$ python manage.py startapp hello
$ vi settings.py
You have to add ‘hello’ to the INSTALLED_APPS tupple in the settings.py. For the details of how to define urls and views for your application, please refer to Kay URL Mapping.
- settings.py
INSTALLED_APPS = (
'hello'
)
$ python manage.py runserver
$ python manage.py appcfg update
$ python manage.py extract_messages hello
$ python manage.py add_translations hello -l ja
$ vi hello/i18n/ja/LC_MESSAGES/messages.po
$ python manage.py compile_translations hello
You can also merge newly added catalogue into your translations as follows.
$ python manage.py extract_messages hello
$ python manage.py update_translations hello -l ja
$ vi hello/i18n/ja/LC_MESSAGES/messages.po
$ python manage.py compile_translations hello
Note:
The local dev server reads datastore data file only on startup. So, the dev server will never notice about the datastore operation on your bash session. You must restart your dev server for reflecting the result of the bash sessions.
Note:
Please be careful when you use this feature.
You must use GAE models directly. You can use kay.utils.forms for form handling. You can construct a form automatically from the model definition with kay.utils.forms.modelform.ModelForm. For the details of how to use forms, please refer to Forms usage.
By default, db.Model.kind() returns (‘model’s app name’ + _ + ‘model name’).lower(). So when you see the management bash, there will be ‘appname_modelname’ style kind names . Please don’t be surprised with those names.
You can change this behaviour by settings ADD_APP_PREFIX_TO_KIND to False in your settings.py.
Experimental db_hook feature is now available on repository. To use this feature, you have to set USE_DB_HOOK to True in your top level settings.py file. Also you have to register your hooks beforehands somewhere in your code. I recommend you to do this in appname/__init__.py because Kay always load this file on startup as long as appname is on your INSTALLED_APPS. Here is an example for registering a hook that logs dumpped represantation of the saved entry and whether this operation is creating a new entity or updating an existing entity.
import logging
from kay.utils import db_hook
from kay.utils.db_hook import put_type
from hoge.models import Entry
def log_instance(entity, put_type_id):
from kay.utils.repr import dump
logging.info(dump(entity))
logging.info("put_type: %s" % put_type.get_name(put_type_id))
register_post_save_hook(log_instance, Entry)
from kay.utils.forms import Form
class PersonForm(Form):
name = TextField(required=True)
age = IntegerField()
You can use this form in your view like following.
from forms import PersonForm
form = PersonForm()
if request.method == 'POST'
if form.validate(request.form, request.files):
name = form['name']
age = form['age']
do something with valid form ...
else:
do something with invalid form ...
from google.appengine.ext import db
class MyModel(db.Model):
name = db.StringProperty(required=True)
age = db.IntegerProperty()
from kay.utils.forms.modelform import ModelForm
class MyForm(ModelForm):
class Meta:
model = MyModel
Have fun!