<commit_before>import logging

from django.views.generic import View, TemplateView
from django import forms
from django.shortcuts import redirect, Http404
from django.core.urlresolvers import reverse
from django.views.decorators.csrf import csrf_exempt
from django.contrib import messages


logger = logging.getLogger(__name__)


class RouterViewMixin(object):
    view_name = None
    path_suffix = None
    csrf_exempt = False

    # This is set in the constructor, but the attribute must exist already.
    view_def = None

    def redirect_to(self, name, **kwargs):
        return redirect(self.get_view_url(name, **kwargs))

    def get_view_url(self, view_name, **kwargs):
        return self.view_def.get_view_url(view_name, **kwargs)

    def get_next_view(self, router):
        return 'show'


class RouterTemplateView(RouterViewMixin, TemplateView):
    template_base = 'router'

    def get_template_names(self):
        return [self.get_template_name(self.view_name)]

    def get_template_name(self, name):
        return '%s/%s.html' % (self.template_base, name)


class RouterApiView(RouterViewMixin, View):
    pass


class StartRouterView(RouterApiView):
    view_name = 'start'
    path_suffix = 'start/'

    def post(self, request, router):
        raise NotImplementedError('TODO')


class StopRouterView(RouterApiView):
    view_name = 'stop'
    path_suffix = 'stop/'

    def post(self, request, router):
        raise NotImplementedError('TODO')


class ArchiveRouterView(RouterApiView):
    view_name = 'archive'
    path_suffix = 'archive/'

    def post(self, request, router):
        router.set_status_finished()
        router.save()
        messages.add_message(<commit_msg>Archive routers through the router_api.<commit_after>import logging

from django.views.generic import View, TemplateView
from django import forms
from django.shortcuts import redirect, Http404
from django.core.urlresolvers import reverse
from django.views.decorators.csrf import csrf_exempt
from django.contrib import messages


logger = logging.getLogger(__name__)


class RouterViewMixin(object):
    view_name = None
    path_suffix = None
    csrf_exempt = False

    # This is set in the constructor, but the attribute must exist already.
    view_def = None

    def redirect_to(self, name, **kwargs):
        return redirect(self.get_view_url(name, **kwargs))

    def get_view_url(self, view_name, **kwargs):
        return self.view_def.get_view_url(view_name, **kwargs)

    def get_next_view(self, router):
        return 'show'


class RouterTemplateView(RouterViewMixin, TemplateView):
    template_base = 'router'

    def get_template_names(self):
        return [self.get_template_name(self.view_name)]

    def get_template_name(self, name):
        return '%s/%s.html' % (self.template_base, name)


class RouterApiView(RouterViewMixin, View):
    pass


class StartRouterView(RouterApiView):
    view_name = 'start'
    path_suffix = 'start/'

    def post(self, request, router):
        raise NotImplementedError('TODO')


class StopRouterView(RouterApiView):
    view_name = 'stop'
    path_suffix = 'stop/'

    def post(self, request, router):
        raise NotImplementedError('TODO')


class ArchiveRouterView(RouterApiView):
    view_name = 'archive'
    path_suffix = 'archive/'

    def post(self, request, router):
        router_api = request.user_api.get_router_api(
            router.router_type, router.key)
        router_api.archive_router()
        messages.add_message(
{'fraction_non_alphanumeric': 0.09217638691322902, 'fraction_numerical': 0.0017069701280227596, 'mean_word_length': 3.796725784447476, 'pattern_counts': {'":': 0, '<': 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': '215070', 'n_tokens_mistral': 1093, 'n_tokens_neox': 1044, 'n_words': 262}