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


Python base.User类代码示例

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


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

示例1: copy_users

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

示例2: setUp

 def setUp(self):
     rfk.init()
     rfk.database.init_db("sqlite://")
     setup_settings()
     try:
         self.user = User.add_user('teddydestodes', 'roflmaoblubb')
         self.other_user = User.add_user('test', 'test')
     except UserNameTakenException:
         pass
     rfk.database.session.commit()
开发者ID:AlexCherkashin,项目名称:PyRfK,代码行数:10,代码来源:test_liquidsoaphandler.py

示例3: last_shows

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

示例4: next_shows

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

示例5: doMetaData

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

示例6: settings

def settings():
    form = SettingsForm(request.form,
                        username=current_user.username,
                        email=current_user.mail,
                        show_def_name=current_user.get_setting(code='show_def_name'),
                        show_def_desc=current_user.get_setting(code='show_def_desc'),
                        show_def_tags=current_user.get_setting(code='show_def_tags'),
                        show_def_logo=current_user.get_setting(code='show_def_logo'),
                        use_icy=current_user.get_setting(code='use_icy'))

    if request.method == "POST" and form.validate():
        if current_user.check_password(password=form.old_password.data):
            if form.new_password.data:
                current_user.password = User.make_password(form.new_password.data)
            current_user.mail = form.email.data
            current_user.set_setting(code='show_def_name', value=form.show_def_name.data)
            current_user.set_setting(code='show_def_desc', value=form.show_def_desc.data)
            current_user.set_setting(code='show_def_tags', value=form.show_def_tags.data)
            current_user.set_setting(code='show_def_logo', value=form.show_def_logo.data)
            current_user.set_setting(code='use_icy', value=form.use_icy.data)
            rfk.database.session.commit()
            flash(gettext('Settings successfully updated.'), 'success')
            return redirect(url_for('settings'))
        else:
            form.old_password.errors.append(gettext('Wrong password.'))

    return render_template('settings.html', form=form, TITLE='Settings',
                           imgur={'client': rfk.CONFIG.get('site', 'imgur-client')})
开发者ID:Marzipanmarmelade,项目名称:PyRfK,代码行数:28,代码来源:__init__.py

示例7: doConnect

def doConnect(data):
    """handles a connect from liquidsoap
    
    Keyword arguments:
    data -- list of headers
    
    """
    logger.info('connect request %s' % (json.dumps(data),))
    try:
        auth = data['Authorization'].strip().split(' ')
        if auth[0].lower() == 'basic':
            username, password = base64.b64decode(auth[1]).split(':', 1)
            if username == 'source':
                username, password = password.split(username_delimiter, 1)
        else:
            raise ValueError
        user = User.authenticate(username, password)
        if user.get_setting(code='use_icy'):
            if 'ice-genre' in data:
                user.set_setting(data['ice-genre'],code='icy_show_genre')
            if 'ice-name' in data:
                user.set_setting(data['ice-name'],code='icy_show_name')
            if 'ice-description' in data:
                user.set_setting(data['ice-description'],code='icy_show_description')
        show = init_show(user)
        rfk.database.session.commit()
        logger.info('accepted connect for %s' %(user.username,))
        print user.user
    except (rexc.base.UserNotFoundException, rexc.base.InvalidPasswordException, KeyError):
        logger.info('rejected connect')
        kick()
开发者ID:alphabernd,项目名称:PyRfK,代码行数:31,代码来源:liquidsoaphandler.py

示例8: login

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

示例9: doAuth

def doAuth(username, password):
    """authenticates the user
    this function will also disconnect the current user
    if the user to be authenticated has a show registered.
    if that happened this function will print false to the
    user since we need a graceperiod to actually disconnect
    the other user.
    
    Keyword arguments:
    username
    password
    
    """
    if username == 'source':
        username, password = password.split(username_delimiter)
    try:
        user = User.authenticate(username, password)
        show = Show.get_current_show(user)
        if show is not None and show.flags & Show.FLAGS.PLANNED:
            if kick():
                logger.info('kicking user')
                sys.stdout.write('false')
                return
        logger.info('accepted auth for %s' %(username,))
        sys.stdout.write('true')
    except rexc.base.InvalidPasswordException:
        logger.info('rejected auth for %s (invalid password)' %(username,))
        sys.stdout.write('false')
    except rexc.base.UserNotFoundException:
        logger.info('rejected auth for %s (invalid user)' %(username,))
        sys.stdout.write('false')
    rfk.database.session.commit()
开发者ID:alphabernd,项目名称:PyRfK,代码行数:32,代码来源:liquidsoaphandler.py

示例10: login

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

示例11: setup_default_user

def setup_default_user(username, password):
    users = [User.add_user(username, password)]
    for user in users:
        rfk.database.session.add(user)
        user.add_permission(code='manage-liquidsoap')
        user.add_permission(code='manage-relays')
        user.add_permission(code='admin')
        print "[users] Added %s" % user.username
    rfk.database.session.commit()
开发者ID:AlexCherkashin,项目名称:PyRfK,代码行数:9,代码来源:install.py

示例12: last_tracks

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

示例13: last_tracks

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

示例14: check

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

示例15: setUp

    def setUp(self):
        rfk.init()
        rfk.database.init_db("sqlite://")

        app.template_folder = '../templates/'
        app.static_folder = '../static/'
        app.static_url_path = '/static'
        self.app = app.test_client()

        user_1 = User.add_user('teddydestodes', 'roflmaoblubb')
        user_2 = User.add_user('loom', 'bestes')

        key_1 = ApiKey(application='app_1', description='key_1', user=user_1)
        key_1.gen_key()
        self.key_1 = key_1.key
        key_2 = ApiKey(application='app_2', description='key_2', user=user_2, flag=ApiKey.FLAGS.DISABLED)
        key_2.gen_key()
        self.key_2 = key_2.key
        rfk.database.session.add(key_1, key_2)

        rfk.database.session.commit()
开发者ID:AlexCherkashin,项目名称:PyRfK,代码行数:21,代码来源:test_api.py


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