From 2e15c0f050ff69d1d0e7a0b681bf61d6270cfba8 Mon Sep 17 00:00:00 2001 From: Francesco Filicetti Date: Thu, 9 Sep 2021 14:01:48 +0200 Subject: [PATCH] fix: autopep / autoflake --- src/cms/api/pagination.py | 2 +- src/cms/api/permissions.py | 1 + src/cms/api/tests/test_page_heading.py | 2 +- src/cms/api/tests/test_user.py | 3 --- src/cms/api/urls.py | 12 +++++++----- src/cms/api/views/generics.py | 4 +--- src/cms/api/views/locks.py | 4 ++-- src/cms/api/views/media.py | 2 -- src/cms/api/views/menu.py | 4 ++-- src/cms/api/views/menu_item_localization.py | 8 ++++---- src/cms/carousels/models.py | 2 +- src/cms/contacts/admin.py | 2 +- src/cms/contacts/forms.py | 2 +- src/cms/contacts/models.py | 14 ++++++-------- src/cms/contacts/serializers.py | 2 +- src/cms/contacts/tests.py | 3 +-- src/cms/contexts/forms.py | 6 +++--- src/cms/contexts/serializers.py | 8 ++++---- src/cms/contexts/tests.py | 2 +- src/cms/contexts/utils.py | 4 ++-- src/cms/menus/forms.py | 2 +- src/cms/menus/models.py | 4 ++-- src/cms/menus/templatetags/unicms_menus.py | 11 ++++------- src/cms/pages/admin_actions.py | 1 + .../templatetags/unicms_publications.py | 6 +++--- src/cms/templates/placeholders.py | 2 -- 26 files changed, 51 insertions(+), 62 deletions(-) diff --git a/src/cms/api/pagination.py b/src/cms/api/pagination.py index 1820f14d..693d0ea7 100644 --- a/src/cms/api/pagination.py +++ b/src/cms/api/pagination.py @@ -17,7 +17,7 @@ def url_refactor(self, url): def get_paginated_response(self, data): return Response({ 'count': self.page.paginator.count, - 'next': self.url_refactor(self.get_next_link()), + 'next': self.url_refactor(self.get_next_link()), 'previous': self.url_refactor(self.get_previous_link()), 'page': int(self.request.query_params.get('page', 1)), 'per_page': self.page_size, diff --git a/src/cms/api/permissions.py b/src/cms/api/permissions.py index c7112e47..4ae852a9 100644 --- a/src/cms/api/permissions.py +++ b/src/cms/api/permissions.py @@ -4,6 +4,7 @@ class UNICMSSafePermissions(BasePermission): """ """ + def has_permission(self, request, view): method = request.method diff --git a/src/cms/api/tests/test_page_heading.py b/src/cms/api/tests/test_page_heading.py index a674dbea..04d96d6f 100644 --- a/src/cms/api/tests/test_page_heading.py +++ b/src/cms/api/tests/test_page_heading.py @@ -7,7 +7,7 @@ from cms.contexts.tests import ContextUnitTest -from cms.pages.models import PageHeading, PageHeadingLocalization +from cms.pages.models import PageHeading from cms.pages.tests import PageUnitTest diff --git a/src/cms/api/tests/test_user.py b/src/cms/api/tests/test_user.py index 486a6949..3f769d5f 100644 --- a/src/cms/api/tests/test_user.py +++ b/src/cms/api/tests/test_user.py @@ -1,8 +1,5 @@ import logging -from django.contrib.auth.models import Permission -from django.contrib.contenttypes.models import ContentType -from django.core.exceptions import ObjectDoesNotExist from django.test import Client, TestCase from django.urls import reverse diff --git a/src/cms/api/urls.py b/src/cms/api/urls.py index e1e83c78..b1fc5ec7 100644 --- a/src/cms/api/urls.py +++ b/src/cms/api/urls.py @@ -24,11 +24,11 @@ urlpatterns = [] urlpatterns += re_path(r'api/$', - TemplateView.as_view( + TemplateView.as_view( template_name='redoc.html', extra_context={'schema_url':'openapi-schema'} - ), - name='unicms-api-redoc'), + ), + name='unicms-api-redoc'), # Public API Resources # urlpatterns += path('api/contexts', publication.ApiContext.as_view(), name='api-contexts'), @@ -334,8 +334,10 @@ # publication media collections pug_prefix = f'{pu_prefix}//media-collections' -urlpatterns += path(f'{pug_prefix}/', publication_media_collection.PublicationMediaCollectionList.as_view(), name='editorial-board-publication-media-collections'), -urlpatterns += path(f'{pug_prefix}//', publication_media_collection.PublicationMediaCollectionView.as_view(), name='editorial-board-publication-media-collection'), +urlpatterns += path(f'{pug_prefix}/', publication_media_collection.PublicationMediaCollectionList.as_view(), + name='editorial-board-publication-media-collections'), +urlpatterns += path(f'{pug_prefix}//', publication_media_collection.PublicationMediaCollectionView.as_view(), + name='editorial-board-publication-media-collection'), urlpatterns += path(f'{pug_prefix}//logs/', publication_media_collection.PublicationMediaCollectionLogsView.as_view(), name='editorial-board-publication-media-collection-logs'), urlpatterns += path(f'{pug_prefix}/form/', publication_media_collection.PublicationMediaCollectionFormView.as_view(), diff --git a/src/cms/api/views/generics.py b/src/cms/api/views/generics.py index b67c4071..1e3045f9 100644 --- a/src/cms/api/views/generics.py +++ b/src/cms/api/views/generics.py @@ -1,4 +1,3 @@ -import json import logging from django.contrib.admin.models import ADDITION @@ -14,7 +13,6 @@ from rest_framework import filters, generics from rest_framework.exceptions import PermissionDenied from rest_framework.permissions import IsAdminUser -from rest_framework.response import Response from .. concurrency import (get_lock_from_cache, # set_lock_to_cache, @@ -59,7 +57,7 @@ def check_locks(item, user): if user_lock and not user_lock == user_id: logger.debug(f'{user} tried to access to {owner_user} actually used by {item}') raise PermissionDenied(LOCK_MESSAGE.format(user=owner_user, - ttl=lock[1]), + ttl=lock[1]), 403) # set_lock_to_cache(user_id, content_type_id, object_id) diff --git a/src/cms/api/views/locks.py b/src/cms/api/views/locks.py index 542041f3..c1de3422 100644 --- a/src/cms/api/views/locks.py +++ b/src/cms/api/views/locks.py @@ -15,7 +15,7 @@ from rest_framework.views import APIView from . generics import check_locks, UniCMSListCreateAPIView -from .. concurrency import * +from .. concurrency import LOCK_MESSAGE, get_lock_from_cache, set_lock_to_cache from .. exceptions import LoggedPermissionDenied @@ -124,7 +124,7 @@ def delete(self, request, *args, **kwargs): if request.user.is_superuser or user_lock: return super().delete(request, *args, **kwargs) raise LoggedPermissionDenied(classname=self.__class__.__name__, - resource=request.method) + resource=request.method) class RedisLockView(APIView): diff --git a/src/cms/api/views/media.py b/src/cms/api/views/media.py index 83b19bac..61f585f9 100644 --- a/src/cms/api/views/media.py +++ b/src/cms/api/views/media.py @@ -160,5 +160,3 @@ def get(self, request): """ """ return Response(tuple(sorted(FILETYPE_ALLOWED))) - - diff --git a/src/cms/api/views/menu.py b/src/cms/api/views/menu.py index a0f84533..45836c35 100644 --- a/src/cms/api/views/menu.py +++ b/src/cms/api/views/menu.py @@ -5,7 +5,7 @@ from django.utils import timezone from django.utils.decorators import method_decorator -from rest_framework.exceptions import NotFound, PermissionDenied +from rest_framework.exceptions import NotFound from rest_framework.permissions import IsAdminUser from rest_framework.response import Response from rest_framework.schemas.openapi import AutoSchema @@ -17,7 +17,7 @@ from cms.menus.models import NavigationBar from cms.menus.serializers import MenuSelectOptionsSerializer, MenuSerializer -from . generics import * +from . generics import UniCMSCachedRetrieveUpdateDestroyAPIView, UniCMSListCreateAPIView, UniCMSListSelectOptionsAPIView, generics from . logs import ObjectLogEntriesList from .. exceptions import LoggedPermissionDenied, LoggedValidationException from .. permissions import MenuGetCreatePermissions, UNICMSSafePermissions diff --git a/src/cms/api/views/menu_item_localization.py b/src/cms/api/views/menu_item_localization.py index a32d252f..0469c97f 100644 --- a/src/cms/api/views/menu_item_localization.py +++ b/src/cms/api/views/menu_item_localization.py @@ -64,10 +64,10 @@ def get_queryset(self): menu_item_id = self.kwargs['menu_item_id'] item_id = self.kwargs['pk'] items = NavigationBarItemLocalization.objects\ - .select_related('item')\ - .filter(pk=item_id, - item__menu__pk=menu_id, - item__pk=menu_item_id) + .select_related('item')\ + .filter(pk=item_id, + item__menu__pk=menu_id, + item__pk=menu_item_id) return items def patch(self, request, *args, **kwargs): diff --git a/src/cms/carousels/models.py b/src/cms/carousels/models.py index a2793422..f6b61944 100644 --- a/src/cms/carousels/models.py +++ b/src/cms/carousels/models.py @@ -25,7 +25,7 @@ def get_items(self, lang=settings.LANGUAGE): items = [] for i in self.carouselitem_set.filter(carousel=self, is_active=True)\ - .order_by('order'): + .order_by('order'): items.append(i.localized(lang=lang)) return items diff --git a/src/cms/contacts/admin.py b/src/cms/contacts/admin.py index 57141299..a728c672 100644 --- a/src/cms/contacts/admin.py +++ b/src/cms/contacts/admin.py @@ -3,7 +3,7 @@ from django.contrib import admin from cms.contexts.admin import AbstractCreatedModifiedBy -from . models import * +from . models import Contact, ContactInfo, ContactInfoLocalization, ContactLocalization class ContactInfoLocalizationInline(nested_admin.NestedStackedInline): diff --git a/src/cms/contacts/forms.py b/src/cms/contacts/forms.py index fcaccf1e..d77eb6c9 100644 --- a/src/cms/contacts/forms.py +++ b/src/cms/contacts/forms.py @@ -3,7 +3,7 @@ from cms.api.settings import FORM_SOURCE_LABEL -from . models import * +from . models import Contact, ContactInfo, ContactInfoLocalization, ContactLocalization class ContactForm(ModelForm): diff --git a/src/cms/contacts/models.py b/src/cms/contacts/models.py index a90e8204..1a4de9a2 100644 --- a/src/cms/contacts/models.py +++ b/src/cms/contacts/models.py @@ -5,8 +5,7 @@ from cms.api.utils import check_user_permission_on_object from cms.contexts.models_abstract import AbstractLockable from cms.medias.models import Media -from cms.templates.models import (CMS_LINKS_LABELS, - ActivableModel, +from cms.templates.models import (ActivableModel, CreatedModifiedBy, SortableModel, TimeStampedModel) @@ -31,7 +30,6 @@ class Contact(ActivableModel, TimeStampedModel, CreatedModifiedBy, image = models.ForeignKey(Media, on_delete=models.PROTECT, null=True, blank=True) - class Meta: ordering = ['name'] verbose_name_plural = _("Contacts") @@ -50,7 +48,7 @@ def get_infos(self, lang=settings.LANGUAGE): infos = [] for i in self.contactinfo_set.filter(contact=self, is_active=True)\ - .order_by('order'): + .order_by('order'): infos.append(i.localized(lang=lang)) return infos @@ -116,16 +114,16 @@ def __str__(self): class ContactInfoLocalization(ActivableModel, - TimeStampedModel, SortableModel, - CreatedModifiedBy): + TimeStampedModel, SortableModel, + CreatedModifiedBy): contact_info = models.ForeignKey(ContactInfo, on_delete=models.CASCADE) language = models.CharField(choices=settings.LANGUAGES, max_length=12, default='en') label = models.CharField(max_length=160, - blank=True, - default='') + blank=True, + default='') value = models.CharField(max_length=160, blank=True, default='') class Meta: diff --git a/src/cms/contacts/serializers.py b/src/cms/contacts/serializers.py index 97bfd7bd..f781a2f2 100644 --- a/src/cms/contacts/serializers.py +++ b/src/cms/contacts/serializers.py @@ -43,7 +43,7 @@ class Meta: class ContactInfoSerializer(UniCMSCreateUpdateSerializer, - UniCMSContentTypeClass): + UniCMSContentTypeClass): contact = ContactForeignKey() class Meta: diff --git a/src/cms/contacts/tests.py b/src/cms/contacts/tests.py index dd25a847..ca70d019 100644 --- a/src/cms/contacts/tests.py +++ b/src/cms/contacts/tests.py @@ -2,9 +2,8 @@ from django.test import TestCase -from cms.medias.tests import MediaUnitTest -from . models import * +from . models import Contact, ContactInfo, ContactInfoLocalization, ContactLocalization logger = logging.getLogger(__name__) diff --git a/src/cms/contexts/forms.py b/src/cms/contexts/forms.py index 214cfe83..8dbc696c 100644 --- a/src/cms/contexts/forms.py +++ b/src/cms/contexts/forms.py @@ -72,8 +72,8 @@ class WebPathCloneForm(forms.Form): queryset=None, required=True, help_text=_("Parent element in which insert the new webpaths")) exclude_pages = forms.BooleanField(label=_('Exclude pages'), - required=False, - help_text=_("Exclude webpaths' pages")) + required=False, + help_text=_("Exclude webpaths' pages")) exclude_news = forms.BooleanField(label=_('Exclude news'), required=False, help_text=_("Exclude webpaths' news")) @@ -82,7 +82,7 @@ class WebPathCloneForm(forms.Form): help_text=_("Take only webpath children")) def __init__(self, *args, **kwargs): - site_id = kwargs.pop('site_id', None) + kwargs.pop('site_id', None) super().__init__(*args, **kwargs) self.fields['parent'].queryset = WebPath.objects.filter(site__is_active=True) setattr(self.fields['parent'], diff --git a/src/cms/contexts/serializers.py b/src/cms/contexts/serializers.py index a6094d40..ad02e756 100644 --- a/src/cms/contexts/serializers.py +++ b/src/cms/contexts/serializers.py @@ -93,15 +93,15 @@ def validate_path(self, value): # def create(self, validated_data): # try: - # return WebPath.objects.create(**validated_data) + # return WebPath.objects.create(**validated_data) # except Exception as e: - # raise e + # raise e # def update(self, instance, validated_data): # try: - # return super().update(instance, validated_data) + # return super().update(instance, validated_data) # except Exception as e: - # raise e + # raise e class WebPathSelectOptionsSerializer(serializers.ModelSerializer): diff --git a/src/cms/contexts/tests.py b/src/cms/contexts/tests.py index 59ad2c8c..2e42054d 100644 --- a/src/cms/contexts/tests.py +++ b/src/cms/contexts/tests.py @@ -106,7 +106,7 @@ def test_same_of_existent_webpath(self): 'path': webpath.path, 'is_active': True} try: - webpath2 = WebPath.objects.create(**kwargs) + WebPath.objects.create(**kwargs) except Exception as e: assert e diff --git a/src/cms/contexts/utils.py b/src/cms/contexts/utils.py index c4a70d5e..e95a6b44 100644 --- a/src/cms/contexts/utils.py +++ b/src/cms/contexts/utils.py @@ -15,7 +15,7 @@ from copy import deepcopy -from django_auto_serializer.auto_serializer import * +from django_auto_serializer.auto_serializer import ImportableSerializedInstance, SerializableInstance logger = logging.getLogger(__name__) @@ -28,7 +28,7 @@ def get_CMS_HOOKS(): def detect_user_language(request): - req_lang = translation.get_language_from_request(request) # is browser language + req_lang = translation.get_language_from_request(request) # is browser language current = request.session.get(translation.LANGUAGE_SESSION_KEY, req_lang) lang = request.GET.get('lang', current) translation.activate(lang) diff --git a/src/cms/menus/forms.py b/src/cms/menus/forms.py index 81fe0e19..8d7b6697 100644 --- a/src/cms/menus/forms.py +++ b/src/cms/menus/forms.py @@ -47,7 +47,7 @@ def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) if menu_id and menu_item_id: self.fields['item'].queryset = NavigationBarItem.objects.filter(pk=menu_item_id, - menu__pk=menu_id) + menu__pk=menu_id) class Meta: model = NavigationBarItemLocalization diff --git a/src/cms/menus/models.py b/src/cms/menus/models.py index 164b855d..86d3f6ce 100644 --- a/src/cms/menus/models.py +++ b/src/cms/menus/models.py @@ -117,8 +117,8 @@ def link(self, request=None): elif self.webpath: # does it have sense? # if self.publication: - # ctx_webpath = self.publication.get_publication_context(webpath=self.webpath) - # return ctx_webpath.url if ctx_webpath else '' + # ctx_webpath = self.publication.get_publication_context(webpath=self.webpath) + # return ctx_webpath.url if ctx_webpath else '' # else: # return self.webpath.get_full_path() return self.webpath.get_site_path(request) diff --git a/src/cms/menus/templatetags/unicms_menus.py b/src/cms/menus/templatetags/unicms_menus.py index 18578413..87d44344 100644 --- a/src/cms/menus/templatetags/unicms_menus.py +++ b/src/cms/menus/templatetags/unicms_menus.py @@ -1,10 +1,9 @@ import logging from django import template -from django.conf import settings from django.utils.safestring import SafeString -from cms.contexts.utils import handle_faulty_templates, append_slash +from cms.contexts.utils import handle_faulty_templates from cms.menus.models import NavigationBar @@ -59,7 +58,7 @@ def load_menu(context, template, section=None, menu_id=None): @register.simple_tag(takes_context=True) def load_item_childs(context, item, exclude=None): _func_name = 'load_item_childs' - _log_msg = f'Template Tag {_func_name}' + f'Template Tag {_func_name}' if item: request = context['request'] @@ -72,7 +71,7 @@ def load_item_childs(context, item, exclude=None): @register.simple_tag(takes_context=True) def load_item_inherited_content(context, item): _func_name = 'load_item_inherited_content' - _log_msg = f'Template Tag {_func_name}' + f'Template Tag {_func_name}' if item and item.inherited_content and item.inherited_content.is_active: request = context['request'] @@ -84,12 +83,10 @@ def load_item_inherited_content(context, item): @register.simple_tag(takes_context=True) def load_item_publication(context, item): _func_name = 'load_item_publication' - _log_msg = f'Template Tag {_func_name}' + f'Template Tag {_func_name}' if item and item.publication and item.publication.is_active: request = context['request'] language = getattr(request, 'LANGUAGE_CODE', '') item.publication.translate_as(lang=language) return item.publication - - diff --git a/src/cms/pages/admin_actions.py b/src/cms/pages/admin_actions.py index c91c0054..1c1ec055 100644 --- a/src/cms/pages/admin_actions.py +++ b/src/cms/pages/admin_actions.py @@ -30,4 +30,5 @@ def update_template(self, request, queryset): 'pages':queryset, 'form': form}) + update_template.short_description = "Update template" diff --git a/src/cms/publications/templatetags/unicms_publications.py b/src/cms/publications/templatetags/unicms_publications.py index a5f8d43e..45275f0a 100644 --- a/src/cms/publications/templatetags/unicms_publications.py +++ b/src/cms/publications/templatetags/unicms_publications.py @@ -81,9 +81,9 @@ def load_publications_preview(context, template, exclude_categories=exclude_categories, tags_csv=tags_csv) pub_in_context = PublicationContext.objects.\ - filter(**query_params).\ - distinct().\ - order_by('order','-date_start') + filter(**query_params).\ + distinct().\ + order_by('order','-date_start') if in_evidence: now = timezone.localtime() diff --git a/src/cms/templates/placeholders.py b/src/cms/templates/placeholders.py index 65399b08..565e119a 100644 --- a/src/cms/templates/placeholders.py +++ b/src/cms/templates/placeholders.py @@ -1,6 +1,4 @@ import logging -import random -import string from django.utils.safestring import SafeString