1

Python と Django は初めてで、3 ステップのアクティベーション/登録システムを開発しようとしています。

ステップ 1:確認のため、メールアドレス、氏名を登録します。

ステップ 2:検証が完了したら、電子メールで送信されるアクティベーション キーと電子メール アドレスをレコード ユーザー名として使用して、新しいユーザー レコードを作成します。

ステップ 3:アカウントを有効にします。


ステップ 1 を処理するアプリケーションを作成し、django-registration と django カスタム ユーザー モデルを組み合わせて、ステップ 2 と 3 を処理することができました。

これはすべて、組み込みの管理機能を介してステップ 1 と 2 の間の手動リンクで機能します。ただし、ステップ 1 から検証済みのすべてのユーザーを選択し、レコードを使用してステップ 2 を自動的に処理できる管理者アクションが必要です。それぞれのフォームを使用する必要はありません。

これを行うには、RegistrationManager create_inactive_user メソッドを呼び出すことができるはずです。私の問題は、Python/Django の知識が限られているため、このメソッドを呼び出すのに苦労していることです。

実際には問題ないと思っていますが、ステップ 1 のアプリケーション モデルでエラーが発生しています。このモデルは BaseManager の normalize_email ユーティリティを使用し、そのアプリケーション内で直接使用すると機能しますが、create_inactive_user を使用するとエラーが発生します: TypeError at /admin/simple_reg/emailreg/ 'NoneType' object is not callable

含まれていないものがあると思います。以下は、私の admin.py ファイルからの関連する詳細です。

from django.contrib import admin
from django.contrib.auth import get_user_model

from simple_reg.models import EmailReg       # Initial step 1 registration model
from userinfo.models import UserManager      # Step 2 and 3 custom user model
from registration.models import RegistrationManager


class EmailRegAdmin(admin.ModelAdmin):
...
    def create_user_record(self, request, queryset):
        # Generate new User records from validated email contacts
        count = 0
        validated = len(queryset)
        for contact in queryset:
            pword = 'randomletters'
            try:
                existing = get_user_model().objects.filter(email__exact=contact.email)
                if existing.exists():
                    print "A user with the email address of %s already exists." % (contact.email)
                else:
                    RegistrationManager().create_inactive_user(contact.first_name,
                                           contact.last_name, contact.email, pword, site)
                        count = count + 1
                except:
                    print "User %s was not created" % (contact.email)

        self.message_user(request, "Of %s validations, %s user accounts have been created." % (validated, count))

create_user_record.short_description = "Generate new User records on selected contacts"

それは非常に単純なことだと確信しているので、誰かが私を正しい方向に向けることができることを願っています.

4

2 に答える 2

1

最終的に自分で答えを見つけました。

RegistrationManager ではなく、RegistrationProfile を呼び出す必要がありました。

私はそれが簡単なことだと知っていました!

于 2013-07-10T09:15:37.713 に答える
0

独自の User モデルを作成し、ブール型の is_active() のようなフィールドを定義するのが最も簡単な方法かもしれません。

于 2013-07-09T23:24:59.350 に答える