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


Python Account.create方法代码示例

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


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

示例1: create_user

# 需要导入模块: from account.models import Account [as 别名]
# 或者: from account.models.Account import create [as 别名]
def create_user(backend, details, response, uid, username, user=None, *args, **kwargs):
    """Create user. Depends on get_username pipeline."""
    if user:
        return {'user': user}
    if not username:
        return None

    warn_setting('SOCIAL_AUTH_CREATE_USERS', 'create_user')

    if not setting('SOCIAL_AUTH_CREATE_USERS', True):
        # Send signal for cases where tracking failed registering is useful.
        socialauth_not_registered.send(sender=backend.__class__, uid=uid, response=response, details=details)
        return None

    email = details.get('email')
    request = kwargs["request"]

    user = User.objects.create_user(username=username, email=email)

    Account.create(request=request, user=user)
    EmailAddress.objects.add_email(user, user.email, primary=True)

    return {
        'user': user,
        'is_new': True
    }
开发者ID:InQuant,项目名称:crate.web,代码行数:28,代码来源:user.py

示例2: user_post_save

# 需要导入模块: from account.models import Account [as 别名]
# 或者: from account.models.Account import create [as 别名]
def user_post_save(sender, **kwargs):
    """
    After User.save is called we check to see if it was a created user. If so,
    we check if the User object wants account creation. If all passes we
    create an Account object.
    
    We only run on user creation to avoid having to check for existence on
    each call to User.save.
    """
    user, created = kwargs["instance"], kwargs["created"]
    disabled = getattr(user, "_disable_account_creation", not settings.ACCOUNT_CREATE_ON_SAVE)
    if created and not disabled:
        from account.models import Account
        Account.create(user=user)
开发者ID:andrei1089,项目名称:django-user-accounts,代码行数:16,代码来源:receivers.py

示例3: create_account

# 需要导入模块: from account.models import Account [as 别名]
# 或者: from account.models.Account import create [as 别名]
 def create_account(self, form):
     account = Account.create(request=self.request, user=self.created_user, create_email=False)
     fields = {}
     if "street" in form.cleaned_data:
         fields["street"] = form.cleaned_data["street"]
     if "plz_city" in form.cleaned_data:
         fields["plz_city"] = form.cleaned_data["plz_city"]
     if "phone" in form.cleaned_data:
         fields["phone"] = form.cleaned_data["phone"]
     for k, v in fields.items():
         setattr(account, k, v)
     account.save()
     return account
开发者ID:Tamriel,项目名称:wagtail_room_booking,代码行数:15,代码来源:views.py

示例4: create_account

# 需要导入模块: from account.models import Account [as 别名]
# 或者: from account.models.Account import create [as 别名]
 def create_account(self, form):
     return Account.create(request=self.request, user=self.created_user, create_email=False)
开发者ID:worseisbetter,项目名称:django-user-accounts,代码行数:4,代码来源:views.py

示例5: create_account

# 需要导入模块: from account.models import Account [as 别名]
# 或者: from account.models.Account import create [as 别名]
 def create_account(self, new_user, form):
     return Account.create(request=self.request, user=new_user)
开发者ID:hdknr,项目名称:django-user-accounts,代码行数:4,代码来源:views.py

示例6: create_account

# 需要导入模块: from account.models import Account [as 别名]
# 或者: from account.models.Account import create [as 别名]
    def create_account(self, form):
        return Account.create(request=self.request, user=self.created_user, create_email=False, 
				subscribe_to_newsletter=form.cleaned_data["subscribe_to_newsletter"])
开发者ID:syst3mw0rm,项目名称:django-user-accounts,代码行数:5,代码来源:views.py

示例7: str

# 需要导入模块: from account.models import Account [as 别名]
# 或者: from account.models.Account import create [as 别名]
            content = urllib2.urlopen(url)
            # Facebook default image check
            if sender.name == 'facebook' and 'image/gif' in str(content.info()):
                return

            filename = user.username + "_profile" + '.' + content.headers.subtype
            profile.photo.save(filename, ContentFile(content.read()))
        except IOError, e:
            logger.debug(e)
    try:
        profile.language = response.get('locale').split("_")[0]
        profile.full_clean()
    except Exception:
        pass
    profile.time_zone = response.get('timezone')
    profile.save()
    account = user.account_set.all()[0] or Account.create(user=user, create_email=False)
    try:
        account.language = response.get('locale').split("_")[0]
        tz_offset = int(response.get('timezone'))
        tz_joiner = "" if tz_offset < 0 else "+"
        account.timezone = coerce_timezone_value(tz_joiner.join(("Etc/GMT", str(tz_offset))))
        account.full_clean()
    except Exception:
        pass
    account.save()
    email, created = EmailAddress.objects.get_or_create(user=user, email=user.email)
    email.verified = True
    email.save()
    return True
开发者ID:kirason,项目名称:ahgl-site,代码行数:32,代码来源:models.py

示例8: post

# 需要导入模块: from account.models import Account [as 别名]
# 或者: from account.models.Account import create [as 别名]
    def post(self, request, *args, **kwargs):
        try:
            data = json.loads(request.body)
        except:
            return HttpResponseBadRequest(self.format_error)

        # Data should be a list of registration info in dictionary format.
        if not (isinstance(data, list) and all([isinstance(d, dict) for d in data])):
            return HttpResponseBadRequest(self.format_error)

        all_valid = True
        seen_emails = []
        user_data = []
        for registration in data:
            form = GroupRegistrationForm(data=registration)
            if form.is_valid():
                # Check if this is a duplicate of an email provided in this request.
                email = User.objects.normalize_email(form.cleaned_data['email'])
                if email in seen_emails:
                    all_valid = False
                    user_data.append({
                        'valid': False,
                        'error_message': 'This email is a duplicate of one above.',
                        'user': None,
                    })
                else:
                    seen_emails.append(email)
                    created, user = form.save(commit=False)
                    if created:
                        # Delay account creation until the transaction is
                        # committed.
                        user._disable_account_creation = True
                        user.save()
                    user_data.append({
                        'valid': True,
                        'created': created,
                        'user': {
                            'pycon_id': user.pk,
                            'email': form.cleaned_data.get('email'),
                            'first_name': form.cleaned_data.get('first_name', ''),
                            'last_name': form.cleaned_data.get('last_name', ''),
                        }
                    })
            else:
                all_valid = False
                user_data.append({
                    'valid': False,
                    'errors': [e for errors in form.errors.values() for e in errors],
                    'user': None,
                })

        # The request is atomic - all users are created (or found), or none
        # are.
        if all_valid:
            for d in user_data:
                if d['created']:
                    # Now that the transaction has been committed,
                    # create an Account for the user so that they can log in.
                    user = User.objects.get(pk=d['user']['pycon_id'])
                    Account.create(user=user)
        else:
            for d in user_data:
                d['user'] = None
                d.pop('created', None)
            transaction.set_rollback(True)

        return_data = {'success': all_valid, 'users': user_data}
        return HttpResponse(json.dumps(return_data))
开发者ID:PyCon,项目名称:pycon,代码行数:70,代码来源:views.py


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