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


Python Answer.get方法代码示例

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


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

示例1: test_voting_security

# 需要导入模块: from models import Answer [as 别名]
# 或者: from models.Answer import get [as 别名]
 def test_voting_security(self):
     answer = Answer.create(question = self.question, text= 'fake answer', creator = self.avatar)
     self.app.get(answer.voting_url+'/up', status = 302)
     answer = Answer.get(answer.key())
     self.assertEqual(answer.vote_count, 1)
     self.logout()
     self.app.get(answer.voting_url+'/down', status = 302)
     answer = Answer.get(answer.key())
     self.assertEqual(answer.vote_count, 1)        
开发者ID:sudhirj,项目名称:boragle,代码行数:11,代码来源:web_question_tests.py

示例2: set_answer

# 需要导入模块: from models import Answer [as 别名]
# 或者: from models.Answer import get [as 别名]
def set_answer(puzzle_name, player_id, question, content_type, content):
    player = Player.get(Player.id == player_id)
    puzzle, _ = Puzzle.get_or_create(name=puzzle_name)
    try:
        answer = Answer.get(
            (Answer.puzzle == puzzle) & (Answer.player == player))
    except Answer.DoesNotExist:
        answer = Answer(puzzle=puzzle, player=player)

    answer.question = question

    if content_type == 'text':
        answer.value = content
    elif content_type == 'image':
        filename = '%s_%s.jpg' %  (puzzle.id, player.id)
        path = '%s/images/%s' % (STATIC_DIR, filename)
        with open(path, 'wb') as fp:
            fp.write(content)
        answer.value = 'image:' + filename
    elif content_type == 'video':
        filename = '%s_%s.mp4' %  (puzzle.id, player.id)
        path = '%s/videos/%s' % (STATIC_DIR, filename)
        with open(path, 'wb') as fp:
            fp.write(content)
        answer.value = 'video:' + filename

    answer.save()
开发者ID:ChickTech,项目名称:puzzle-hunt,代码行数:29,代码来源:flask_app.py

示例3: statistics

# 需要导入模块: from models import Answer [as 别名]
# 或者: from models.Answer import get [as 别名]
def statistics(request):
    _check_for_admin()
    question = get_question()
    chooses = question.chooses
    answers = dict((ans.key().id(), {"answer":ans, "count": 0, "chooses":[]}) for ans in question.answers)

    for choose in chooses:
        for answer in Answer.get(choose.answers):
            if answer:
                key = answer.key()
                id = key.id()
                answers[id]["count"] += 1
                answer = Answer.get(key)
                answers[id]["chooses"] = Choose.gql("where answers = :1 order by when", answer).fetch(200)

    return render_to_response('statistics.html', {
            'answers':sorted(answers.items(), key=lambda a:a[1]["count"], reverse=True)
        }, context_instance=RequestContext(request))
开发者ID:soswow,项目名称:yet-another-one-poll-on-app-engine,代码行数:20,代码来源:views.py

示例4: question

# 需要导入模块: from models import Answer [as 别名]
# 或者: from models.Answer import get [as 别名]
def question(request, qid, **kwargs):

    session_data = {}
    if local.request.session['uid']:
        session_data['user_name'] = User.get_by_id(local.request.session['uid'])[0].name
    try:
        question = Question.get_by_id(qid)[0]
    except TypeError:
        return not_found(request)

    question.views += 1
    question.update()

    edit = question.latest_edit()[0]
    category = Category.get_by_id(question.category_id)[0]
    user = User.get_by_id(question.user_id)[0]
    
    question_data =  {
        'title' : str(edit.title),
        'category' : str(category.name),
        'votes' : str(question.votes),
        'author' : str(user.name),
        'author_id' : str(user.id),
        'avatar' : str(user.avatar),
        'views' : str(question.views),
        'created' : str(question.created),
        'body' : str(edit.body),
        }
    
    try:
        answers_list = Answer.get(where=('question_id', qid), order=('votes', 'desc'))
        answer_data_list = []
        for answer in answers_list:
            answer_user = User.get_by_id(answer.user_id)[0]
            answer_edit = AnswerEdit.get(where=('answer_id', answer.id))[0]
            answer_data = {
                'votes' : str(answer.votes),
                'author' : str(answer_user.name),
                'author_id' : str(answer_user.id),
                'avatar' : str(answer_user.avatar),
                'body' : str(answer_edit.body),
                }
            answer_data_list.append(answer_data)
            
    except TypeError:
        answer_data_list = False
    
    page = Page(session_data)
    page.title = str(edit.title) + ' - Meno'
    content = Thread(question_data, answer_data_list)
    local.request.session['last'] = request.base_url
    return respond(page.render(content))
开发者ID:lachlanmarks,项目名称:meno,代码行数:54,代码来源:views.py

示例5: user

# 需要导入模块: from models import Answer [as 别名]
# 或者: from models.Answer import get [as 别名]
def user(request, uid, **kwargs):
    user = User.get_by_id(uid)[0]
    questions = Question.get(where=('author_id', uid), order=('date_created', 'desc'))
    try:
        user.questions_count = len(questions)
    except TypeError:
        user.questions_count = None

    answers = Answer.get(where=('author_id', uid), order=('date_created', 'desc'))
    try:
        user.answers_count = len(questions)
    except TypeError:
        user.answers_count = None

    session_data = {}
    if local.request.session['uid']:
        session_data['user_name'] = User.get_by_id(local.request.session['uid'])[0].name

    page = Page(session_data)
    page.title = user.name + "'s Profile - Meno"
    content = Profile(user)

    local.request.session['last'] = request.base_url
    return respond(page.render(content))
开发者ID:lachlanmarks,项目名称:meno,代码行数:26,代码来源:views.py


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