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


Python User.lookup_by_attribute方法代码示例

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


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

示例1: profile_edit_view

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import lookup_by_attribute [as 别名]
def profile_edit_view(request):
    """returns current user information.  On POST collects all information
    fromt the page and edits the user and criteria accordingly.
    """
    username = request.authenticated_userid
    user = User.lookup_by_attribute(username=username)[0]
    criteria = Criteria.lookup_by_attribute(user=user)[0]
    if request.method == 'POST':
        User.edit(id=user.id,
                  username=username,
                  firstname=request.params.get('first_name'),
                  lastname=request.params.get('last_name'),
                  restaurants=request.params.get('favorite_restaurants'),
                  food=request.params.get('favorite_food')
                  )
        Criteria.edit(id=criteria.id,
                      location=request.params.getall('location'),
                      taste=request.params.getall('taste'),
                      diet=request.params.getall('diet'),
                      cost=request.params.getall('cost'),
                      age=request.params.getall('age')
                      )
        headers = remember(request, username)
        return HTTPFound(request.route_url(
                         'profile_detail', username=username
                         ),
                         headers=headers)
    profile = {}
    profile['criteria'] = criteria
    profile['username'] = username
    profile['user'] = user
    return profile
开发者ID:kaka0525,项目名称:taste-buddies,代码行数:34,代码来源:views.py

示例2: groupfinder

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import lookup_by_attribute [as 别名]
def groupfinder(uname, request):
    user = User.lookup_by_attribute(username=uname)[0]

    acls = []

    if user:
        for group in user.groups:
            acls.append('group:{}'.format(group.id))

    return acls
开发者ID:kaka0525,项目名称:taste-buddies,代码行数:12,代码来源:security.py

示例3: passes_verification

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import lookup_by_attribute [as 别名]
def passes_verification(request):
    username = request.params.get('username', None)
    udata = User.lookup_by_attribute(username=username)[0]

    try:
        verified_status = udata.confirmed
    except:
        verified_status = False

    return verified_status
开发者ID:kaka0525,项目名称:taste-buddies,代码行数:12,代码来源:views.py

示例4: profile_detail_view

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import lookup_by_attribute [as 别名]
def profile_detail_view(request):
    """will allow the user who owns the profile or any user who is in a group
    with that user to see that users current informmation and criteria.
    """
    if not (request.has_permission('owner')
            or request.has_permission('connect')):
        return HTTPForbidden()

    user = User.lookup_by_attribute(username=request.matchdict['username'])[0]
    profile = {}
    profile['username'] = request.authenticated_userid,
    profile['user'] = user
    profile['criteria'] = Criteria.lookup_by_attribute(user=user)[0]
    return profile
开发者ID:kaka0525,项目名称:taste-buddies,代码行数:16,代码来源:views.py

示例5: do_login

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import lookup_by_attribute [as 别名]
def do_login(request):
    login_result = False
    manager = BCRYPTPasswordManager()

    entered_username = request.params.get('username', None)
    entered_password = request.params.get('password', None)

    user_obj = User.lookup_by_attribute(username=entered_username)[0]
    db_username = user_obj.username

    if entered_username == db_username:
        db_hashed = user_obj.password
        # manager.check returns BOOL
        login_result = manager.check(db_hashed, entered_password)

    return login_result
开发者ID:kaka0525,项目名称:taste-buddies,代码行数:18,代码来源:views.py

示例6: verify

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import lookup_by_attribute [as 别名]
def verify(request):
    error_msg = None
    username = request.authenticated_userid
    user = User.lookup_by_attribute(username=username)[0]

    if request.method == "POST":
        user_vcode = int(request.params.get('verify_code'))
        db_vcode = user.ver_code

        if user_vcode == db_vcode:
            user.edit(id=user.id, confirmed=True)

            action = HTTPFound(
                request.route_url('profile_detail', username=username)
            )

    action = {'username': username, 'error_msg': error_msg}

    return action
开发者ID:kaka0525,项目名称:taste-buddies,代码行数:21,代码来源:views.py

示例7: group_create_view

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import lookup_by_attribute [as 别名]
def group_create_view(request):
    """Collects all information from the page and instanciates a new
    group and its corresponding criteria.
    """
    username = request.authenticated_userid
    admin = User.lookup_by_attribute(username=username)[0]
    if request.method == 'POST':
        group = Group.add(name=request.params.get('name'),
                          description=request.params.get('description'),
                          admin=admin, users=[admin], forum=OrderedDict())
        Criteria.add(location=request.params.getall('location'),
                     taste=request.params.getall('taste'),
                     diet=request.params.getall('diet'),
                     cost=request.params.getall('cost'),
                     age=request.params.getall('age'),
                     group=group)
        return HTTPFound(request.route_url('group_detail',
                         group_name=group.name))
    profile = {}
    profile['criteria'] = Criteria()
    profile['username'] = username
    return profile
开发者ID:kaka0525,项目名称:taste-buddies,代码行数:24,代码来源:views.py

示例8: group_detail_view

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import lookup_by_attribute [as 别名]
def group_detail_view(request):
    """returns current group information.  If recievng input form a form
    will add that user as a group member if they aren't already.  Will look
    to see whether a new discussion is being created and if so, add it
    to the group forum.  If a new post on an existing discussion is created
    that post will be added to the appropriate discussion.  Discussions
    are returned in reverse order.
    """
    username = request.authenticated_userid
    group = Group.lookup_by_attribute(name=request.matchdict['group_name'])[0]
    criteria = Criteria.lookup_by_attribute(group=group)[0]
    if request.method == 'POST':
        user = User.lookup_by_attribute(username=username)[0]
        user.groups.append(group)
        time = datetime.datetime.utcnow()
        if request.params.get('title'):
            title = request.params.get('title')
            group.forum[title] = [(request.params.get('post'), username, time)]
            group.edit(id=group.id, forum=group.forum)
        else:
            title = request.params.items()[0][0]
            post = request.params.items()[0][1]
            group.forum[title].append((post, username, time))
            group.edit(id=group.id, forum=group.forum)
        return HTTPFound(request.route_url(
                         'group_detail',
                         group_name=request.matchdict['group_name'],
                         ))
    profile = {}
    forum = OrderedDict()
    for _ in range(len(group.forum)):
        to_add = group.forum.popitem()
        forum[to_add[0]] = to_add[1]
    profile['forum'] = forum
    profile['criteria'] = criteria
    profile['group'] = group
    profile['username'] = username
    return profile
开发者ID:kaka0525,项目名称:taste-buddies,代码行数:40,代码来源:views.py

示例9: send_verify_email

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import lookup_by_attribute [as 别名]
def send_verify_email(request):

    ver_code = randint(1000, 9999)

    username = request.authenticated_userid
    user = User.lookup_by_attribute(username=username)[0]
    user.edit(id=user.id, ver_code=int(ver_code))

    fromaddr = "[email protected]"
    toaddr = user.email

    msg = MIMEMultipart()
    msg["From"] = fromaddr
    msg["To"] = toaddr
    msg["Subject"] = "Your Tastebuddies Verification Code"

    body = ''

    here = os.path.dirname(os.path.abspath(__file__))
    email_directory = os.path.join(here, 'static', 'email_templates')
    body_template = os.path.join(email_directory, 'body.txt')
    with open(body_template, 'r') as fh:
        body = str(fh.read())

    body = body.format(ver_code=ver_code)

    msg.attach(MIMEText(body, 'plain'))

    server = smtplib.SMTP('smtp.gmail.com', 587)
    server.starttls()
    server.login("tastebot", 'TASTEBUDDIES')
    text = msg.as_string()

    server.sendmail(fromaddr, toaddr, text)

    return HTTPFound(request.route_url('verify'))
开发者ID:kaka0525,项目名称:taste-buddies,代码行数:38,代码来源:views.py


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