<commit_before>from django.views.generic.list import ListView
from django.views.generic.base import TemplateView
from django.views.generic.detail import DetailView
from django.utils.decorators import method_decorator
from django.contrib.auth.decorators import login_required
from django.core.exceptions import PermissionDenied
from django.http import Http404, HttpResponseRedirect
from django.core.urlresolvers import reverse, reverse_lazy
from django.conf import settings
from django.utils.translation import ugettext_lazy as _
from orders.models import LineFollowerJuniorStage #LineFollowerStage,
from results.models import LineFollowerJuniorResult, \
    ConstructionResult, DroneResult, StairClimbingResult, \
    ColorSelectingResult, ScenarioResult, InnovativeJuryResult, \
    InnovativeJury, InnovativeTotalResult, LineFootballResult, \
    TrafficResult, MazeResult
    #LineFollowerResult,
from sumo.models import *


RESULTS_DICT = {
    # "line_follower": LineFollowerResult,
    "line_follower_junior": LineFollowerJuniorResult,
    "construction": ConstructionResult,
    "drone": DroneResult,
    "stair_climbing": StairClimbingResult,
    "color_selecting": ColorSelectingResult,
    "scenario": ScenarioResult,
    "innovative": InnovativeJuryResult,
    "traffic": TrafficResult,
    "line_football": LineFootballResult,
    "maze": MazeResult,
}


class ResultListView(ListView):
    template_name = 'results/result_list.html'

    def dispatch(self, *args, **kwargs):
        category = self.kwargs.get('slug')
        if not category in dict(settings.ALL_CATEGORIES).keys():
            raise Http404
        if not settings.PROJECT_RESULTS or \
           not category in dict(settings.RESULT_CATEGORIES).keys():
            raise PermissionDenied
        if category == 'line_follower':
            return HttpResponseRedirect(
                reverse('line_follower_stage_result_list'))
        elif category == 'line_follower_junior':
            return redirect(reverse('line_follower_junior_stage_result_list'))
        elif category == 'micro_sumo':
            return HttpResponseRedirect(reverse('sumo_result_home'))
        elif category == 'innovative':
            return HttpResponseRedirect(reverse('innovative_referee'))

        return super(ResultListView, self).dispatch(*args, **kwargs)

    def get_queryset(self):
        result_model = RESULTS_DICT[self.kwargs.get('slug')]
        return result_model.objects.filter(is_best=True)

    def get_context_data(self, **kwargs):
        context = super(ResultListView, self).get_context_data(**kwargs)
        context['category'] = dict(
            settings.ALL_CATEGORIES)[self.kwargs.get('slug')]

        return context


# class LineFollowerStageResultListView(ListView):
#     model = LineFollowerStage
#     template_name = 'results/line_follower_stage_list.html'
#<commit_msg>add RefereeHomeView<commit_after>from django.views.generic.list import ListView
from django.views.generic.base import TemplateView
from django.views.generic.detail import DetailView
from django.utils.decorators import method_decorator
from django.contrib.auth.decorators import login_required
from django.core.exceptions import PermissionDenied
from django.http import Http404, HttpResponseRedirect
from django.core.urlresolvers import reverse, reverse_lazy
from django.conf import settings
from django.utils.translation import ugettext_lazy as _
from orders.models import LineFollowerJuniorStage #LineFollowerStage,
from results.models import LineFollowerJuniorResult, \
    ConstructionResult, DroneResult, StairClimbingResult, \
    ColorSelectingResult, ScenarioResult, InnovativeJuryResult, \
    InnovativeJury, InnovativeTotalResult, LineFootballResult, \
    TrafficResult, MazeResult
    #LineFollowerResult,
from sumo.models import *


RESULTS_DICT = {
    # "line_follower": LineFollowerResult,
    "line_follower_junior": LineFollowerJuniorResult,
    "construction": ConstructionResult,
    "drone": DroneResult,
    "stair_climbing": StairClimbingResult,
    "color_selecting": ColorSelectingResult,
    "scenario": ScenarioResult,
    "innovative": InnovativeJuryResult,
    "traffic": TrafficResult,
    "line_football": LineFootballResult,
    "maze": MazeResult,
}


class ResultListView(ListView):
    template_name = 'results/result_list.html'

    def dispatch(self, *args, **kwargs):
        category = self.kwargs.get('slug')
        if not category in dict(settings.ALL_CATEGORIES).keys():
            raise Http404
        if not settings.PROJECT_RESULTS or \
           not category in dict(settings.RESULT_CATEGORIES).keys():
            raise PermissionDenied
        if category == 'line_follower':
            return HttpResponseRedirect(
                reverse('line_follower_stage_result_list'))
        elif category == 'line_follower_junior':
            return redirect(reverse('line_follower_junior_stage_result_list'))
        elif category == 'micro_sumo':
            return HttpResponseRedirect(reverse('sumo_result_home'))
        elif category == 'innovative':
            return HttpResponseRedirect(reverse('innovative_referee'))

        return super(ResultListView, self).dispatch(*args, **kwargs)

    def get_queryset(self):
        result_model = RESULTS_DICT[self.kwargs.get('slug')]
        return result_model.objects.filter(is_best=True)

    def get_context_data(self, **kwargs):
        context = super(ResultListView, self).get_context_data(**kwargs)
        context['category'] = dict(
            settings.ALL_CATEGORIES)[self.kwargs.get('slug')]

        return context

class RefereeHomeView(TemplateView):
    template_name = "referee/home.html"

    def dispatch(self, *args, **kwargs):
        if not self.request.user.is_superuser and \
           not self.request.user.has_group("referee"):
            raise PermissionDenied
        return super(RefereeHomeView, self).dispatch(*args, **kwargs)

    def get_context_data(self, **kwargs):
        context = super(RefereeHomeView, self).get_context_data(**kwargs)
        context["categories"] = settings.ORDER_CATEGORIES
        return context



# class LineFollowerStageResultListView(ListView):
#     model = LineFollowerStage
#     template_name = 'results/line_follower_stage_list.html'
#
{'fraction_non_alphanumeric': 0.08963540837446267, 'fraction_numerical': 0.001910523801942366, 'mean_word_length': 4.086639676113361, 'pattern_counts': {'":': 22, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3673111', 'n_tokens_mistral': 1850, 'n_tokens_neox': 1761, 'n_words': 361}