Skip to content

Commit

Permalink
fix: autopep / autoflake
Browse files Browse the repository at this point in the history
  • Loading branch information
francesco-filicetti committed Sep 9, 2021
1 parent 61b4676 commit 2e15c0f
Show file tree
Hide file tree
Showing 26 changed files with 51 additions and 62 deletions.
2 changes: 1 addition & 1 deletion src/cms/api/pagination.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions src/cms/api/permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
class UNICMSSafePermissions(BasePermission):
"""
"""

def has_permission(self, request, view):

method = request.method
Expand Down
2 changes: 1 addition & 1 deletion src/cms/api/tests/test_page_heading.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
3 changes: 0 additions & 3 deletions src/cms/api/tests/test_user.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down
12 changes: 7 additions & 5 deletions src/cms/api/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand Down Expand Up @@ -334,8 +334,10 @@

# publication media collections
pug_prefix = f'{pu_prefix}/<int:publication_id>/media-collections'
urlpatterns += path(f'{pug_prefix}/', publication_media_collection.PublicationMediaCollectionList.as_view(), name='editorial-board-publication-media-collections'),
urlpatterns += path(f'{pug_prefix}/<int:pk>/', 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}/<int:pk>/', publication_media_collection.PublicationMediaCollectionView.as_view(),
name='editorial-board-publication-media-collection'),
urlpatterns += path(f'{pug_prefix}/<int:pk>/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(),
Expand Down
4 changes: 1 addition & 3 deletions src/cms/api/views/generics.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import json
import logging

from django.contrib.admin.models import ADDITION
Expand All @@ -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,
Expand Down Expand Up @@ -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)

Expand Down
4 changes: 2 additions & 2 deletions src/cms/api/views/locks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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):
Expand Down
2 changes: 0 additions & 2 deletions src/cms/api/views/media.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,5 +160,3 @@ def get(self, request):
"""
"""
return Response(tuple(sorted(FILETYPE_ALLOWED)))


4 changes: 2 additions & 2 deletions src/cms/api/views/menu.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
8 changes: 4 additions & 4 deletions src/cms/api/views/menu_item_localization.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion src/cms/carousels/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion src/cms/contacts/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion src/cms/contacts/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
14 changes: 6 additions & 8 deletions src/cms/contacts/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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")
Expand All @@ -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

Expand Down Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion src/cms/contacts/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class Meta:


class ContactInfoSerializer(UniCMSCreateUpdateSerializer,
UniCMSContentTypeClass):
UniCMSContentTypeClass):
contact = ContactForeignKey()

class Meta:
Expand Down
3 changes: 1 addition & 2 deletions src/cms/contacts/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)
Expand Down
6 changes: 3 additions & 3 deletions src/cms/contexts/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand All @@ -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'],
Expand Down
8 changes: 4 additions & 4 deletions src/cms/contexts/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion src/cms/contexts/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions src/cms/contexts/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/cms/menus/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/cms/menus/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
11 changes: 4 additions & 7 deletions src/cms/menus/templatetags/unicms_menus.py
Original file line number Diff line number Diff line change
@@ -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


Expand Down Expand Up @@ -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']
Expand All @@ -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']
Expand All @@ -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


1 change: 1 addition & 0 deletions src/cms/pages/admin_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,5 @@ def update_template(self, request, queryset):
'pages':queryset,
'form': form})


update_template.short_description = "Update template"
6 changes: 3 additions & 3 deletions src/cms/publications/templatetags/unicms_publications.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 0 additions & 2 deletions src/cms/templates/placeholders.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import logging
import random
import string

from django.utils.safestring import SafeString

Expand Down

0 comments on commit 2e15c0f

Please sign in to comment.