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


Python Site.selectBy方法代码示例

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


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

示例1: view_question

# 需要导入模块: from models import Site [as 别名]
# 或者: from models.Site import selectBy [as 别名]
def view_question(site_key, question_id, answer_id=None):
    context = { }
    
    try:
        context['site'] = Site.selectBy(key=site_key).getOne()
    except SQLObjectNotFound:
        raise HTTPError(code=404, output='No site exists with the key %s.' % site_key)
    
    # get the question referenced by this question id
    query = 'id:%s siteKey:%s' % (question_id, site_key)
    results = solr_conn().search(query)
    if len(results) == 0:
        raise HTTPError(code=404, output='No question exists with the ID %s for the site, %s.' % (question_id, context['site'].name))
    
    decode_json_fields(results)
    retrieve_users(results)
    retrieve_sites(results)
    
    result = results.docs[0]
    convert_comments_to_html(result)
    if settings.REWRITE_LINKS_AND_IMAGES:
        rewrite_result(result)
    sort_answers(result)
    context['result'] = result

    context['answer_id'] = answer_id
    
    return render_template('question.html', context)
开发者ID:eplanet,项目名称:offstack,代码行数:30,代码来源:server.py

示例2: site_index

# 需要导入模块: from models import Site [as 别名]
# 或者: from models.Site import selectBy [as 别名]
def site_index(site_key):
    context = { }
    context['sites'] = get_sites()
    
    try:
        context['site'] = Site.selectBy(key=site_key).getOne()
    except SQLObjectNotFound:
        raise HTTPError(code=404, output='No site exists with the key %s.' % site_key)
    
    context['random_questions'] = get_random_questions(site_key=site_key, count=settings.NUM_OF_RANDOM_QUESTIONS)    
    
    return render_template('index.html', context)
开发者ID:eplanet,项目名称:offstack,代码行数:14,代码来源:server.py

示例3: view_answer

# 需要导入模块: from models import Site [as 别名]
# 或者: from models.Site import selectBy [as 别名]
def view_answer(site_key, answer_id):
    context = { }
    
    try:
        context['site'] = Site.selectBy(key=site_key).getOne()
    except SQLObjectNotFound:
        raise HTTPError(code=404, output='No site exists with the key %s.' % site_key)
    
    # get the question referenced by this answer id
    query = 'answerId:%s siteKey:%s' % (answer_id, site_key)
    results = solr_conn().search(query)
    if len(results) == 0:
        raise HTTPError(code=404, output='No answer exists with the ID %s for the site, %s.' % (answer_id, context['site'].name))
    
    question_id = results.docs[0]['id']

    redirect('%s%s/%s/%s' % (settings.APP_URL_ROOT, site_key, question_id, answer_id))
开发者ID:eplanet,项目名称:offstack,代码行数:19,代码来源:server.py

示例4: site_search

# 需要导入模块: from models import Site [as 别名]
# 或者: from models.Site import selectBy [as 别名]
def site_search(site_key):
    context = { }
    # the template uses this to allow searching on other sites
    context['sites'] = get_sites()
    
    try:
        context['site'] = Site.selectBy(key=site_key).getOne()
    except SQLObjectNotFound:
        raise HTTPError(code=404, output='No site exists with the key %s.' % site_key)
    
    # perform the search limited by this site
    search_context = perform_search(site_key)
    if not search_context:
        raise HTTPError(code=500, output='Invalid query attempted.')
    
    context.update(search_context)
    
    return render_template('site_results.html', context)
开发者ID:eplanet,项目名称:offstack,代码行数:20,代码来源:server.py


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