Account Options

  1. Sign in
The old Google Groups will be going away soon.
Switch to the new Google Groups.
Google Groups Home
« Groups Home
localflavor-ja
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  3 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
tsuyuki makoto  
View profile   Translate to Translated (View Original)
 More options Feb 18 2007, 9:56 am
From: "tsuyuki makoto" <mtsuy...@gmail.com>
Date: Sun, 18 Feb 2007 23:56:40 +0900
Local: Sun, Feb 18 2007 9:56 am
Subject: localflavor-ja

露木です。

開発SVN版に、localflavorというコントリビュートパッケージができました。
地域に関連したものはこの中に入ることになるようです。
usaに続き、ukが登場したのでjpもぜひとも入れたいと思っています。

まずは、郵便番号と都道府県に関するものを書いてみました。
newformsの中を始めてまともに見たので、どんどん突っ込んでください。
django.contrib.localflavor.jpの直下に置くことを想定しています。

つづいて、電話番号に関するものを書く予定ですが、ちょっと人生が辛い
のですぐには書けないかもしれません。
#コメントやテスト・ドキュメントも書かないと…

  forms.py
1K Download

  models.py
2K Download

  validators.py
6K Download

  jp_prefectures.py
1K Download

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Yasushi Masuda  
View profile   Translate to Translated (View Original)
 More options Feb 19 2007, 12:30 am
From: Yasushi Masuda <ymas...@ethercube.com>
Date: Mon, 19 Feb 2007 14:30:09 +0900
Local: Mon, Feb 19 2007 12:30 am
Subject: Re: [django-ja:422] localflavor-ja
露木さん,仕事早いですね :)

ざっと見ですが,コード拝見しました.

1. models.py は不要だと思います. CharField には validator_list を指定できるので,
実質的には CharField(validator_list=[isValidJPPostalCode])と同じだからです.
choices=JP_PREFECTURES も同様です. localflavor の提供するバリデータやサービス
データに isValidJPPostalCode や JP_PREFECTURESがあるとドキュメントに明記されて
いれば十分だと思います.

2. validator のバリデータは,旧番号体系,新番号体系,両方に対応可の 3 種類が
用意されていて,それぞれが別個の正規表現を使っています.この,両方に対応可
のバリデータは,内部で前者の二つを試して,例えば旧番号->新番号にフォール
バックしてバリデーションしてはどうでしょう.また, validator で定義している
正規表現ですが, 3. で述べる理由から, public なモジュール変数にしては
どうでしょう.あと,統一性から _jp_postal_... は jp_postalcode_... または
jp_postal_code_ ... が良いと思います (standard 的には後者だと思います)

3. forms の JPPostalCodeField は,contrib/localflavors/us/forms.py の
USZipCodeField のように, RegexField を継承してはどうでしょう.その際,
デフォルトの正規表現を validators から import して使います.例えば,
  from validators import jp_postal_code_newformat_re
  class JPPostalCodeField(RegexField):
    def __init__(self, pattern=jp_postal_code_newformat_re, *args, **kwargs):
      super(JPPostalCodeField, self).__init__(pattern, ...)
のようにするわけです.これなら, clean() の処理は RegexField 任せにできます.

--
Yasushi Masuda
http://ymasuda.jp/

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
tsuyuki makoto  
View profile   Translate to Translated (View Original)
 More options Feb 20 2007, 5:02 am
From: "tsuyuki makoto" <mtsuy...@gmail.com>
Date: Tue, 20 Feb 2007 19:02:57 +0900
Local: Tues, Feb 20 2007 5:02 am
Subject: Re: [django-ja:423] Re: localflavor-ja
露木です。

増田さん、いつもありがとうございます:)

> 1. models.py は不要だと思います. CharField には validator_list を指定できるので,
> 実質的には CharField(validator_list=[isValidJPPostalCode])と同じだからです.
> choices=JP_PREFECTURES も同様です. localflavor の提供するバリデータやサービス
> データに isValidJPPostalCode や JP_PREFECTURESがあるとドキュメントに明記されて
> いれば十分だと思います.

validator_listやchoicesがform_for_modelによって生成されるFormで利用されない
ので、無理矢理フィールドを作ったのですが考えてみればnewformsはまだ実装中
でしたね。
validator_listやchoicesでvalidationされるようになるのを待ちます(=modelはいらない)。

実は、まだnewformsやnewadminの使い方をよく認識していません…

SomeForm = form_for_model(Some)
SomeForm.attr_a = JPPostalCodeField(pattern=jp_postal_code_newformat_re,
                                                          error_message='なんとか')
こんな感じにフォームを定義して、ビュー毎にどのフォームを使うかを設定する
のかな?モデルにデフォルト設定とかできるのかな?
#モデルになんても書くスタイルが気に入っていたので、newformsはちょっと気に入らない:)

なので、いまのところusaやukでやっていること以上をやるのは時期尚早だったと
反省しましたorz

> 2. validator のバリデータは,旧番号体系,新番号体系,両方に対応可の 3 種類が
> 用意されていて,それぞれが別個の正規表現を使っています.この,両方に対応可
> のバリデータは,内部で前者の二つを試して,例えば旧番号->新番号にフォール
> バックしてバリデーションしてはどうでしょう.また, validator で定義している
> 正規表現ですが, 3. で述べる理由から, public なモジュール変数にしては
> どうでしょう.あと,統一性から _jp_postal_... は jp_postalcode_... または
> jp_postal_code_ ... が良いと思います (standard 的には後者だと思います)

2種類にした方がわかりやすいし、DRY!って言えていい気がします。
が、2種類にしてしまうと、JPPostalCodeFieldをRegexFieldの継承にするときに
困ってしまうような気がしています。
はて

> 3. forms の JPPostalCodeField は,contrib/localflavors/us/forms.py の
> USZipCodeField のように, RegexField を継承してはどうでしょう.その際,
> デフォルトの正規表現を validators から import して使います.例えば,
>   from validators import jp_postal_code_newformat_re
>   class JPPostalCodeField(RegexField):
>     def __init__(self, pattern=jp_postal_code_newformat_re, *args, **kwargs):
>       super(JPPostalCodeField, self).__init__(pattern, ...)
> のようにするわけです.これなら, clean() の処理は RegexField 任せにできます.

validatorを使わないと、毎回error_messageを渡さなければいけないなと
思ったのがRegexFieldを使わなかった理由です。
が、エラーメッセージ位書けばいい気もしますし、validatorと同じ文字列を利用
できるようにしてもいいとも思います。
ふむ…

ちょいと再挑戦します。


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »