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


Python User.add方法代码示例

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


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

示例1: signup_noncommercial

# 需要导入模块: from metabrainz.model.user import User [as 别名]
# 或者: from metabrainz.model.user.User import add [as 别名]
def signup_noncommercial():
    """Sign up endpoint for non-commercial users."""
    mb_username = session.fetch_data(SESSION_KEY_MB_USERNAME)
    if not mb_username:
        session.persist_data(**{
            SESSION_KEY_ACCOUNT_TYPE: ACCOUNT_TYPE_NONCOMMERCIAL,
        })
        return redirect(url_for(".signup"))
    mb_email = session.fetch_data(SESSION_KEY_MB_EMAIL)

    form = NonCommercialSignUpForm(default_email=mb_email)
    if form.validate_on_submit():
        new_user = User.add(
            is_commercial=False,
            musicbrainz_id=mb_username,
            contact_name=form.contact_name.data,
            contact_email=form.contact_email.data,
            data_usage_desc=form.usage_desc.data,
        )
        login_user(new_user)
        flash.success("Thanks for signing up!")
        send_mail(
            subject="[MetaBrainz] Sign up confirmation",
            text='Dear %s,\n\nThank you for signing up!\n\nYou can now generate '
                 'an access token for the MetaBrainz API on your profile page.'
                 % new_user.contact_name,
            recipients=[new_user.contact_email],
        )
        return redirect(url_for('.profile'))

    return render_template("users/signup-non-commercial.html", form=form)
开发者ID:lessc0de,项目名称:metabrainz.org,代码行数:33,代码来源:views.py

示例2: signup_noncommercial

# 需要导入模块: from metabrainz.model.user import User [as 别名]
# 或者: from metabrainz.model.user.User import add [as 别名]
def signup_noncommercial():
    """Sign up endpoint for non-commercial users."""
    mb_username = session.fetch_data(SESSION_KEY_MB_USERNAME)
    if not mb_username:
        session.persist_data(**{
            SESSION_KEY_ACCOUNT_TYPE: ACCOUNT_TYPE_NONCOMMERCIAL,
        })
        return redirect(url_for(".signup"))
    mb_email = session.fetch_data(SESSION_KEY_MB_EMAIL)

    form = NonCommercialSignUpForm(default_email=mb_email)
    if form.validate_on_submit():
        # Checking if this user already exists
        new_user = User.get(musicbrainz_id=mb_username)
        if not new_user:
            new_user = User.add(
                is_commercial=False,
                musicbrainz_id=mb_username,
                contact_name=form.contact_name.data,
                contact_email=form.contact_email.data,
                data_usage_desc=form.usage_desc.data,
            )
            flash.success(gettext("Thanks for signing up!"))
            try:
                send_mail(
                    subject="[MetaBrainz] Sign up confirmation",
                    text='Dear %s,\n\nThank you for signing up!\n\nYou can now generate '
                         'an access token for the MetaBrainz API on your profile page.'
                         % new_user.contact_name,
                    recipients=[new_user.contact_email],
                )
            except MailException as e:
                logging.error(e)
                flash.warning(gettext(
                    "Failed to send welcome email to you. We are looking into it. "
                    "Sorry for inconvenience!"
                ))
        else:
            flash.info(gettext("You already have a MetaBrainz account!"))
        login_user(new_user)
        return redirect(url_for('.profile'))

    return render_template("users/signup-non-commercial.html", form=form, mb_username=mb_username)
开发者ID:metabrainz,项目名称:metabrainz.org,代码行数:45,代码来源:views.py

示例3: signup_noncommercial

# 需要导入模块: from metabrainz.model.user import User [as 别名]
# 或者: from metabrainz.model.user.User import add [as 别名]
def signup_noncommercial():
    """Sign up endpoint for non-commercial users."""
    mb_username = session.fetch_data(SESSION_KEY_MB_USERNAME)
    if not mb_username:
        session.persist_data(**{
            SESSION_KEY_ACCOUNT_TYPE: ACCOUNT_TYPE_NONCOMMERCIAL,
        })
        return redirect(url_for(".signup"))
    mb_email = session.fetch_data(SESSION_KEY_MB_EMAIL)

    form = NonCommercialSignUpForm(default_email=mb_email)
    if form.validate_on_submit():
        new_user = User.add(
            is_commercial=False,
            musicbrainz_id=mb_username,
            contact_name=form.contact_name.data,
            contact_email=form.contact_email.data,
            data_usage_desc=form.usage_desc.data,
        )
        login_user(new_user)
        flash.success("Thanks for signing up!")
        return redirect(url_for('.profile'))

    return render_template("users/signup-non-commercial.html", form=form)
开发者ID:lalinsky,项目名称:metabrainz.org,代码行数:26,代码来源:views.py

示例4: signup_commercial

# 需要导入模块: from metabrainz.model.user import User [as 别名]
# 或者: from metabrainz.model.user.User import add [as 别名]
def signup_commercial():
    """Sign up endpoint for commercial users.

    Commercial users need to choose support tier before filling out the form.
    `tier_id` argument with ID of a tier of choice is required there.
    """
    tier_id = request.args.get('tier_id')
    if not tier_id:
        flash.warn("You need to choose support tier before signing up!")
        return redirect(url_for('.account_type'))
    selected_tier = Tier.get(id=tier_id)
    if not selected_tier or not selected_tier.available:
        flash.error("You need to choose existing tier before signing up!")
        return redirect(url_for(".account_type"))

    mb_username = session.fetch_data(SESSION_KEY_MB_USERNAME)
    if not mb_username:
        session.persist_data(**{
            SESSION_KEY_ACCOUNT_TYPE: ACCOUNT_TYPE_COMMERCIAL,
            SESSION_KEY_TIER_ID: selected_tier.id,
        })
        return redirect(url_for(".signup"))
    mb_email = session.fetch_data(SESSION_KEY_MB_EMAIL)

    form = CommercialSignUpForm(default_email=mb_email)

    def custom_validation(f):
        if f.amount_pledged.data < selected_tier.price:
            flash.warning("Custom amount must be more than threshold amount"
                          "for selected tier or equal to it!")
            return False
        # Complete address is required if payment method is invoicing
        if f.payment_method.data == PAYMENT_METHOD_INVOICING:
            if not (form.address_street.data and
                    form.address_city.data and
                    form.address_state.data and
                    form.address_postcode.data and
                    form.address_country.data):
                flash.warning("You need to fill in all address fields if your "
                              "selected payment method is invoicing!")
                return False
        return True

    if form.validate_on_submit() and custom_validation(form):
        new_user = User.add(
            is_commercial=True,
            musicbrainz_id=mb_username,
            contact_name=form.contact_name.data,
            contact_email=form.contact_email.data,
            data_usage_desc=form.usage_desc.data,

            org_name=form.org_name.data,
            org_desc=form.org_desc.data,
            website_url=form.website_url.data,
            org_logo_url=form.logo_url.data,
            api_url=form.api_url.data,

            address_street=form.address_street.data,
            address_city=form.address_city.data,
            address_state=form.address_state.data,
            address_postcode=form.address_postcode.data,
            address_country=form.address_country.data,

            tier_id=tier_id,
            payment_method=form.payment_method.data,
            amount_pledged=form.amount_pledged.data,
        )
        login_user(new_user)
        flash.success("Thanks for signing up! Your application will be reviewed "
                      "soon. We will send you updates via email.")
        send_mail(
            subject="[MetaBrainz] Sign up confirmation",
            text="Dear %s,\n\nThank you for signing up!\n\nCurrently everyone is on "
                 "a summer vacation until July 14. Your application will be reviewed "
                 "as soon as we get back. We will send you updates via email. Sorry "
                 "for the inconvenience."
                 % new_user.contact_name,
            recipients=[new_user.contact_email],
        )
        return redirect(url_for('.profile'))

    return render_template("users/signup-commercial.html", form=form, tier=selected_tier)
开发者ID:lessc0de,项目名称:metabrainz.org,代码行数:84,代码来源:views.py

示例5: signup_commercial

# 需要导入模块: from metabrainz.model.user import User [as 别名]
# 或者: from metabrainz.model.user.User import add [as 别名]
def signup_commercial():
    """Sign up endpoint for commercial users.

    Commercial users need to choose support tier before filling out the form.
    `tier_id` argument with ID of a tier of choice is required there.
    """
    tier_id = request.args.get('tier_id')
    if not tier_id:
        flash.warn("You need to choose support tier before signing up!")
        return redirect(url_for('.account_type'))
    selected_tier = Tier.get(id=tier_id)
    if not selected_tier or not selected_tier.available:
        flash.error("You need to choose existing tier before signing up!")
        return redirect(url_for(".account_type"))

    mb_username = session.fetch_data(SESSION_KEY_MB_USERNAME)
    if not mb_username:
        session.persist_data(**{
            SESSION_KEY_ACCOUNT_TYPE: ACCOUNT_TYPE_COMMERCIAL,
            SESSION_KEY_TIER_ID: selected_tier.id,
        })
        return redirect(url_for(".signup"))
    mb_email = session.fetch_data(SESSION_KEY_MB_EMAIL)

    form = CommercialSignUpForm(default_email=mb_email)

    def custom_validation(f):
        if f.amount_pledged.data < selected_tier.price:
            flash.warning("Custom amount must be more than threshold amount"
                          "for selected tier or equal to it!")
            return False
        return True

    if form.validate_on_submit() and custom_validation(form):
        # Checking if this user already exists
        new_user = User.get(musicbrainz_id=mb_username)
        if not new_user:
            new_user = User.add(
                is_commercial=True,
                musicbrainz_id=mb_username,
                contact_name=form.contact_name.data,
                contact_email=form.contact_email.data,
                data_usage_desc=form.usage_desc.data,

                org_name=form.org_name.data,
                org_desc=form.org_desc.data,
                website_url=form.website_url.data,
                org_logo_url=form.logo_url.data,
                api_url=form.api_url.data,

                address_street=form.address_street.data,
                address_city=form.address_city.data,
                address_state=form.address_state.data,
                address_postcode=form.address_postcode.data,
                address_country=form.address_country.data,

                tier_id=tier_id,
                amount_pledged=form.amount_pledged.data,
            )
            flash.success("Thanks for signing up! Your application will be reviewed "
                          "soon. We will send you updates via email.")
            send_mail(
                subject="[MetaBrainz] Sign up confirmation",
                text='Dear %s,\n\nThank you for signing up!\n\nYour application'
                     ' will be reviewed soon. We will send you updates via email.'
                     % new_user.contact_name,
                recipients=[new_user.contact_email],
            )
        else:
            flash.info("You already have a MetaBrainz account!")
        login_user(new_user)
        return redirect(url_for('.profile'))

    return render_template("users/signup-commercial.html", form=form, tier=selected_tier, mb_username=mb_username)
开发者ID:Freso,项目名称:metabrainz.org,代码行数:76,代码来源:views.py


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