• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python models.QotdGame类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: sidebar_widget

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'})
开发者ID:ArmandNM,项目名称:wouso,代码行数:26,代码来源:views.py


示例2: index

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))
开发者ID:alexef,项目名称:wouso-1,代码行数:27,代码来源:views.py


示例3: post

    def post(self, request, *args, **kwargs):
        if self.qotd is None:
            form = None
        else:
            form = QotdForm(self.qotd, request.POST)
            if form.is_valid():
                choice = int(form.cleaned_data['answers'])
                QotdGame.answered(self.qotd_user, self.qotd, choice)
                return redirect('games.qotd.views.done')

        return render_to_response('qotd/index.html',
                                  {'question': self.qotd, 'form': form},
                                  context_instance=RequestContext(request))
开发者ID:ArmandNM,项目名称:wouso,代码行数:13,代码来源:views.py


示例4: post

    def post(self, request, *args, **kwargs):
        if self.qotd is None:
            form = None
        else:
            form = QotdForm(self.qotd, request.POST)
            if form.is_valid():
                choice = int(form.cleaned_data["answers"])
                QotdGame.answered(self.qotd_user, self.qotd, choice)
                return redirect("games.qotd.views.done")

        return render_to_response(
            "qotd/index.html", {"question": self.qotd, "form": form}, context_instance=RequestContext(request)
        )
开发者ID:jessepollak,项目名称:wouso,代码行数:13,代码来源:views.py


示例5: done

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"))

    user = request.user.get_profile().get_extension(QotdUser)
    qotd = user.my_question

    if not qotd:
        return redirect("homepage")

    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)
    )
开发者ID:tiriplicamihai,项目名称:wouso,代码行数:25,代码来源:views.py


示例6: done

def done(request):
    if QotdGame.disabled():
        return redirect('wouso.interface.views.homepage')
    # Do not show results until done
    if not request.user.get_profile().get_extension(QotdUser).has_answered:
        return redirect('games.qotd.views.history')

    user = request.user.get_profile().get_extension(QotdUser)
    qotd = user.my_question

    if not qotd:
        return redirect("homepage")

    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))
开发者ID:ArmandNM,项目名称:wouso,代码行数:27,代码来源:views.py


示例7: sidebar_widget

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})
开发者ID:alexef,项目名称:wouso-1,代码行数:9,代码来源:views.py


示例8: read

 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 {}
开发者ID:AndreiRO,项目名称:wouso,代码行数:10,代码来源:api.py


示例9: index

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))
开发者ID:TomyRO,项目名称:wouso,代码行数:41,代码来源:views.py


示例10: index

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)
    )
开发者ID:tiriplicamihai,项目名称:wouso,代码行数:41,代码来源:views.py


示例11: dispatch

    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)
开发者ID:Ciocirlan,项目名称:wouso,代码行数:21,代码来源:views.py


示例12: sidebar_widget

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})
开发者ID:tiriplicamihai,项目名称:wouso,代码行数:15,代码来源:views.py


示例13: sidebar_widget

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})
开发者ID:dragoscalinescu,项目名称:wouso,代码行数:16,代码来源:views.py


示例14: create

 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'}
开发者ID:AndreiRO,项目名称:wouso,代码行数:18,代码来源:api.py


示例15: sidebar_widget

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"})
开发者ID:jessepollak,项目名称:wouso,代码行数:19,代码来源:views.py


示例16: history

def history(request):
    return render_to_response(
        'qotd/history.html',
        {'history': QotdGame.get_history()},
        context_instance=RequestContext(request))
开发者ID:ArmandNM,项目名称:wouso,代码行数:5,代码来源:views.py


示例17: history

def history(request):
    return render_to_response(
        "qotd/history.html", {"history": QotdGame.get_history()}, context_instance=RequestContext(request)
    )
开发者ID:jessepollak,项目名称:wouso,代码行数:4,代码来源:views.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python models.Question类代码示例发布时间:2022-05-27
下一篇:
Python models.Publish类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap