library_indicators/views.py
from .api_connections import RequestLibraryRawDatafrom quero_cultura.views import ParserYAMLfrom quero_cultura.views import get_metabase_urlfrom project_indicators.views import clean_urlfrom .models import LibraryAreafrom .models import LibraryDatafrom .models import LibraryTagsfrom .models import LastUpdateLibraryDatefrom datetime import datetimefrom django.shortcuts import renderfrom celery.decorators import task DEFAULT_INITIAL_DATE = "2012-01-01 15:47:38.337553" # Get graphics urls from metabase# To add new graphis, just add in the metabase_graphics variableview_type = "question"Similar blocks of code found in 4 locations. Consider refactoring.metabase_graphics = [{'id': 1, 'url': get_metabase_url(view_type, 25, "true")}, {'id': 2, 'url': get_metabase_url(view_type, 26, "true")}, {'id': 3, 'url': get_metabase_url(view_type, 27, "true")}, {'id': 4, 'url': get_metabase_url(view_type, 28, "true")}, {'id': 5, 'url': get_metabase_url(view_type, 29, "true")}] detailed_data = [{'id': 1, 'url': get_metabase_url("dashboard", 8, "false")}] page_type = "Bibliotecas"graphic_type = 'library_graphic_detail'Similar blocks of code found in 3 locations. Consider refactoring.page_descripition = "Biblioteca é todo espaço, seja ele concreto ou virtual "\ + "que reúne coleção de informações de qualquer tipo,"\ + "sejam livros, enciclopédias, dicionário, monografias,"\ + " revista, entre outros. Os gráficos abaixo representam"\ + " indicadores culturais extraidos das Bibliotecas"\ + " cadastradas na plataforma" def index(request): return render(request, 'quero_cultura/indicators_page.html', {'metabase_graphics': metabase_graphics, 'detailed_data': detailed_data, 'page_type': page_type, 'graphic_type': graphic_type, 'page_descripition': page_descripition}) Identical blocks of code found in 6 locations. Consider refactoring.def graphic_detail(request, graphic_id): try: graphic = metabase_graphics[int(graphic_id) - 1] except IndexError: return render(request, 'quero_cultura/not_found.html') return render(request, 'quero_cultura/graphic_detail.html', {'graphic': graphic}) Similar blocks of code found in 2 locations. Consider refactoring.@task(name="load_libraries")Function `populate_library_data` has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.def populate_library_data(): if len(LastUpdateLibraryDate.objects) == 0: LastUpdateLibraryDate(DEFAULT_INITIAL_DATE).save() size = LastUpdateLibraryDate.objects.count() last_update = LastUpdateLibraryDate.objects[size - 1].create_date LastUpdateLibraryDate(str(datetime.now())).save() parser_yaml = ParserYAML() urls = parser_yaml.get_multi_instances_urls for url in urls: request = RequestLibraryRawData(last_update, url).data new_url = clean_url(url) for library in request: date = library["createTimestamp"]['date'] accessibility = str(library["acessibilidade"]).capitalize() if accessibility == '' or accessibility == 'None': accessibility = 'Não definido' LibraryData(new_url, library["type"]['name'], accessibility, date).save() for area in library["terms"]["area"]: LibraryArea(new_url, str(area).title()).save() for tag in library["terms"]["tag"]: LibraryTags(new_url, str(tag).title()).save()