• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python user.User类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: signup_noncommercial

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,
            )
        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:caroline-gschwend,项目名称:metabrainz.org,代码行数:34,代码来源:views.py


示例2: approve

    def approve(self):
        user_id = request.args.get('user_id')
        User.get(id=user_id).set_state(STATE_ACTIVE)
        flash.info("User #%s has been approved." % user_id)

        # Redirecting to the next pending user
        next_user = User.get(state=STATE_PENDING)
        if next_user:
            return redirect(url_for('.details', user_id=next_user.id))
        else:
            return redirect(url_for('.index'))
开发者ID:lalinsky,项目名称:metabrainz.org,代码行数:11,代码来源:views.py


示例3: reject

    def reject(self):
        user_id = request.args.get('user_id')
        User.get(id=user_id).set_state(STATE_REJECTED)
        flash.warn("User #%s has been rejected." % user_id)

        # Redirecting to the next pending user
        next_user = User.get(state=STATE_PENDING)
        if next_user:
            return redirect(url_for('.details', user_id=next_user.id))
        else:
            return redirect(url_for('.index'))
开发者ID:lalinsky,项目名称:metabrainz.org,代码行数:11,代码来源:views.py


示例4: wait

    def wait(self):
        user_id = request.args.get('user_id')
        User.get(id=user_id).set_state(STATE_WAITING)
        flash.info('User #%s has been put into the waiting list.' % user_id)

        # Redirecting to the next pending user
        next_user = User.get(state=STATE_PENDING)
        if next_user:
            return redirect(url_for('.details', user_id=next_user.id))
        else:
            flash.info('No more pending users.')
            return redirect(url_for('.index'))
开发者ID:metabrainz,项目名称:metabrainz.org,代码行数:12,代码来源:views.py


示例5: approve

    def approve(self):
        user_id = request.args.get('user_id')
        if request.args.get('limited'):
            User.get(id=user_id).set_state(STATE_LIMITED)
        else:
            User.get(id=user_id).set_state(STATE_ACTIVE)
        flash.info('User #%s has been approved.' % user_id)

        # Redirecting to the next pending user
        next_user = User.get(state=STATE_PENDING)
        if next_user:
            return redirect(url_for('.details', user_id=next_user.id))
        else:
            flash.info('No more pending users.')
            return redirect(url_for('.index'))
开发者ID:metabrainz,项目名称:metabrainz.org,代码行数:15,代码来源:views.py


示例6: update

def update(user_id, **kwargs):
    user = User.get(id=user_id)
    if not user:
        raise ValueError("Can't find user with a specified ID (%s)" % user_id)

    multiparams = {
        "id": user_id,
        "musicbrainz_id": kwargs.pop("musicbrainz_id", user.musicbrainz_id),
        "contact_name": kwargs.pop("contact_name", user.contact_name),
        "contact_email": kwargs.pop("contact_email", user.contact_email),
        "state": kwargs.pop("state", user.state),
        "is_commercial": kwargs.pop("is_commercial", user.is_commercial),
        "org_name": kwargs.pop("org_name", user.org_name),
        "org_desc": kwargs.pop("org_desc", user.org_desc),
        "api_url": kwargs.pop("api_url", user.api_url),
        "address_street": kwargs.pop("address_street", user.address_street),
        "address_city": kwargs.pop("address_city", user.address_city),
        "address_state": kwargs.pop("address_state", user.address_state),
        "address_postcode": kwargs.pop("address_postcode", user.address_postcode),
        "address_country": kwargs.pop("address_country", user.address_country),
        "tier_id": kwargs.pop("tier_id", user.tier_id),
        "amount_pledged": kwargs.pop("amount_pledged", user.amount_pledged),
        "featured": kwargs.pop("featured", user.featured),
        "website_url": kwargs.pop("website_url", user.website_url),
        "logo_filename": kwargs.pop("logo_filename", user.logo_filename),
        "org_logo_url": kwargs.pop("org_logo_url", user.org_logo_url),
        "data_usage_desc": kwargs.pop("data_usage_desc", user.data_usage_desc),
        "good_standing": kwargs.pop("good_standing", user.good_standing),
        "in_deadbeat_club": kwargs.pop("in_deadbeat_club", user.in_deadbeat_club),
    }
    if kwargs:
        raise TypeError("Unexpected **kwargs: %r" % kwargs)

    with db.engine.connect() as connection:
        connection.execute(sqlalchemy.text("""
            UPDATE "user"
               SET musicbrainz_id = :musicbrainz_id,
                   contact_name = :contact_name,
                   contact_email = :contact_email,
                   state = :state,
                   is_commercial = :is_commercial,
                   org_name = :org_name,
                   org_desc = :org_desc,
                   api_url = :api_url,
                   address_street = :address_street,
                   address_city = :address_city,
                   address_state = :address_state,
                   address_postcode = :address_postcode,
                   address_country = :address_country,
                   tier_id = :tier_id,
                   amount_pledged = :amount_pledged,
                   featured = :featured,
                   website_url = :website_url,
                   logo_filename = :logo_filename,
                   org_logo_url = :org_logo_url,
                   data_usage_desc = :data_usage_desc,
                   good_standing = :good_standing,
                   in_deadbeat_club = :in_deadbeat_club
             WHERE id = :id
        """), multiparams)
开发者ID:metabrainz,项目名称:metabrainz.org,代码行数:60,代码来源:user.py


示例7: details

 def details(self, user_id):
     user = User.get(id=user_id)
     active_tokens = Token.get_all(owner_id=user.id, is_active=True)
     return self.render(
         'admin/users/details.html',
         user=user,
         active_tokens=active_tokens,
     )
开发者ID:metabrainz,项目名称:metabrainz.org,代码行数:8,代码来源:views.py


示例8: index

 def index(self):
     page = int(request.args.get('page', default=1))
     if page < 1:
         return redirect(url_for('.index'))
     limit = 20
     offset = (page - 1) * limit
     users, count = User.get_all_commercial(limit=limit, offset=offset)
     return self.render('admin/commercial-users/index.html', users=users,
                        page=page, limit=limit, count=count)
开发者ID:metabrainz,项目名称:metabrainz.org,代码行数:9,代码来源:views.py


示例9: musicbrainz_post

def musicbrainz_post():
    """MusicBrainz OAuth2 callback endpoint."""
    if not musicbrainz_login.validate_post_login():
        raise BadRequest("Login failed!")
    code = request.args.get('code')
    if not code:
        raise InternalServerError("Authorization code is missing!")
    mb_username, mb_email = musicbrainz_login.get_user(code)
    session.persist_data(**{
        SESSION_KEY_MB_USERNAME: mb_username,
        SESSION_KEY_MB_EMAIL: mb_email,
    })
    user = User.get(musicbrainz_id=mb_username)
    if user:  # Checking if user is already signed up
        login_user(user)
        next = session.session.get('next')
        return redirect(next) if next else redirect(url_for('.profile'))
    else:
        return redirect(url_for('.signup'))
开发者ID:lessc0de,项目名称:metabrainz.org,代码行数:19,代码来源:views.py


示例10: signup_noncommercial

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,代码行数:24,代码来源:views.py


示例11: home

def home():
    return render_template(
        'index/index.html',
        good_users=User.get_featured(limit=4, with_logos=True),
        bad_users=User.get_featured(in_deadbeat_club=True, limit=1, with_logos=True),
    )
开发者ID:caroline-gschwend,项目名称:metabrainz.org,代码行数:6,代码来源:views.py


示例12: edit

    def edit(self, user_id):
        user = User.get(id=user_id)

        form = forms.UserEditForm(defaults={
            'musicbrainz_id': user.musicbrainz_id,
            'contact_name': user.contact_name,
            'contact_email': user.contact_email,
            'state': user.state,
            'is_commercial': user.is_commercial,
            'org_name': user.org_name,
            'org_desc': user.org_desc,
            'api_url': user.api_url,
            'address_street': user.address_street,
            'address_city': user.address_city,
            'address_state': user.address_state,
            'address_postcode': user.address_postcode,
            'address_country': user.address_country,
            'tier': user.tier_id,
            'amount_pledged': user.amount_pledged or 0,
            'featured': user.featured,
            'website_url': user.website_url,
            'logo_url': user.org_logo_url,
            'usage_desc': user.data_usage_desc,
            'good_standing': user.good_standing,
            'in_deadbeat_club': user.in_deadbeat_club,
        })

        if form.validate_on_submit():
            update_data = {
                'musicbrainz_id': form.musicbrainz_id.data,
                'contact_name': form.contact_name.data,
                'contact_email': form.contact_email.data,
                'state': form.state.data,
                'is_commercial': form.is_commercial.data,
                'org_name': form.org_name.data,
                'org_desc': form.org_desc.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': int(form.tier.data) if form.tier.data != 'None' else None,
                'amount_pledged': form.amount_pledged.data,
                'featured': form.featured.data,
                'website_url': form.website_url.data,
                'org_logo_url': form.logo_url.data,
                'data_usage_desc': form.usage_desc.data,
                'good_standing': form.good_standing.data,
                'in_deadbeat_club': form.in_deadbeat_club.data,
            }
            if form.logo.data:
                extension = os.path.splitext(secure_filename(form.logo.data.filename))[1]
                # Using a random UUID instead of user ID here so that we don't unnecessarily expose them.
                logo_filename = '%s%s' % (uuid.uuid4(), extension)
                update_data['logo_filename'] = logo_filename
                image_storage = form.logo.data  # type: werkzeug.datastructures.FileStorage
                if user.logo_filename:
                    # Deleting old logo
                    try:
                        os.remove(os.path.join(forms.LOGO_STORAGE_DIR, user.logo_filename))
                    except OSError as e:
                        logging.warning(e)
                # Saving new one
                image_storage.save(os.path.join(forms.LOGO_STORAGE_DIR, logo_filename))
            db_user.update(user_id=user.id, **update_data)
            return redirect(url_for('.details', user_id=user.id))

        return self.render(
            'admin/users/edit.html',
            user=user,
            form=form,
        )
开发者ID:metabrainz,项目名称:metabrainz.org,代码行数:73,代码来源:views.py


示例13: get_featured_users

 def get_featured_users(self, **kwargs):
     return User.get_featured(tier_id=self.id, **kwargs)
开发者ID:caroline-gschwend,项目名称:metabrainz.org,代码行数:2,代码来源:tier.py


示例14: load_user

def load_user(user_id):
    return User.get(id=user_id)
开发者ID:caroline-gschwend,项目名称:metabrainz.org,代码行数:2,代码来源:__init__.py


示例15: index

 def index(self):
     users = User.get_all(state=STATE_PENDING)
     return self.render('admin/users/index.html', users=users)
开发者ID:lalinsky,项目名称:metabrainz.org,代码行数:3,代码来源:views.py


示例16: user

def user(user_id):
    user = User.get(id=user_id)
    return jsonify({
        "username": user.musicbrainz_id,
    })
开发者ID:dpmittal,项目名称:metabrainz.org,代码行数:5,代码来源:user.py


示例17: account_type

def account_type():
    return render_template(
        'users/account-type.html',
        tiers=Tier.get_available(sort=True),
        featured_users=User.get_featured()
    )
开发者ID:lessc0de,项目名称:metabrainz.org,代码行数:6,代码来源:views.py


示例18: bad_customers

def bad_customers():
    return render_template(
        'index/bad-customers.html',
        bad_users=User.get_featured(in_deadbeat_club=True),
    )
开发者ID:caroline-gschwend,项目名称:metabrainz.org,代码行数:5,代码来源:views.py


示例19: signup_commercial

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,代码行数:82,代码来源:views.py


示例20: signup_commercial

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,代码行数:74,代码来源:views.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python metaclass.twiss函数代码示例发布时间:2022-05-27
下一篇:
Python helpers.render_template函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap