本文整理汇总了Python中models.QotdGame.get_for_today方法的典型用法代码示例。如果您正苦于以下问题:Python QotdGame.get_for_today方法的具体用法?Python QotdGame.get_for_today怎么用?Python QotdGame.get_for_today使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.QotdGame
的用法示例。
在下文中一共展示了QotdGame.get_for_today方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: sidebar_widget
# 需要导入模块: from models import QotdGame [as 别名]
# 或者: from models.QotdGame import get_for_today [as 别名]
def sidebar_widget(context):
# TODO: nothing should happen in the sidebar_widget
user = context.get('user', None)
if not user or not user.is_authenticated():
return ''
if QotdGame.disabled():
return ''
qotd = QotdGame.get_for_today()
qotd_user = user.get_profile().get_extension(QotdUser)
if not qotd_user.has_question:
qotd_user.set_question(qotd)
else:
qotd = qotd_user.my_question
if qotd_user.has_answered:
time_passed = datetime.now() - qotd_user.last_answered
qotd_user.reset_question()
if time_passed > timedelta(seconds=120): # two minutes
return ''
return render_to_string('qotd/sidebar.html',
{'question': qotd,
'quser': qotd_user,
'qotd': QotdGame,
'id': 'qotd'})
示例2: index
# 需要导入模块: from models import QotdGame [as 别名]
# 或者: from models.QotdGame import get_for_today [as 别名]
def index(request):
if QotdGame.disabled():
return HttpResponseRedirect(reverse('wouso.interface.views.homepage'))
qotd = QotdGame.get_for_today()
profile = request.user.get_profile()
qotd_user = profile.get_extension(QotdUser)
if qotd_user.has_answered:
return HttpResponseRedirect(reverse('games.qotd.views.done'))
if qotd is None:
form = None
elif request.method == "POST":
form = QotdForm(qotd, request.POST)
if form.is_valid():
choice = int(form.cleaned_data['answers'])
QotdGame.answered(qotd_user, qotd, choice)
return HttpResponseRedirect(reverse('games.qotd.views.done'))
else:
form = QotdForm(qotd)
return render_to_response('qotd/index.html',
{'question': qotd, 'form': form},
context_instance=RequestContext(request))
示例3: sidebar_widget
# 需要导入模块: from models import QotdGame [as 别名]
# 或者: from models.QotdGame import get_for_today [as 别名]
def sidebar_widget(request):
qotd = QotdGame.get_for_today()
qotd_user = request.user.get_profile().get_extension(QotdUser)
if qotd_user.has_answered:
time_passed = datetime.now() - qotd_user.last_answered
if time_passed > timedelta(seconds=120): # two minutes
return ''
return render_to_string('qotd/sidebar.html', {'question': qotd, 'quser': qotd_user, 'qotd': QotdGame})
示例4: read
# 需要导入模块: from models import QotdGame [as 别名]
# 或者: from models.QotdGame import get_for_today [as 别名]
def read(self, request):
question = QotdGame.get_for_today()
try:
qotduser = request.user.get_profile().get_extension(QotdUser)
except models.Model.DoesNotExist:
raise Http404()
if question:
return {'text': question.text, 'answers': dict([(a.id, a.text) for a in question.answers]),
'had_answered': qotduser.has_answered}
return {}
示例5: sidebar_widget
# 需要导入模块: from models import QotdGame [as 别名]
# 或者: from models.QotdGame import get_for_today [as 别名]
def sidebar_widget(request):
qotd = QotdGame.get_for_today()
qotd_user = request.user.get_profile().get_extension(QotdUser)
if not qotd_user.has_question:
qotd_user.set_question(qotd)
else:
qotd = qotd_user.my_question
if qotd_user.has_answered:
time_passed = datetime.now() - qotd_user.last_answered
qotd_user.reset_question()
if time_passed > timedelta(seconds=120): # two minutes
return ""
return render_to_string("qotd/sidebar.html", {"question": qotd, "quser": qotd_user, "qotd": QotdGame})
示例6: sidebar_widget
# 需要导入模块: from models import QotdGame [as 别名]
# 或者: from models.QotdGame import get_for_today [as 别名]
def sidebar_widget(request):
# TODO: nothing should happen in the sidebar_widget
qotd = QotdGame.get_for_today()
qotd_user = request.user.get_profile().get_extension(QotdUser)
if not qotd_user.has_question:
qotd_user.set_question(qotd)
else:
qotd = qotd_user.my_question
if qotd_user.has_answered:
time_passed = datetime.now() - qotd_user.last_answered
qotd_user.reset_question()
if time_passed > timedelta(seconds=120): # two minutes
return ''
return render_to_string('qotd/sidebar.html', {'question': qotd, 'quser': qotd_user, 'qotd': QotdGame})
示例7: create
# 需要导入模块: from models import QotdGame [as 别名]
# 或者: from models.QotdGame import get_for_today [as 别名]
def create(self, request):
question = QotdGame.get_for_today()
try:
qotduser = request.user.get_profile().get_extension(QotdUser)
except models.Model.DoesNotExist:
raise Http404()
if not question:
return {'success': False, 'error': 'No question for today'}
if qotduser.has_answered:
return {'success': False, 'error': 'User already answered'}
attrs = self.flatten_dict(request.data)
if 'answer' not in attrs.keys():
return {'success': False, 'error': 'Answer not provided'}
try:
answer_id = int(attrs['answer'])
answer = Answer.objects.get(pk=answer_id)
except ValueError, Answer.DoesNotExist:
return {'success': False, 'error': 'Invalid answer'}
示例8: sidebar_widget
# 需要导入模块: from models import QotdGame [as 别名]
# 或者: from models.QotdGame import get_for_today [as 别名]
def sidebar_widget(context):
# TODO: nothing should happen in the sidebar_widget
user = context.get("user", None)
if not user or not user.is_authenticated():
return ""
qotd = QotdGame.get_for_today()
qotd_user = user.get_profile().get_extension(QotdUser)
if not qotd_user.has_question:
qotd_user.set_question(qotd)
else:
qotd = qotd_user.my_question
if qotd_user.has_answered:
time_passed = datetime.now() - qotd_user.last_answered
qotd_user.reset_question()
if time_passed > timedelta(seconds=120): # two minutes
return ""
return render_to_string("qotd/sidebar.html", {"question": qotd, "quser": qotd_user, "qotd": QotdGame, "id": "qotd"})
示例9: index
# 需要导入模块: from models import QotdGame [as 别名]
# 或者: from models.QotdGame import get_for_today [as 别名]
def index(request):
if QotdGame.disabled():
return HttpResponseRedirect(reverse('wouso.interface.views.homepage'))
profile = request.user.get_profile()
qotd_user = profile.get_extension(QotdUser)
if qotd_user.has_modifier('qotd-blind'):
return render_to_response('qotd/index.html', {"error":_("You have been blinded,you cannot answer to the Question of the Day")}, context_instance=RequestContext(request))
if not qotd_user.has_question:
qotd = QotdGame.get_for_today()
qotd_user.set_question(qotd)
else:
qotd = qotd_user.my_question
if qotd_user.has_answered:
qotd_user.reset_question()
extra = request.GET.urlencode()
if extra:
extra = '?' + extra
return HttpResponseRedirect(reverse('games.qotd.views.done') + extra)
if qotd is None:
form = None
elif request.method == "POST":
form = QotdForm(qotd, request.POST)
if form.is_valid():
choice = int(form.cleaned_data['answers'])
QotdGame.answered(qotd_user, qotd, choice)
extra = request.GET.urlencode()
if extra:
extra = '?' + extra
return HttpResponseRedirect(reverse('games.qotd.views.done') + extra)
else:
form = QotdForm(qotd)
return render_to_response('qotd/index.html',
{'question': qotd, 'form': form},
context_instance=RequestContext(request))
示例10: index
# 需要导入模块: from models import QotdGame [as 别名]
# 或者: from models.QotdGame import get_for_today [as 别名]
def index(request):
if QotdGame.disabled():
return HttpResponseRedirect(reverse("wouso.interface.views.homepage"))
profile = request.user.get_profile()
qotd_user = profile.get_extension(QotdUser)
if qotd_user.magic.has_modifier("qotd-blind"):
messages.error(request, _("You have been blinded,you cannot answer to the Question of the Day"))
return redirect("games.qotd.views.history")
elif not qotd_user.has_question:
qotd = QotdGame.get_for_today()
qotd_user.set_question(qotd)
else:
qotd = qotd_user.my_question
if qotd_user.has_answered:
qotd_user.reset_question()
extra = request.GET.urlencode()
if extra:
extra = "?" + extra
return HttpResponseRedirect(reverse("games.qotd.views.done") + extra)
if qotd is None:
form = None
elif request.method == "POST":
form = QotdForm(qotd, request.POST)
if form.is_valid():
choice = int(form.cleaned_data["answers"])
QotdGame.answered(qotd_user, qotd, choice)
extra = request.GET.urlencode()
if extra:
extra = "?" + extra
return HttpResponseRedirect(reverse("games.qotd.views.done") + extra)
else:
form = QotdForm(qotd)
return render_to_response(
"qotd/index.html", {"question": qotd, "form": form}, context_instance=RequestContext(request)
)
示例11: dispatch
# 需要导入模块: from models import QotdGame [as 别名]
# 或者: from models.QotdGame import get_for_today [as 别名]
def dispatch(self, request, *args, **kwargs):
if QotdGame.disabled():
return redirect('wouso.interface.views.homepage')
profile = request.user.get_profile()
self.qotd_user = profile.get_extension(QotdUser)
if self.qotd_user.magic.has_modifier('qotd-blind'):
messages.error(request, _("You have been blinded, you cannot answer to the Question of the Day"))
return redirect('games.qotd.views.history')
elif not self.qotd_user.has_question:
self.qotd = QotdGame.get_for_today()
self.qotd_user.set_question(self.qotd)
else:
self.qotd = self.qotd_user.my_question
if self.qotd_user.has_answered:
self.qotd_user.reset_question()
return redirect('games.qotd.views.history')
return super(QotdView, self).dispatch(request, *args, **kwargs)
示例12: done
# 需要导入模块: from models import QotdGame [as 别名]
# 或者: from models.QotdGame import get_for_today [as 别名]
def done(request):
if QotdGame.disabled():
return HttpResponseRedirect(reverse('wouso.interface.views.homepage'))
# Do not show results until done
if not request.user.get_profile().get_extension(QotdUser).has_answered:
return HttpResponseRedirect(reverse("games.qotd.views.index"))
qotd = QotdGame.get_for_today()
user = request.user.get_profile().get_extension(QotdUser)
choice = user.last_answer
ans = [a for a in qotd.answers if a.id == choice]
if ans:
ans = ans[0]
valid = ans.correct
else:
ans = None
valid = False
return render_to_response('qotd/done.html',
{'question': qotd, 'choice': ans, 'valid': valid,},
context_instance=RequestContext(request))