From 56fa90da1efd7d1fec2c8cdbeeb9855687d14927 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lvaro=20Justen=20=28=40turicas=29?= Date: Fri, 10 May 2024 18:36:50 -0300 Subject: [PATCH] make lint --- clipping/admin.py | 31 ++++++++++--------- clipping/apps.py | 2 +- clipping/forms.py | 17 +++++----- .../management/commands/import_clippings.py | 22 ++++++++----- clipping/models.py | 8 ++--- clipping/tests.py | 2 -- clipping/urls.py | 4 +-- clipping/views.py | 13 ++++---- core/views.py | 18 ++++++----- 9 files changed, 64 insertions(+), 53 deletions(-) diff --git a/clipping/admin.py b/clipping/admin.py index f8cb5aaa..fafc9362 100644 --- a/clipping/admin.py +++ b/clipping/admin.py @@ -1,11 +1,10 @@ from django import forms +from django.conf import settings from django.contrib import admin -from django.forms.models import ModelChoiceField - -from .models import ClippingRelation, Clipping from django.contrib.contenttypes.models import ContentType +from django.forms.models import ModelChoiceField -from django.conf import settings +from .models import Clipping, ClippingRelation class ClippingRelationAdminForm(forms.ModelForm): @@ -14,40 +13,44 @@ class ClippingRelationAdminForm(forms.ModelForm): for model_name in settings.CONTENTS[app_name]: contents.append(model_name) - content_type = ModelChoiceField(ContentType.objects.filter(app_label__in=settings.CONTENTS, model__in=contents), - empty_label="--------", label='Content') - object_id = forms.CharField(widget=forms.Select(choices=[('','---------')]), label='Element') + content_type = ModelChoiceField( + ContentType.objects.filter(app_label__in=settings.CONTENTS, model__in=contents), + empty_label="--------", + label="Content", + ) + object_id = forms.CharField(widget=forms.Select(choices=[("", "---------")]), label="Element") class Meta: model = ClippingRelation - fields = ['content_type', 'object_id', 'clipping'] + fields = ["content_type", "object_id", "clipping"] @admin.register(ClippingRelation) class ClippingRelationAdmin(admin.ModelAdmin): form = ClippingRelationAdminForm - list_display = ('get_clipping_relation', 'clipping', 'content_type') + list_display = ("get_clipping_relation", "clipping", "content_type") def get_clipping_relation(self, obj): return obj.content_object.name - get_clipping_relation.short_description = 'Relation' + + get_clipping_relation.short_description = "Relation" class ClippingAdminForm(forms.ModelForm): - category = forms.CharField(widget=forms.Select(choices=settings.CATEGORY_CHOICES), label='Category') + category = forms.CharField(widget=forms.Select(choices=settings.CATEGORY_CHOICES), label="Category") class Meta: model = Clipping - exclude = ['added_by'] + exclude = ["added_by"] @admin.register(Clipping) class ClippingAdmin(admin.ModelAdmin): form = ClippingAdminForm - list_display = ('date','title', 'author', 'vehicle', 'category', 'url', 'added_by', 'published') + list_display = ("date", "title", "author", "vehicle", "category", "url", "added_by", "published") # Sets the current user as the adder def save_model(self, request, obj, form, change): - if getattr(obj, 'added_by', None) is None: + if getattr(obj, "added_by", None) is None: obj.added_by = request.user obj.save() diff --git a/clipping/apps.py b/clipping/apps.py index 6b35d3be..67270305 100644 --- a/clipping/apps.py +++ b/clipping/apps.py @@ -2,4 +2,4 @@ class ClippingConfig(AppConfig): - name = 'clipping' + name = "clipping" diff --git a/clipping/forms.py b/clipping/forms.py index 8ae0a70f..f87ea691 100644 --- a/clipping/forms.py +++ b/clipping/forms.py @@ -1,16 +1,17 @@ -from django.forms import ModelForm -from .models import Clipping from django import forms from django.conf import settings +from django.forms import ModelForm + +from .models import Clipping class ClippingForm(ModelForm): - category = forms.CharField(widget=forms.Select(choices=settings.CATEGORY_CHOICES), label='Categoria') - date = forms.CharField(widget=forms.TextInput(attrs={'class':'datepicker'}),label='Data') - author = forms.CharField(label='Autor') - title = forms.CharField(label='Título') + category = forms.CharField(widget=forms.Select(choices=settings.CATEGORY_CHOICES), label="Categoria") + date = forms.CharField(widget=forms.TextInput(attrs={"class": "datepicker"}), label="Data") + author = forms.CharField(label="Autor") + title = forms.CharField(label="Título") class Meta: model = Clipping - fields = '__all__' - exclude = ['added_by', 'published'] + fields = "__all__" + exclude = ["added_by", "published"] diff --git a/clipping/management/commands/import_clippings.py b/clipping/management/commands/import_clippings.py index 9c1f49b9..b651f63a 100644 --- a/clipping/management/commands/import_clippings.py +++ b/clipping/management/commands/import_clippings.py @@ -1,11 +1,9 @@ -import os import csv -import rows - -from django.core.management.base import BaseCommand from pathlib import Path from django.contrib.auth import get_user_model +from django.core.management.base import BaseCommand + from clipping.models import Clipping @@ -23,10 +21,18 @@ def handle(self, *args, **kwargs): csv_file = self.clean_args(**kwargs) username = "turicas" user = get_user_model().objects.get(username=username) - with open(csv_file, encoding='utf-8') as csvfile: + with open(csv_file, encoding="utf-8") as csvfile: reader = csv.DictReader(csvfile) for row in reader: - p = Clipping(date=row['data'], vehicle=row['veiculo'], author=row['autor'], title=row['titulo'], - category=row['categoria'], url=row['link'], published=True, added_by=user) + p = Clipping( + date=row["data"], + vehicle=row["veiculo"], + author=row["autor"], + title=row["titulo"], + category=row["categoria"], + url=row["link"], + published=True, + added_by=user, + ) p.save() - self.stdout.write(self.style.SUCCESS('Successfully imported')) + self.stdout.write(self.style.SUCCESS("Successfully imported")) diff --git a/clipping/models.py b/clipping/models.py index 7fe241f1..f248f9b3 100644 --- a/clipping/models.py +++ b/clipping/models.py @@ -1,8 +1,9 @@ import datetime + from django.contrib.auth import get_user_model -from django.db import models from django.contrib.contenttypes.fields import GenericForeignKey from django.contrib.contenttypes.models import ContentType +from django.db import models class Clipping(models.Model): @@ -14,8 +15,7 @@ class Clipping(models.Model): url = models.URLField(null=False, blank=False, unique=True) published = models.BooleanField(default=False, blank=True) - added_by = models.ForeignKey(get_user_model(), null=True, blank=True, - on_delete=models.SET_NULL) + added_by = models.ForeignKey(get_user_model(), null=True, blank=True, on_delete=models.SET_NULL) def __str__(self): return self.title @@ -32,4 +32,4 @@ def __str__(self): return "Content: {} | Clipping: {}".format(self.content_object.name, self.clipping.title) class Meta: - unique_together = ['content_type', 'object_id', 'clipping'] + unique_together = ["content_type", "object_id", "clipping"] diff --git a/clipping/tests.py b/clipping/tests.py index 7ce503c2..a39b155a 100644 --- a/clipping/tests.py +++ b/clipping/tests.py @@ -1,3 +1 @@ -from django.test import TestCase - # Create your tests here. diff --git a/clipping/urls.py b/clipping/urls.py index ebaf58e8..19e5dc82 100644 --- a/clipping/urls.py +++ b/clipping/urls.py @@ -3,6 +3,6 @@ from . import views urlpatterns = [ - path('get/contentype_instances/', views.get_contenttype_instances), - path('get/selected_instance/', views.get_current_selected_instance), + path("get/contentype_instances/", views.get_contenttype_instances), + path("get/selected_instance/", views.get_current_selected_instance), ] diff --git a/clipping/views.py b/clipping/views.py index e8ec5e8e..d7f1ddaa 100644 --- a/clipping/views.py +++ b/clipping/views.py @@ -1,17 +1,18 @@ import json -from django.http import HttpResponse -from django.shortcuts import render # get_object_or_404, redirect + from django.contrib.contenttypes.models import ContentType -from .models import Clipping, ClippingRelation +from django.http import HttpResponse + +from .models import ClippingRelation def get_contenttype_instances(request): - pk = request.GET.get('id') - result = list(ContentType.objects.get(id=pk).model_class().objects.filter().values('id', 'name')) + pk = request.GET.get("id") + result = list(ContentType.objects.get(id=pk).model_class().objects.filter().values("id", "name")) return HttpResponse(json.dumps(result), content_type="application/json") def get_current_selected_instance(request): - pk = request.GET.get('id') + pk = request.GET.get("id") result = ClippingRelation.objects.get(id=pk).object_id return HttpResponse(json.dumps(result), content_type="application/json") diff --git a/core/views.py b/core/views.py index 3dbdba36..5a139684 100644 --- a/core/views.py +++ b/core/views.py @@ -2,6 +2,7 @@ import uuid from django.conf import settings +from django.contrib.contenttypes.models import ContentType from django.core.exceptions import ObjectDoesNotExist from django.core.mail import EmailMessage from django.core.paginator import Paginator @@ -10,6 +11,8 @@ from django.shortcuts import get_object_or_404, redirect, render from django.urls import reverse +from clipping.forms import ClippingForm +from clipping.models import ClippingRelation from core.filters import parse_querystring from core.forms import ContactForm, DatasetSearchForm, get_table_dynamic_form from core.middlewares import disable_non_logged_user_cache @@ -18,9 +21,6 @@ from core.util import cached_http_get_json from data_activities_log.activites import recent_activities from traffic_control.logging import log_blocked_request -from clipping.models import ClippingRelation -from clipping.forms import ClippingForm -from django.contrib.contenttypes.models import ContentType class Echo: @@ -208,15 +208,17 @@ def dataset_detail(request, slug, tablename=""): del querystring[key] clipping = [] - clipping_type_dataset = ContentType.objects.get(app_label='core', model='dataset') - clipping_dataset = list(ClippingRelation.objects.filter(content_type=clipping_type_dataset.id, object_id=dataset.pk)) + clipping_type_dataset = ContentType.objects.get(app_label="core", model="dataset") + clipping_dataset = list( + ClippingRelation.objects.filter(content_type=clipping_type_dataset.id, object_id=dataset.pk) + ) clipping.extend(clipping_dataset) - clipping_type_table = ContentType.objects.get(app_label='core', model='table') + clipping_type_table = ContentType.objects.get(app_label="core", model="table") clipping_table = list(ClippingRelation.objects.filter(content_type=clipping_type_table.id, object_id=table.pk)) clipping.extend(clipping_table) message = None - if request.method == 'POST': + if request.method == "POST": clipping_form = ClippingForm(request.POST) if clipping_form.is_valid(): clipping = clipping_form.save(commit=False) @@ -244,7 +246,7 @@ def dataset_detail(request, slug, tablename=""): "total_count": all_data.count(), "version": version, "form": clipping_form, - "message": message + "message": message, } status = 200