当前位置: 首页>>代码示例>>Python>>正文


Python Person.apply_state_new_user方法代码示例

本文整理汇总了Python中core.models.Person.apply_state_new_user方法的典型用法代码示例。如果您正苦于以下问题:Python Person.apply_state_new_user方法的具体用法?Python Person.apply_state_new_user怎么用?Python Person.apply_state_new_user使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在core.models.Person的用法示例。


在下文中一共展示了Person.apply_state_new_user方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: respond_with_new_user

# 需要导入模块: from core.models import Person [as 别名]
# 或者: from core.models.Person import apply_state_new_user [as 别名]
    def respond_with_new_user(self, request, next_url, desuprofile):
        """
        This implements the following case:

        2. No Kompassi account is linked to this Desuprofile, and no Kompassi account matches the
           Desuprofile by email address. A new Kompassi account is created and logged in.
        """

        User = get_user_model()
        password = create_temporary_password()

        # Kompassi has stricter rules for username validation than Desusite
        username = desuprofile.username.lower()
        try:
            valid_username(username)
        except DjangoValidationError:
            username = None
        else:
            try:
                User.objects.get(username=username)
            except User.DoesNotExist:
                # Username is free
                pass
            else:
                # Username clash with an existing account, use safe username
                username = None

        if username is None:
            username = "desuprofile_{id}".format(id=desuprofile.id)

        with transaction.atomic():
            user = User(
                username=username,
                is_active=True,
                is_staff=False,
                is_superuser=False,
            )

            user.set_password(password)
            user.save()

            person = Person(
                first_name=desuprofile.first_name.strip(),
                surname=desuprofile.last_name.strip(),
                nick=desuprofile.nickname.strip(),
                email=desuprofile.email.strip(),
                phone=desuprofile.phone.strip(),
                birth_date=(
                    datetime.strptime(desuprofile.birth_date.strip(), '%Y-%m-%d').date()
                    if desuprofile.birth_date
                    else None
                ),
                notes='Luotu Desuprofiilista',
                user=user,
            )

            person.save()

            connection = Connection(
                id=int(desuprofile.id),
                desuprofile_username=desuprofile.username,
                user=user,
            )
            connection.save()

        person.apply_state_new_user(request, password)
        messages.success(request, 'Sinulle on luotu Desuprofiiliisi liitetty Kompassi-tunnus. Tervetuloa Kompassiin!')

        return respond_with_connection(request, next_url, connection)
开发者ID:tracon,项目名称:kompassi,代码行数:71,代码来源:views.py


注:本文中的core.models.Person.apply_state_new_user方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。