<commit_before>from pprint import pprint

from django.contrib.auth.mixins import PermissionRequiredMixin

from fo2.connections import db_cursor_so

from base.paginator import paginator_basic
from base.views import O2BaseGetPostView

from cd.forms.endereco import EnderecoForm
from cd.functions.estante import gera_estantes_enderecos
from cd.queries.endereco import (
    add_endereco,
    query_endereco,
)


class Endereco(PermissionRequiredMixin, O2BaseGetPostView):

    def __init__(self, *args, **kwargs):
        super(Endereco, self).__init__(*args, **kwargs)
        self.Form_class = EnderecoForm
        self.form_class_has_initial = True
        self.cleaned_data2self = True
        self.permission_required = 'cd.can_admin_pallet'
        self.template_name = 'cd/endereco.html'
        self.title_name = 'Endereços'
        self.cleaned_data2self = True

    def mount_context(self):
        cursor = db_cursor_so(self.request)
        data = query_endereco(self.tipo)

        count_add = 0
        if self.tipo == 'ES':
            enderecos = gera_estantes_enderecos()
            for endereco in enderecos:
                if not next(
                    (d for d in data if d['end'] == endereco),
                    False
                ):
                    add_endereco(cursor, endereco)
                    count_add += 1

        if count_add:
            data = query_endereco(self.tipo)

        data = paginator_basic(data, 50, self.page)

        if self.tipo == 'TO':
            headers = ['Espaço']
            fields = ['espaco']
        else:            
            headers = []
            fields = []
        headers += ['Endereço', 'Rota']<commit_msg>view Endereco: retirando código repetido<commit_after>from pprint import pprint

from django.contrib.auth.mixins import PermissionRequiredMixin

from fo2.connections import db_cursor_so

from base.paginator import paginator_basic
from base.views import O2BaseGetPostView

from cd.forms.endereco import EnderecoForm
from cd.functions.estante import gera_estantes_enderecos
from cd.queries.endereco import (
    add_endereco,
    query_endereco,
)


class Endereco(PermissionRequiredMixin, O2BaseGetPostView):

    def __init__(self, *args, **kwargs):
        super(Endereco, self).__init__(*args, **kwargs)
        self.Form_class = EnderecoForm
        self.form_class_has_initial = True
        self.cleaned_data2self = True
        self.permission_required = 'cd.can_admin_pallet'
        self.template_name = 'cd/endereco.html'
        self.title_name = 'Endereços'

    def mount_context(self):
        cursor = db_cursor_so(self.request)
        data = query_endereco(self.tipo)

        count_add = 0
        if self.tipo == 'ES':
            enderecos = gera_estantes_enderecos()
            for endereco in enderecos:
                if not next(
                    (d for d in data if d['end'] == endereco),
                    False
                ):
                    add_endereco(cursor, endereco)
                    count_add += 1

        if count_add:
            data = query_endereco(self.tipo)

        data = paginator_basic(data, 50, self.page)

        if self.tipo == 'TO':
            headers = ['Espaço']
            fields = ['espaco']
        else:            
            headers = []
            fields = []
        headers += ['Endereço', 'Rota']
{'fraction_non_alphanumeric': 0.08632453277959062, 'fraction_numerical': 0.005043013942450311, 'mean_word_length': 2.154349859681946, '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': '1172358', 'n_tokens_mistral': 1057, 'n_tokens_neox': 1021, 'n_words': 223}