本文整理汇总了Python中models.WorkshopGame.get_for_now方法的典型用法代码示例。如果您正苦于以下问题:Python WorkshopGame.get_for_now方法的具体用法?Python WorkshopGame.get_for_now怎么用?Python WorkshopGame.get_for_now使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.WorkshopGame
的用法示例。
在下文中一共展示了WorkshopGame.get_for_now方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: play
# 需要导入模块: from models import WorkshopGame [as 别名]
# 或者: from models.WorkshopGame import get_for_now [as 别名]
def play(request):
"""
Play current workshop or show expired message.
"""
workshop = WorkshopGame.get_for_now()
player = request.user.get_profile()
error = ''
if not workshop:
return do_error(request, _('No current workshop'))
elif player not in workshop.semigroup.players.all():
return do_error(request, _('You are not in the current semigroup'))
elif not workshop.is_active():
return do_error(request, _('Workshop is not active'))
assesment = Assesment.objects.get_or_create(player=player, workshop=workshop)[0]
if assesment.answered:
return do_error(request, _('You have already answered this workshop'))
if request.method == 'POST':
answers = {}
for q in workshop.questions.all():
answers[q.id] = request.POST.get('answer_%d' % q.id)
assesment.set_answered(answers)
return redirect('workshop_index_view')
return render_to_response('workshop/play.html',
{'assesment': assesment,
'workshop': workshop},
context_instance=RequestContext(request)
)
示例2: index
# 需要导入模块: from models import WorkshopGame [as 别名]
# 或者: from models.WorkshopGame import get_for_now [as 别名]
def index(request, extra_context=None):
player = request.user.get_profile()
assesment = Assesment.get_for_player_and_workshop(request.user.get_profile(), WorkshopGame.get_for_now())
if not extra_context:
extra_context = {}
extra_context.update({'workshopgame': WorkshopGame, 'workshop': WorkshopGame.get_for_player_now(player),
'assesment': assesment})
return render_to_response('workshop/index.html',
extra_context,
context_instance=RequestContext(request)
)