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


Python User.get_user方法代码示例

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


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

示例1: last_shows

# 需要导入模块: from rfk.database.base import User [as 别名]
# 或者: from rfk.database.base.User import get_user [as 别名]
def last_shows():
    """Return show history

    Keyword arguments:
        - dj_id -- filter by dj
        - dj_name -- filter by dj
        - limit -- limit the output (default=5)
    """

    dj_id = request.args.get("dj_id", None)
    dj_name = request.args.get("dj_name", None)
    limit = request.args.get("limit", 5)

    clauses = [Show.end < datetime.utcnow()]

    try:
        if dj_id:
            clauses.append(UserShow.user == User.get_user(id=dj_id))
        if dj_name:
            clauses.append(UserShow.user == User.get_user(username=dj_name))

        result = Show.query.join(UserShow).filter(*clauses).order_by(Show.begin.desc()).limit(limit).all()

        data = {"last_shows": {"shows": []}}
        if result:
            for show in result:

                begin = show.begin.isoformat()
                end = show.end.isoformat()

                dj = []
                for usershow in show.users:
                    dj.append(
                        {"dj_name": usershow.user.username, "dj_id": usershow.user.user, "status": usershow.status}
                    )

                data["last_shows"]["shows"].append(
                    {
                        "show_id": show.show,
                        "show_name": show.name,
                        "show_description": show.description,
                        "show_flags": show.flags,
                        "show_begin": begin,
                        "show_end": end,
                        "dj": dj,
                    }
                )
        else:
            data = {"last_shows": None}
        return jsonify(wrapper(data))
    except UserNotFoundException:
        return jsonify(wrapper({"last_shows": None}))
开发者ID:AlexCherkashin,项目名称:PyRfK,代码行数:54,代码来源:web.py

示例2: next_shows

# 需要导入模块: from rfk.database.base import User [as 别名]
# 或者: from rfk.database.base.User import get_user [as 别名]
def next_shows():
    """Return the next planned show(s)

    Keyword arguments:
        - dj_id -- filter by dj
        - dj_name -- filter by dj
        - limit -- limit the output (default=5)
    """

    dj_id = request.args.get('dj_id', None)
    dj_name = request.args.get('dj_name', None)
    limit = request.args.get('limit', 5)

    clauses = []
    clauses.append(Show.begin > datetime.utcnow())
    try:
        if dj_id:
            clauses.append(UserShow.user == User.get_user(id=dj_id))
        if dj_name:
            clauses.append(UserShow.user == User.get_user(username=dj_name))

        result = Show.query.join(UserShow).filter(*clauses).order_by(Show.begin.asc()).limit(limit).all()

        data = {'next_shows': {'shows': []}}
        if result:
            for show in result:

                begin = show.begin.isoformat()
                end = show.end.isoformat()

                dj = []
                for usershow in show.users:
                    dj.append(
                        {'dj_name': usershow.user.username, 'dj_id': usershow.user.user, 'status': usershow.status})

                data['next_shows']['shows'].append({
                    'show_id': show.show,
                    'show_name': show.name,
                    'show_description': show.description,
                    'show_flags': show.flags,
                    'show_begin': begin,
                    'show_end': end,
                    'dj': dj
                })
        else:
            data = {'next_shows': None}
        return jsonify(wrapper(data))
    except UserNotFoundException:
        return jsonify(wrapper({'next_shows': None}))
开发者ID:keios,项目名称:PyRfK,代码行数:51,代码来源:web.py

示例3: doMetaData

# 需要导入模块: from rfk.database.base import User [as 别名]
# 或者: from rfk.database.base.User import get_user [as 别名]
def doMetaData(data):
    logger.debug('meta %s' % (json.dumps(data),))
    if 'userid' not in data or data['userid'] == 'none':
        print 'no userid'
        return
    user = User.get_user(id=data['userid'])
    if user == None:
        print 'user not found'
        return

    if 'artist' in data:
        artist = data['artist'].strip()
    else:
        artist = None

    if 'title' in data:
        title = data['title'].strip()
    else:
        title = None

    if 'song' in data:
        song = data['song'].split(' - ', 1)
        if (artist is None) or (len(artist) == 0):
            artist = song[0]
        if (title is None) or (len(title) == 0):
            title = song[1]
    show = init_show(user)
    if artist is None and title is None:
        track = Track.current_track()
        if track:
            track.end_track()
    else:
        track = Track.new_track(show, artist, title)
    rfk.database.session.commit()
开发者ID:keios,项目名称:PyRfK,代码行数:36,代码来源:liquidsoaphandler.py

示例4: login

# 需要导入模块: from rfk.database.base import User [as 别名]
# 或者: from rfk.database.base.User import get_user [as 别名]
def login():
    form = login_form(request.form)
    if request.method == 'POST' and form.validate():
        username = form.username.data
        try:
            user = User.get_user(username=username)
            if user and user.check_password(password=form.password.data):
                user.authenticated = True
                remember = form.remember.data
                if login_user(user, remember=remember):
                    if not user.last_login:
                        flash(gettext('<strong>Tip:</strong> It appears that this is your first login, if you need any help please visit our help section by clicking <a href="/help">here</a>.'), 'info')
                    user.last_login = now()
                    loc = rfk.helper.get_location(request.remote_addr)
                    if 'country_code' in loc and loc['country_code'] is not None:
                        user.country = loc['country_code']
                    rfk.database.session.commit()
                    flash(gettext('Login successful. Welcome %s!' % user.username), 'success')
                    return redirect(request.args.get('next') or url_for('index'))
                else:
                    form.username.errors.append(gettext('There was an error while logging you in.'))
                    #flash('There was an error while logging you in.', 'error')
            else:
                form.username.errors.append(gettext('Invalid User or Password.'))
                #flash('Invalid username or password.')
        except UserNotFoundException:
            form.username.errors.append(gettext('Invalid User or Password.'))
            #flash('Invalid username or password.')
    return render_template('login.html', form=form, TITLE='Login')
开发者ID:Marzipanmarmelade,项目名称:PyRfK,代码行数:31,代码来源:__init__.py

示例5: login

# 需要导入模块: from rfk.database.base import User [as 别名]
# 或者: from rfk.database.base.User import get_user [as 别名]
def login():
    form = login_form(request.form)
    if request.method == 'POST' and form.validate():
        username = form.username.data
        try:
            user = User.get_user(username=username)
            if user and user.check_password(password=form.password.data):
                user.authenticated = True
                remember = form.remember.data
                if login_user(user, remember=remember):
                    user.last_login = now()
                    loc = rfk.helper.get_location(request.remote_addr)
                    if 'country_code' in loc and loc['country_code'] is not None:
                        user.country = loc['country_code']
                    rfk.database.session.commit()
                    flash('Logged in!', 'success')
                    return redirect(request.args.get('next') or url_for('index'))
                else:
                    form.username.errors.append('There was an error while logging you in.')
                    flash('There was an error while logging you in.', 'error')
            else:
                form.username.errors.append('Invalid User or Password.')
                flash('Invalid username or password.')
        except UserNotFoundException:
            form.username.errors.append('Invalid User or Password.')
            flash('Invalid username or password.')
    return render_template('login.html', form=form, TITLE='Login')
开发者ID:keios,项目名称:PyRfK,代码行数:29,代码来源:__init__.py

示例6: copy_users

# 需要导入模块: from rfk.database.base import User [as 别名]
# 或者: from rfk.database.base.User import get_user [as 别名]
def copy_users():
    streamer = oldsession.query(Streamer).yield_per(50)
    
    for olduser in streamer:
        print olduser.username
        if User.get_user(olduser.username) is None:
            user = User.add_user(olduser.username, olduser.password)
            rfk.database.session.add(user)
            rfk.database.session.flush()
    rfk.database.session.commit()
开发者ID:AlexCherkashin,项目名称:PyRfK,代码行数:12,代码来源:mk3tomk4.py

示例7: last_tracks

# 需要导入模块: from rfk.database.base import User [as 别名]
# 或者: from rfk.database.base.User import get_user [as 别名]
def last_tracks():
    """Return the last played tracks
    
    Keyword arguments:
        dj_id -- filter by dj
        dj_name -- filter by dj
        limit -- limit the output (default=5)
    """
    
    dj_id = request.args.get('dj_id', None)
    dj_name = request.args.get('dj_name', None)
    limit = request.args.get('limit', 5)
    limit = limit if limit <= 50 else 50
    
    clauses = []
    clauses.append(Track.end < datetime.utcnow())
    
    if dj_id is not None:
        clauses.append(UserShow.user == User.get_user(id=dj_id))
    if dj_name is not None:
        clauses.append(UserShow.user == User.get_user(username=dj_name))
        
    result = Track.query.filter(*clauses).order_by(Track.end.desc()).limit(limit).all()
    
    data = {'last_tracks': {'tracks': []}}
    if result:
        for track in result:
            
            begin = track.begin.isoformat()
            end = track.end.isoformat()
            
            data['last_tracks']['tracks'].append({
                'track_id': track.track,
                'track_begin': begin,
                'track_end': end,
                'track_title': track.title.name,
                'track_artist': track.title.artist.name
            })
    else:
        data = {'last_tracks': None}
    return jsonify(wrapper(data))
开发者ID:alphabernd,项目名称:PyRfK,代码行数:43,代码来源:web.py

示例8: last_tracks

# 需要导入模块: from rfk.database.base import User [as 别名]
# 或者: from rfk.database.base.User import get_user [as 别名]
def last_tracks():
    """Return the last played tracks

    Keyword arguments:
        - dj_id -- filter by dj
        - dj_name -- filter by dj
        - limit -- limit the output (default=5)
    """

    dj_id = request.args.get("dj_id", None)
    dj_name = request.args.get("dj_name", None)
    limit = int(request.args.get("limit", 5))
    limit = limit if limit <= 50 else 50

    clauses = [Track.end < datetime.utcnow()]

    if dj_id is not None:
        clauses.append(UserShow.user == User.get_user(id=dj_id))
    if dj_name is not None:
        clauses.append(UserShow.user == User.get_user(username=dj_name))

    result = Track.query.join(Show).join(UserShow).filter(*clauses).order_by(Track.end.desc()).limit(limit).all()

    data = {"last_tracks": {"tracks": []}}
    if result:
        for track in result:
            begin = track.begin.isoformat()
            end = track.end.isoformat()

            data["last_tracks"]["tracks"].append(
                {
                    "track_id": track.track,
                    "track_begin": begin,
                    "track_end": end,
                    "track_title": track.title.name,
                    "track_artist": track.title.artist.name,
                }
            )
    else:
        data = {"last_tracks": None}
    return jsonify(wrapper(data))
开发者ID:AlexCherkashin,项目名称:PyRfK,代码行数:43,代码来源:web.py

示例9: check

# 需要导入模块: from rfk.database.base import User [as 别名]
# 或者: from rfk.database.base.User import get_user [as 别名]
def check():
    ret = {}
    try:
        if User.get_user(username=request.form['username']) == None:
            ret['username'] = 'ok'
        else:
            ret['username'] = 'taken'
    except KeyError:
        pass
    response = jsonify(ret)
    response.status_code = 200
    return response
开发者ID:AlexCherkashin,项目名称:PyRfK,代码行数:14,代码来源:register.py

示例10: info

# 需要导入模块: from rfk.database.base import User [as 别名]
# 或者: from rfk.database.base.User import get_user [as 别名]
def info(user):
    user = User.get_user(username=user)

    upcoming_shows = Show.query.join(UserShow).filter(UserShow.user == user, Show.begin >= now()).order_by(
        Show.begin.asc()).limit(5).all()
    last_shows = Show.query.join(UserShow).filter(UserShow.user == user, Show.end <= now()).order_by(
        Show.end.desc()).limit(5).all()
    if user:
        ball = iso_country_to_countryball(user.country)
        return render_template('user/info.html',
                               username=user.username,
                               ball=ball,
                               st=user.get_total_streamtime(),
                               shows={'upcoming': upcoming_shows, 'last': last_shows})
    else:
        abort(404)
开发者ID:keios,项目名称:PyRfK,代码行数:18,代码来源:__init__.py

示例11: doMetaData

# 需要导入模块: from rfk.database.base import User [as 别名]
# 或者: from rfk.database.base.User import get_user [as 别名]
def doMetaData(data):
    logger.debug('meta %s' % (json.dumps(data),))
    if 'userid' not in data or data['userid'] == 'none':
        print 'no userid'
        return
    user = User.get_user(id=data['userid'])
    if user == None:
        print 'user not found'
        return
    artist = data['artist'] or ''
    title = data['title'] or ''
    if 'song' in data:
        song = data['song'].split(' - ', 1)
        if ('artist' not in data) or (len(data['artist'].strip()) == 0):
            artist = song[0]
        if ('title' not in data) or (len(data['title'].strip()) == 0):
            title = song[1]
    show = init_show(user)
    track = Track.new_track(show, artist, title)
    rfk.database.session.commit()
开发者ID:alphabernd,项目名称:PyRfK,代码行数:22,代码来源:liquidsoaphandler.py

示例12: copy_shows

# 需要导入模块: from rfk.database.base import User [as 别名]
# 或者: from rfk.database.base.User import get_user [as 别名]
def copy_shows():
    local = pytz.timezone('Europe/Berlin')
    shows = oldsession.query(Show).yield_per(50)
    for oldshow in shows:
        if oldshow.streamer != None:
            user = User.get_user(username=oldshow.streamer.username)
            if oldshow.type == 'UNPLANNED':
                flag = NShow.FLAGS.UNPLANNED
            elif oldshow.type == 'PLANNED':
                flag = NShow.FLAGS.PLANNED
            show = NShow(name=oldshow.name[:50],
                        description=oldshow.description,
                        flags=flag,
                        begin=local.normalize(local.localize(oldshow.begin).astimezone(pytz.utc)),
                        end=local.normalize(local.localize(oldshow.end).astimezone(pytz.utc)))
            rfk.database.session.add(show)
            rfk.database.session.flush()
            show.add_user(user)
            rfk.database.session.flush()
            rfk.database.session.commit()
开发者ID:AlexCherkashin,项目名称:PyRfK,代码行数:22,代码来源:mk3tomk4.py

示例13: dj

# 需要导入模块: from rfk.database.base import User [as 别名]
# 或者: from rfk.database.base.User import get_user [as 别名]
def dj():
    """Return complete dj information
    
    Keyword arguments:
        dj_id -- database id of the requested dj
        dj_name -- nickname of the requested dj
    
    At least one argument is required
    """
    
    dj_id = request.args.get('dj_id', None)
    dj_name = request.args.get('dj_name', None)
    try:
        user = User.get_user(id=dj_id, username=dj_name)
        return jsonify(wrapper({'dj': {'dj_id': user.user,
                                       'dj_name': user.username }}))
    except rexc.base.UserNotFoundException:
        return jsonify(wrapper({'dj': None}))
    except AssertionError:
        return jsonify(wrapper(None, 400, 'missing required query parameter'))
开发者ID:alphabernd,项目名称:PyRfK,代码行数:22,代码来源:web.py

示例14: doDisconnect

# 需要导入模块: from rfk.database.base import User [as 别名]
# 或者: from rfk.database.base.User import get_user [as 别名]
def doDisconnect(userid):
    logger.info('doDisconnect: diconnect for userid %s' % (userid,))
    if userid == "none" or userid == '':
        print "Whooops no userid?"
        logger.warn('doDisconnect: no userid supplied!')
        rfk.database.session.commit()
        return
    user = User.get_user(id=int(userid))
    if user:
        usershows = UserShow.query.filter(UserShow.user == user,
                                          UserShow.status == UserShow.STATUS.STREAMING).all()
        for usershow in usershows:
            usershow.status = UserShow.STATUS.STREAMED
            if usershow.show.flags & Show.FLAGS.UNPLANNED:
                usershow.show.end_show()
        rfk.database.session.commit()
        track = Track.current_track()
        if track:
            track.end_track()
        rfk.database.session.commit()
    else:
        print "no user found"
开发者ID:NinjaTune,项目名称:PyRfK,代码行数:24,代码来源:liquidsoaphandler.py

示例15: finish

# 需要导入模块: from rfk.database.base import User [as 别名]
# 或者: from rfk.database.base.User import get_user [as 别名]
def finish():
    ret = {'success': False}
    try:
        if not User.check_username(request.form['username']):
            ret['username'] = 'invalid'
        elif len(request.form['password']) == 0:
            ret['password'] = 'invalid'
        elif len(request.form['stream_password']) == 0:
            ret['stream_password'] = 'invalid'
        elif User.get_user(username=request.form['username']) == None:
            ret['success'] = True
            user = User(request.form['username'],
                        User.make_password(request.form['password']),
                        User.make_password(request.form['stream_password']))
            session.add(user)
            session.commit()
        else:
            ret['username'] = 'taken'
    except KeyError:
        pass
    response = jsonify(ret)
    response.status_code = 200
    return response
开发者ID:AlexCherkashin,项目名称:PyRfK,代码行数:25,代码来源:register.py


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