<commit_before>from django.conf import settings
from django.contrib import messages
from django.contrib.auth.decorators import permission_required
from django.contrib.auth.mixins import PermissionRequiredMixin
from django.db import transaction
from django.db.models import Count, OuterRef, Subquery
from django.shortcuts import get_object_or_404, redirect, render
from django.views.generic import View
from django_tables2 import RequestConfig

from extras.models import Graph, GRAPH_TYPE_PROVIDER
from utilities.forms import ConfirmationForm
from utilities.paginator import EnhancedPaginator
from utilities.views import (
    BulkDeleteView, BulkEditView, BulkImportView, ObjectDeleteView, ObjectEditView, ObjectListView,
)
from . import filters, forms, tables
from .constants import TERM_SIDE_A, TERM_SIDE_Z
from .models import Circuit, CircuitTermination, CircuitType, Provider


#
# Providers
#

class ProviderListView(PermissionRequiredMixin, ObjectListView):
    permission_required = 'circuits.view_provider'
    queryset = Provider.objects.annotate(count_circuits=Count('circuits'))
    filter = filters.ProviderFilter
    filter_form = forms.ProviderFilterForm
    table = tables.ProviderDetailTable
    template_name = 'circuits/provider_list.html'


class ProviderView(PermissionRequiredMixin, View):
    permission_required = 'circuits.view_provider'

    def get(self, request, slug):

        provider = get_object_or_404(Provider, slug=slug)
        circuits = Circuit.objects.filter(provider=provider).prefetch_related('type', 'tenant', 'terminations__site')
        circuits_table = tables.CircuitTable(circuits, orderable=False)
        show_graphs = Graph.objects.filter(type=GRAPH_TYPE_PROVIDER).exists()

        paginate = {
            'paginator_class': EnhancedPaginator,
            'per_page': request.GET.get('per_page', settings.PAGINATE_COUNT)
        }
        RequestConfig(request, paginate).configure(circuits_table)

        return render(request, 'circuits/provider.html', {
            'provider': provider,
            'circuits_table': circuits_table,
            'show_graphs': show_graphs,
        })


class ProviderCreateView(PermissionRequiredMixin, ObjectEditView):
    permission_required = 'circuits.add_provider'
    model = Provider
    model_form = forms.ProviderForm
    template_name = 'circuits/provider_edit.html'
    default_return_url = 'circuits:provider_list'


class ProviderEditView(ProviderCreateView):
    permission_required = 'circuits.change_provider'<commit_msg>Hid the provider column<commit_after>from django.conf import settings
from django.contrib import messages
from django.contrib.auth.decorators import permission_required
from django.contrib.auth.mixins import PermissionRequiredMixin
from django.db import transaction
from django.db.models import Count, OuterRef, Subquery
from django.shortcuts import get_object_or_404, redirect, render
from django.views.generic import View
from django_tables2 import RequestConfig

from extras.models import Graph, GRAPH_TYPE_PROVIDER
from utilities.forms import ConfirmationForm
from utilities.paginator import EnhancedPaginator
from utilities.views import (
    BulkDeleteView, BulkEditView, BulkImportView, ObjectDeleteView, ObjectEditView, ObjectListView,
)
from . import filters, forms, tables
from .constants import TERM_SIDE_A, TERM_SIDE_Z
from .models import Circuit, CircuitTermination, CircuitType, Provider


#
# Providers
#

class ProviderListView(PermissionRequiredMixin, ObjectListView):
    permission_required = 'circuits.view_provider'
    queryset = Provider.objects.annotate(count_circuits=Count('circuits'))
    filter = filters.ProviderFilter
    filter_form = forms.ProviderFilterForm
    table = tables.ProviderDetailTable
    template_name = 'circuits/provider_list.html'


class ProviderView(PermissionRequiredMixin, View):
    permission_required = 'circuits.view_provider'

    def get(self, request, slug):

        provider = get_object_or_404(Provider, slug=slug)
        circuits = Circuit.objects.filter(provider=provider).prefetch_related('type', 'tenant', 'terminations__site')
        show_graphs = Graph.objects.filter(type=GRAPH_TYPE_PROVIDER).exists()

        circuits_table = tables.CircuitTable(circuits, orderable=False)
        circuits_table.columns.hide('provider')

        paginate = {
            'paginator_class': EnhancedPaginator,
            'per_page': request.GET.get('per_page', settings.PAGINATE_COUNT)
        }
        RequestConfig(request, paginate).configure(circuits_table)

        return render(request, 'circuits/provider.html', {
            'provider': provider,
            'circuits_table': circuits_table,
            'show_graphs': show_graphs,
        })


class ProviderCreateView(PermissionRequiredMixin, ObjectEditView):
    permission_required = 'circuits.add_provider'
    model = Provider
    model_form = forms.ProviderForm
    template_name = 'circuits/provider_edit.html'
    default_return_url = 'circuits:provider_list'


class ProviderEditView(ProviderCreateView):
    permission_required = 'circuits.change_provider'
{'fraction_non_alphanumeric': 0.07862311754351653, 'fraction_numerical': 0.0027381185214159984, 'mean_word_length': 4.824601366742597, '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': '1969889', 'n_tokens_mistral': 1495, 'n_tokens_neox': 1387, 'n_words': 303}