當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。