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


Python models.QotdGame类代码示例

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


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


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