Esempio n. 1
0
def sidebar_widget(context):
    user = context.get('user', None)
    if not user or not user.is_authenticated():
        return ''

    if QuizGame.disabled():
        return ''

    number_of_active_quizzes = Quiz.objects.filter(status='A', type='P').count()

    return render_to_string('quiz/sidebar.html',
                            {'number_of_active_quizzes': number_of_active_quizzes})
Esempio n. 2
0
    def dispatch(self, request, *args, **kwargs):
        if QuizGame.disabled():
            return redirect('wouso.interface.views.homepage')

        profile = request.user.get_profile()
        self.quiz_user = profile.get_extension(QuizUser)
        self.quiz = get_object_or_404(Quiz, pk=kwargs['id'])
        self.through = UserToQuiz.objects.get(user=self.quiz_user, quiz=self.quiz)

        # check if user is eligible to play quiz
        if not self.through.can_play_again() and not self.quiz_user.user.is_staff:
            messages.error(request,
                           _('You can replay this quiz in {days} day(s)!'.format(
                               days=self.through.days_until_can_replay)), )
            # redirect to same page
            return HttpResponseRedirect(request.META.get('HTTP_REFERER'))

        return super(QuizView, self).dispatch(request, *args, **kwargs)