1
我在本地環境中設置了一個可用的夾層(使用pybb)。 pybb得到了一個抽象的Profile類來定義一些用戶屬性,並且在你還沒有使用的時候也會發佈一個Profile類。在Mezzanine項目上創建帳戶時返回多個對象(配置文件)
一切工作除了註冊過程這在創建用戶結束了,但造成了下面的回溯:
我認爲pybbMiddleware可能是問題。在pybb的signals.py(我如何創建2個配置文件?)
class PybbMiddleware(object):
def process_request(self, request):
if request.user.is_authenticated():
try:
# Here we try to load profile, but can get error
# if user created during syncdb but profile model
# under south control. (Like pybb.Profile).
profile = request.user.get_profile()
except ObjectDoesNotExist:
# Ok, we should create new profile for this user
# and grant permissions for add posts
user_saved(request.user, created=True)
profile = request.user.get_profile()
language = translation.get_language_from_request(request)
if not profile.language:
profile.language = language
profile.save()
if profile.language and profile.language != language:
request.session['django_language'] = profile.language
translation.activate(profile.language)
request.LANGUAGE_CODE = translation.get_language()
的user_saved():
def user_saved(instance, created, **kwargs):
if not created:
return
try:
add_post_permission = Permission.objects.get_by_natural_key('add_post', 'pybb', 'post')
add_topic_permission = Permission.objects.get_by_natural_key('add_topic', 'pybb', 'topic')
except ObjectDoesNotExist:
return
instance.user_permissions.add(add_post_permission, add_topic_permission)
instance.save()
if settings.AUTH_PROFILE_MODULE == 'pybb.Profile':
from models import Profile
Profile(user=instance).save()
和最重要的是我有另一個user_saved()應收/模型.py:
@receiver(post_save, sender=User)
def user_saved(sender=None, instance=None, **kwargs):
Profile.objects.get_or_create(**{str(user_field): instance})
是否調用了兩個並因此創建了2個配置文件?
感謝您的幫助!
你知道了嗎? – 2013-08-27 21:29:47