Web Images Videos Maps News Shopping Gmail more »
Recently Visited Groups | Help | Sign in
Google Groups Home
Formクラス中の clean_<fieldname>中でユーザーのパスワードを確認する
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
  2 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
 
kame  
View profile   Translate to Translated (View Original)
 More options Jun 5, 2:11 pm
From: kame <densyaj...@gmail.com>
Date: Fri, 5 Jun 2009 11:11:09 -0700 (PDT)
Local: Fri, Jun 5 2009 2:11 pm
Subject: Formクラス中の clean_<fieldname>中でユーザーのパスワードを確認する
お世話になっております、kameと申します。Djangoに2ヶ月くらい没頭しているのですが、
自分で作成したFormクラス中(Forms.formの子クラス)の、 clean_<fieldname> 中のバリデーションで少々はまっており
ます。

現在、私がDjangoで作成しているアプリケーションにログイン後、セキュリティのために、ユーザーが自分でパスワードを
変更出来るためのMVTを実装しようとしているのですが、どうしてもFormクラスのclean_<fieldname>メソッド(例: def
clean_NewPassword(self): )
中でユーザーの情報、すなわち"django.contrib.auth.models.User" (以下models.User)の情報を取得する
ことが出来なくて困っております。
この問題により、models.Userのcheck_passwordをclean_<fieldname>中で利用することが出来ないため、現在の
パスワードが正しいかを
判定することができなくて困っております。

唯一の引数であるselfをprint dirしてみたのですが、User関連の情報は納められておりませんでした。

色々考えて、View中でこのFormクラスを束縛で作る際に、

---------------------------------
if request.method == 'POST':
    query_dict = request.POST.copy()
    query_dict.__setitem__('user_obj', request.user)
    form = password_change(query_dict)
---------------------------------
などとあがいてみた物の、うまくいきませんでした。

皆様は、フォームクラスのclean_<fieldname>中で、ファイルやデータベースに収まっている情報などと、照合を
行いたい場合、どのように対処されておりますでしょうか。

もし、おわかりになる方がいらっしゃいましたらご教授ください。

では!


    Reply to author    Forward  
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.
kame  
View profile   Translate to Translated (View Original)
 More options Jun 6, 5:22 am
From: kame <densyaj...@gmail.com>
Date: Sat, 6 Jun 2009 02:22:01 -0700 (PDT)
Local: Sat, Jun 6 2009 5:22 am
Subject: Re: Formクラス中の clean_<fieldname>中でユーザーのパスワードを確認する
自己レスです。上の問題ですが、解決することができました。
formクラスのinitをオーバーライドし、

#(forms.py)
class TestForm(forms.form):
def __init__(self, user, *args, **kwargs):
    self.user = user
    super(password_change, self).__init__(*args, **kwargs)
        .
        .
-------------------------------
#(view.py)
          .
          .
    form = password_change(request.user)
    if request.method == 'POST':
            form = password_change(request.user, request.POST)
                         .
                         .
とすることで、request.userの情報をformsクラス中に持たすことができました。
実は、一番はじめにこの方法にトライしていたのですが、うまくいきませんでした。
その理由は、formのインスタンスを作成する際、以下のように、引数を渡していたためでした。

form = password_change(request.POST, request.user) #引数の渡し方が逆

それに気づかず、1日を費やしてしまいました・・・
何はともあれ解決することができました。

では


    Reply to author    Forward  
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 »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2009 Google