jQuery UI の autocomplete ウィジェットについて 調査したので、その時のメモ
銀行名か金融機関コードで検索して、 入力補完してくれるサンプルを書いた
ポイントは以下の通り
- データ構造は、配列
- 配列の要素は、Hashで、valueというキーの値が検索対象となる
- value以外は、任意のキーを指定可能
こちらも、銀行名か金融機関コードで検索して、 入力補完してくれるサンプル。
前のサンプルと違う点は、2つのフィールドに対して、同一のsuggestデータを使っている
ポイントは以下の通り
上記2つのサンプルは、挙動を理解しやすいようにするため、 サジェストするためのデータはコードに埋めたが、 remote API呼び出しも可能。
上記のサンプルでは、jquery側空、search.phpというAPIを呼び出し、 APIがJSON形式のデータを返している。
APIは、GETのパラメータで"term"を受け取り、 それに基づくsuggestデータを返却している
以下のようなことを考えた
% mkdir /tmp/py27
% cd /tmp/py27
% (buildout.cfg + bootstrap.pyを用意)
% cat buildout.cfg
[buildout]
python = python
parts =
python
env
[python]
recipe = zc.recipe.cmmi
url = http://www.python.org/ftp/python/2.7.2/Python-2.7.2.tgz
executable = ${buildout:parts-directory}/python/bin/python2.7
environment =
LDFLAGS=-Wl,-rpath,${buildout:parts-directory}/python/lib
extra_options =
--enable-unicode=ucs4
--enable-shared
--with-threads
[env]
recipe = zc.recipe.egg
eggs =
virtualenv
virtualenvwrapper
interpreter = python
% python bootstrap.py
% bin/buildout
% export WORKON_HOME=/tmp/virtualenvs
% export VIRTUALENVWRAPPER_HOOK_DIR=/tmp/virtualenvs
% export VIRTUALENVWRAPPER_LOG_DIR=/tmp/virtualenvs
## FIXME: クリーンな環境でうまくいくか?
% mkvirtualenv -p /tmp/py27/parts/python/bin/python testenv
% /tmp/virtualenvs/testenv/bin/pip install Flask
% /tmp/virtualenvs/testenv/bin/pip install gunicorn
% /tmp/virtualenvs/testenv/bin/pip install supervisor
% cat myserver.py
from flask import Flask
app = Flask(__name__)
@app.route('/')
def index():
return "<h1>hello!Yes!</h1>"
if __name__ == '__main__':
app.run(debug=True)
% /tmp/virtualenvs/testenv/bin/python myserver.py
* Running on http://127.0.0.1:5000/
* Restarting with reloader
cpでinstallしないほうがいい(暫定手順)
% sudo mkdir /tmp/virtualenvs/testenv/lib/python2.7/site-packages/mypj
% touch /tmp/virtualenvs/testenv/lib/python2.7/site-packages/mypj/__init__.py
% sudo cp myserver.py /tmp/virtualenvs/testenv/lib/python2.7/site-packages/mypj/
本当はdaemonモード
% /tmp/virtualenvs/testenv/bin/gunicorn mypj.myserver:app
AppEngineの開発環境で、メール送信機能を使うために postfixを使ったgmail送信環境の構築を行ったので、メモ。
まずは、package install
% sudo aptitude install postfix libsasl2-modules
/etc/postfix/main.cf を編集
以下を追記
# tanarky added
mydomain = tanarky.com
myorigin = $myhostname
relayhost = [smtp.gmail.com]:587
smtp_use_tls = yes
smtp_tls_CAfile = /etc/ssl/certs/ca-certificates.crt
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/relay_password
smtp_sasl_security_options = noanonymous
smtp_sasl_tls_security_options = noanonymous
smtp_sasl_mechanism_filter = plain
パスワードファイル作成
% sudo cat /etc/postfix/relay_password
[smtp.gmail.com]:587 *(Googleアカウント)*@gmail.com:*(Googleアカウントパスワード)*
% sudo postmap /etc/postfix/relay_password
% ls -l /etc/postfix/relay_password*
-rw-r--r-- 1 root root 48 2012-01-01 22:17 /etc/postfix/relay_password
-rw-r--r-- 1 root root 12288 2012-01-01 22:17 /etc/postfix/relay_password.db
% sudo rm /etc/postfix/relay_password
% ls -l /etc/postfix/relay_password*
-rw-r--r-- 1 root root 12288 2012-01-01 22:17 /etc/postfix/relay_password.db
postfix restartしてテスト送信
% sudo /etc/init.d/postfix restart
% sendmail -t ***
To: ***
From: ***
Subject: hello
world.
.
%