From 7bda0acd8ba0d668f53c555acba6bbcf45157b14 Mon Sep 17 00:00:00 2001 From: Markos Gogoulos Date: Thu, 3 Jun 2021 18:26:53 +0300 Subject: [PATCH] Feat flake8 strength (#209) * remove warnings from flake --- cms/settings.py | 2 +- files/feeds.py | 3 +-- files/helpers.py | 1 - files/models.py | 10 +++++----- files/views.py | 8 +++----- setup.cfg | 3 ++- users/views.py | 1 - 7 files changed, 12 insertions(+), 16 deletions(-) diff --git a/cms/settings.py b/cms/settings.py index 9964cd3..004f938 100644 --- a/cms/settings.py +++ b/cms/settings.py @@ -433,7 +433,7 @@ GLOBAL_LOGIN_REQUIRED = False try: # keep a local_settings.py file for local overrides - from .local_settings import * + from .local_settings import * # noqa # ALLOWED_HOSTS needs a url/ip ALLOWED_HOSTS.append(FRONTEND_HOST.replace("http://", "").replace("https://", "")) diff --git a/files/feeds.py b/files/feeds.py index 170e8b3..60ca575 100644 --- a/files/feeds.py +++ b/files/feeds.py @@ -1,12 +1,11 @@ from django.conf import settings from django.contrib.postgres.search import SearchQuery from django.contrib.syndication.views import Feed -from django.db.models import Q from django.urls import reverse from django.utils.feedgenerator import Rss201rev2Feed from . import helpers -from .models import Category, Media +from .models import Media from .stop_words import STOP_WORDS diff --git a/files/helpers.py b/files/helpers.py index 3213c0b..cb06599 100644 --- a/files/helpers.py +++ b/files/helpers.py @@ -381,7 +381,6 @@ def media_file_info(input_file): } if has_audio: - audio_duration = 1 if "duration" in audio_info.keys(): audio_duration = float(audio_info["duration"]) elif "tags" in audio_info.keys() and "DURATION" in audio_info["tags"]: diff --git a/files/models.py b/files/models.py index 1fbdbc2..3339d4d 100644 --- a/files/models.py +++ b/files/models.py @@ -24,7 +24,6 @@ from imagekit.processors import ResizeToFit from mptt.models import MPTTModel, TreeForeignKey from . import helpers -from .methods import notify_users from .stop_words import STOP_WORDS logger = logging.getLogger(__name__) @@ -1343,6 +1342,8 @@ def media_save(sender, instance, created, **kwargs): # SOS: do not put anything here, as if more logic is added, # we have to disconnect signal to avoid infinite recursion if created: + from .methods import notify_users + instance.media_init() notify_users(friendly_token=instance.friendly_token, action="media_added") @@ -1507,7 +1508,7 @@ def encoding_file_save(sender, instance, created, **kwargs): # to avoid that this is run twice if ( len(orig_chunks) - == Encoding.objects.filter( + == Encoding.objects.filter( # noqa media=instance.media, profile=instance.profile, chunks_info=instance.chunks_info, @@ -1537,7 +1538,7 @@ def encoding_file_save(sender, instance, created, **kwargs): chunks_paths = [f.media_file.path for f in chunks] all_logs = "\n".join([st.logs for st in chunks]) - encoding.logs = "{0}\n{1}\n{2}".format(chunks_paths, all_logs) + encoding.logs = "{0}\n{1}".format(chunks_paths, all_logs) workers = list(set([st.worker for st in chunks])) encoding.worker = json.dumps({"workers": workers}) start_date = min([st.add_date for st in chunks]) @@ -1548,7 +1549,7 @@ def encoding_file_save(sender, instance, created, **kwargs): who = Encoding.objects.filter(media=encoding.media, profile=encoding.profile).exclude(id=encoding.id) who.delete() - pass # TODO: merge with above if, do not repeat code + # TODO: merge with above if, do not repeat code else: if instance.status in ["fail", "success"]: instance.media.post_encode_actions(encoding=instance, action="add") @@ -1556,7 +1557,6 @@ def encoding_file_save(sender, instance, created, **kwargs): encodings = set([encoding.status for encoding in Encoding.objects.filter(media=instance.media)]) if ("running" in encodings) or ("pending" in encodings): return - workers = list(set([encoding.worker for encoding in Encoding.objects.filter(media=instance.media)])) @receiver(post_delete, sender=Encoding) diff --git a/files/views.py b/files/views.py index d5e76b1..b5a81b3 100644 --- a/files/views.py +++ b/files/views.py @@ -795,7 +795,7 @@ class MediaSearch(APIView): media = media.filter(user__username=author) if upload_date: - gte = lte = None + gte = None if upload_date == 'today': gte = datetime.now().date() if upload_date == 'this_week': @@ -807,8 +807,6 @@ class MediaSearch(APIView): if upload_date == 'this_year': year = datetime.now().date().year gte = datetime(year, 1, 1) - if lte: - media = media.filter(add_date__lte=lte) if gte: media = media.filter(add_date__gte=gte) @@ -1046,8 +1044,8 @@ class EncodingDetail(APIView): chunk=chunk, chunk_file_path=chunk_file_path, ).count() - > 1 - and force is False + > 1 # noqa + and force is False # noqa ): Encoding.objects.filter(id=encoding_id).delete() return Response({"status": "fail"}, status=status.HTTP_400_BAD_REQUEST) diff --git a/setup.cfg b/setup.cfg index 5422bc9..de959b6 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,4 +1,5 @@ [flake8] exclude = .git,*migrations* max-line-length = 119 -ignore=F401,F403,E501,W503 +#ignore=F401,F403,E501,W503 +ignore=E501 diff --git a/users/views.py b/users/views.py index c22e000..7f2478a 100644 --- a/users/views.py +++ b/users/views.py @@ -149,7 +149,6 @@ def contact_user(request, username): ) user = User.objects.filter(username=username).first() if user and (user.allow_contact or is_mediacms_editor(request.user)): - subject = request.data.get("subject") from_email = request.user.email subject = f"[{settings.PORTAL_NAME}] - Message from {from_email}" body = request.data.get("body")