prefeiturasp/SME-PratoAberto-Editor

View on GitHub
app.py

Summary

Maintainability
F
1 wk
Test Coverage

File app.py has 1671 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import collections
import datetime
import itertools
import json
import os
Severity: Major
Found in app.py - About 4 days to fix

    Function atualiza_historico_escolas has a Cognitive Complexity of 73 (exceeds 5 allowed). Consider refactoring.
    Open

    def atualiza_historico_escolas():
        data = request.form.get('json_dump', request.data)
        jdata = json.loads(data)
        jdata = [dict(t) for t in set([tuple(d.items()) for d in jdata])]
        flag_verificacoes = True
    Severity: Minor
    Found in app.py - About 1 day to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Function upload_file has a Cognitive Complexity of 41 (exceeds 5 allowed). Consider refactoring.
    Open

    def upload_file():
        if 'file' not in request.files:
            flash('Nenhum arquivo foi selecionado!', 'danger')
            return redirect(url_for('backlog'))
    
    
    Severity: Minor
    Found in app.py - About 6 hrs to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Function upload_terceirizadas has a Cognitive Complexity of 31 (exceeds 5 allowed). Consider refactoring.
    Open

    def upload_terceirizadas():
        headers = {'Content-type': 'application/json'}
        data = request.form.get('json_dump', request.data)
        jdata = json.loads(data)
        cardapios = []
    Severity: Minor
    Found in app.py - About 4 hrs to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Function escolas has a Cognitive Complexity of 31 (exceeds 5 allowed). Consider refactoring.
    Open

    def escolas(id_escola=None):
        form = SchoolRegistrationForm(request.form)
        if id_escola:
            school = get_escola(id_escola, raw=True)
            form.cod_eol.data = id_escola
    Severity: Minor
    Found in app.py - About 4 hrs to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Function calendario_grupo_cardapio has a Cognitive Complexity of 28 (exceeds 5 allowed). Consider refactoring.
    Open

    def calendario_grupo_cardapio():
        data = request.form.get('json_dump', request.data)
    
        charset = ['"', '[', ']']
        for char in charset:
    Severity: Minor
    Found in app.py - About 4 hrs to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Function calendario has a Cognitive Complexity of 26 (exceeds 5 allowed). Consider refactoring.
    Open

    def calendario():
        """
        do pendencias_publicacao vem pra ca quando se clica em href="/calendario?
    
        """
    Severity: Minor
    Found in app.py - About 3 hrs to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Function get_cardapios_unidades_especiais has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring.
    Open

    def get_cardapios_unidades_especiais(request_obj, semana_default=None):
        params = request_obj.query_string.decode('utf-8')
        if 'filtro_semana' in params:
            week_filter = request_obj.args.get('filtro_semana')
            initial_date = datetime.datetime.strptime(week_filter.split(' - ')[0], '%d/%m/%Y').strftime('%Y%m%d')
    Severity: Minor
    Found in app.py - About 2 hrs to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Function get_escolas_dict has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
    Open

    def get_escolas_dict(params=None, by_type=None, limit=None):
        schools, _ = get_escolas(params=params, limit=limit)
        schools_dict = []
        if by_type and len(by_type):
            if 'TODOS' in by_type:
    Severity: Minor
    Found in app.py - About 2 hrs to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Function mapa_pendencias has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
    Open

    def mapa_pendencias():
        if request.method == "GET":
            mapa = get_quebras_escolas()
    
            delta_dias = datetime.timedelta(days=7)
    Severity: Minor
    Found in app.py - About 1 hr to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Function atualiza_config_cardapio has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
    Open

    def atualiza_config_cardapio():
        form = OutSourcedMenuForm(request.form)
        new_menu = list()
        if 'is_unidade_especial' in request.form:
            new_menu.append('UE')
    Severity: Minor
    Found in app.py - About 1 hr to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Function publicacao has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
    Open

    def publicacao():
        opt_status = ('STATUS', 'PUBLICADO', 'PENDENTE', 'SALVO', 'DELETADO')
    
        if 'refer' in session:
            if '/download_publicacao' not in request.referrer:
    Severity: Minor
    Found in app.py - About 1 hr to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Function adicionar_escola has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
    Open

    def adicionar_escola():
        form = SchoolRegistrationForm(request.form)
        if not form.validate():
            flash('Ocorreu um erro ao salvar as informações')
            return redirect('editor/escolas?nome=&tipo_unidade=&limit=100&agrupamento=TODOS&tipo_atendimento=TODOS', code=302)
    Severity: Minor
    Found in app.py - About 1 hr to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Function get_pendencias has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
    Open

    def get_pendencias(request_obj, semana_default=None):
        params = request_obj.query_string.decode('utf-8')
        if 'filtro_semana' in params:
            week_filter = request_obj.args.get('filtro_semana')
            initial_date = datetime.datetime.strptime(week_filter.split(' - ')[0], '%d/%m/%Y').strftime('%Y%m%d')
    Severity: Minor
    Found in app.py - About 1 hr to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Function unidades_especiais has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
    Open

    def unidades_especiais(id_unidade_especial=None):
        form = SpecialUnitForm(request.form)
        form_filter = FilterTypeSchoolForm(request.form)
        by_type = form_filter.school_types.data
        if id_unidade_especial:
    Severity: Minor
    Found in app.py - About 1 hr to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Function get_quebras_escolas has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
    Open

    def get_quebras_escolas():
        escolas, paginacao = get_escolas()
        mapa_base = collections.defaultdict(list)
        for escola in escolas:
            try:
    Severity: Minor
    Found in app.py - About 1 hr to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Function get_publicados has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
    Open

    def get_publicados(request_obj, default_week):
        params = request_obj.query_string.decode('utf-8')
    
        if 'filtro_semana_mes' in params:
            week_filter = request_obj.args.get('filtro_semana_mes')
    Severity: Minor
    Found in app.py - About 45 mins to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Avoid deeply nested control flow statements.
    Open

                            for idade, v4 in v3.items():
                                for data, v5 in v4.items():
                                    query = {
                                        'tipo_atendimento': tipo_atendimento,
                                        'tipo_unidade': tipo_unidade,
    Severity: Major
    Found in app.py - About 45 mins to fix

      Avoid deeply nested control flow statements.
      Open

                          if _flag == True:
                              # Encontramos o cardapio
                              posicao = count
                          count += 1
      Severity: Major
      Found in app.py - About 45 mins to fix

        Function dowload_special_unit has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
        Open

        def dowload_special_unit():
            if request.method == 'POST':
                try:
                    ue_id = request.form['unit_special']
        
        
        Severity: Minor
        Found in app.py - About 45 mins to fix

        Cognitive Complexity

        Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

        A method's cognitive complexity is based on a few simple rules:

        • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
        • Code is considered more complex for each "break in the linear flow of the code"
        • Code is considered more complex when "flow breaking structures are nested"

        Further reading

        Function get_cardapios_iguais has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
        Open

        def get_cardapios_iguais():
            url = api + '/editor/cardapios?status=PENDENTE&status=SALVO'
            r = requests.get(url)
            refeicoes = r.json()
        
        
        Severity: Minor
        Found in app.py - About 45 mins to fix

        Cognitive Complexity

        Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

        A method's cognitive complexity is based on a few simple rules:

        • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
        • Code is considered more complex for each "break in the linear flow of the code"
        • Code is considered more complex when "flow breaking structures are nested"

        Further reading

        Function deletados has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
        Open

        def deletados():
            if request.method == "GET":
                deletados = get_deletados()
                deletados = sort_array_date_br(deletados)
                deletados_unicos = []
        Severity: Minor
        Found in app.py - About 45 mins to fix

        Cognitive Complexity

        Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

        A method's cognitive complexity is based on a few simple rules:

        • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
        • Code is considered more complex for each "break in the linear flow of the code"
        • Code is considered more complex when "flow breaking structures are nested"

        Further reading

        Avoid deeply nested control flow statements.
        Open

                            for _key in _keys:
                                if cardapio[_key] != quebra[_key]:
                                    _flag = False
        
        
        Severity: Major
        Found in app.py - About 45 mins to fix

          Function get_escolas has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
          Open

          def get_escolas(params=None, limit=None):
              url = api + '/v2/editor/escolas'
              if params:
                  extra = "?" + "&".join([("{}={}".format(p[0], p[1])) for p in params.items()])
                  url += extra
          Severity: Minor
          Found in app.py - About 35 mins to fix

          Cognitive Complexity

          Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

          A method's cognitive complexity is based on a few simple rules:

          • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
          • Code is considered more complex for each "break in the linear flow of the code"
          • Code is considered more complex when "flow breaking structures are nested"

          Further reading

          Function filtrar_cardapios has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
          Open

          def filtrar_cardapios(params_dict):
              cardapio_aux = []
              url = api + '/editor/cardapios?data_inicial={}&data_final={}'.format(params_dict['data_inicial'], params_dict['data_final'])
              # filtro de  tipo de unidade e tipo de atendimento.
              if params_dict['tipo_unidade'] != 'TODOS':
          Severity: Minor
          Found in app.py - About 25 mins to fix

          Cognitive Complexity

          Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

          A method's cognitive complexity is based on a few simple rules:

          • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
          • Code is considered more complex for each "break in the linear flow of the code"
          • Code is considered more complex when "flow breaking structures are nested"

          Further reading

          Function get_grupo_publicacoes has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
          Open

          def get_grupo_publicacoes(status, data_inicial, data_final):
              url = api + '/editor/cardapios?status=' + status + '&data_inicial=' + data_inicial + '&data_final=' + data_final
              r = requests.get(url)
              refeicoes = r.json()
          
          
          Severity: Minor
          Found in app.py - About 25 mins to fix

          Cognitive Complexity

          Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

          A method's cognitive complexity is based on a few simple rules:

          • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
          • Code is considered more complex for each "break in the linear flow of the code"
          • Code is considered more complex when "flow breaking structures are nested"

          Further reading

          Function visualizador has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
          Open

          def visualizador():
              args = request.args
          
              ##### Optimation referrer #####
              if args.get('status') == 'PUBLICADO':
          Severity: Minor
          Found in app.py - About 25 mins to fix

          Cognitive Complexity

          Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

          A method's cognitive complexity is based on a few simple rules:

          • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
          • Code is considered more complex for each "break in the linear flow of the code"
          • Code is considered more complex when "flow breaking structures are nested"

          Further reading

          Function get_deletados has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
          Open

          def get_deletados():
              url = api + '/editor/cardapios?status=DELETADO'
              r = requests.get(url)
              refeicoes = r.json()
          
          
          Severity: Minor
          Found in app.py - About 25 mins to fix

          Cognitive Complexity

          Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

          A method's cognitive complexity is based on a few simple rules:

          • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
          • Code is considered more complex for each "break in the linear flow of the code"
          • Code is considered more complex when "flow breaking structures are nested"

          Further reading

          There are no issues that match your filters.

          Category
          Status