Skip to content

Commit

Permalink
fix: pre-commit
Browse files Browse the repository at this point in the history
  • Loading branch information
mgogoulos committed Nov 20, 2024
1 parent 99be0f0 commit b8ee2e9
Show file tree
Hide file tree
Showing 10 changed files with 72 additions and 37 deletions.
7 changes: 5 additions & 2 deletions cms/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@

# Comma separated list of domains: ["organization.com", "private.organization.com", "org2.com"]
# Empty list disables.
ALLOWED_DOMAINS_FOR_USER_REGISTRATION = []
ALLOWED_DOMAINS_FOR_USER_REGISTRATION = []

# django rest settings
REST_FRAMEWORK = {
Expand Down Expand Up @@ -538,4 +538,7 @@
SPRITE_NUM_SECS = 10
# number of seconds for sprite image.
# If you plan to change this, you must also follow the instructions on admin_docs.md
# to change the equivalent value in ./frontend/src/static/js/components/media-viewer/VideoViewer/index.js and then re-build frontend
# to change the equivalent value in ./frontend/src/static/js/components/media-viewer/VideoViewer/index.js and then re-build frontend

# how many images will be shown on the slideshow
SLIDESHOW_ITEMS = 30
11 changes: 10 additions & 1 deletion files/admin.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
from django.contrib import admin

from .models import Category, Comment, EncodeProfile, Encoding, Language, Media, Subtitle, Tag
from .models import (
Category,
Comment,
EncodeProfile,
Encoding,
Language,
Media,
Subtitle,
Tag,
)


class CommentAdmin(admin.ModelAdmin):
Expand Down
1 change: 0 additions & 1 deletion files/frontend_translations/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ def check_language_code(language_code):
replacement_strings[language_code] = tr_module.replacement_strings



def get_translation(language_code):
# get list of translations per language
if not check_language_code(language_code):
Expand Down
5 changes: 4 additions & 1 deletion files/management/commands/process_translations.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ def process_translation_files(self, translations_dir):
files = os.listdir(translations_dir)
files = [f for f in files if f.endswith('.py') and f not in ('__init__.py', 'en.py')]
# Import the original English translations
from files.frontend_translations.en import replacement_strings, translation_strings
from files.frontend_translations.en import (
replacement_strings,
translation_strings,
)

for file in files:
file_path = os.path.join(translations_dir, file)
Expand Down
19 changes: 14 additions & 5 deletions files/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -780,13 +780,13 @@ def poster_url(self):
return helpers.url_from_path(self.poster.path)
return None


@property
def slideshow_items(self):
slideshow_items = getattr(settings, "SLIDESHOW_ITEMS", 30)
if self.media_type != "image":
items = []
else:
qs = Media.objects.filter(listable=True, user=self.user, media_type="image").exclude(id=self.id).order_by('id')[:20]
qs = Media.objects.filter(listable=True, user=self.user, media_type="image").exclude(id=self.id).order_by('id')[:slideshow_items]

items = [
{
Expand All @@ -795,12 +795,21 @@ def slideshow_items(self):
"thumbnail_url": item.thumbnail_url,
"title": item.title,
"original_media_url": item.original_media_url,
} for item in qs
}
for item in qs
]

items.insert(
0,
{
"poster_url": self.poster_url,
"url": self.get_absolute_url(),
"thumbnail_url": self.thumbnail_url,
"title": self.title,
"original_media_url": self.original_media_url,
},
)
return items


@property
def subtitles_info(self):
"""Property used on serializers
Expand Down
2 changes: 1 addition & 1 deletion files/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ class Meta:
"ratings_info",
"add_subtitle_url",
"allow_download",
"slideshow_items"
"slideshow_items",
)


Expand Down
34 changes: 14 additions & 20 deletions files/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,17 @@

from .backends import FFmpegBackend
from .exceptions import VideoEncodingError
from .helpers import calculate_seconds, create_temp_file, get_file_name, get_file_type, media_file_info, produce_ffmpeg_commands, produce_friendly_token, rm_file, run_command
from .helpers import (
calculate_seconds,
create_temp_file,
get_file_name,
get_file_type,
media_file_info,
produce_ffmpeg_commands,
produce_friendly_token,
rm_file,
run_command,
)
from .methods import list_tasks, notify_users, pre_save_action
from .models import Category, EncodeProfile, Encoding, Media, Rating, Tag

Expand Down Expand Up @@ -376,23 +386,12 @@ def produce_sprite_from_video(friendly_token):
output_name = tmpdirname + "/sprites.jpg"

fps = getattr(settings, 'SPRITE_NUM_SECS', 10)
ffmpeg_cmd = [
settings.FFMPEG_COMMAND,
"-i", media.media_file.path,
"-f", "image2",
"-vf", f"fps=1/{fps}, scale=160:90",
tmpdir_image_files
]
ffmpeg_cmd = [settings.FFMPEG_COMMAND, "-i", media.media_file.path, "-f", "image2", "-vf", f"fps=1/{fps}, scale=160:90", tmpdir_image_files]
run_command(ffmpeg_cmd)
image_files = [f for f in os.listdir(tmpdirname) if f.startswith("img") and f.endswith(".jpg")]
image_files = sorted(image_files, key=lambda x: int(re.search(r'\d+', x).group()))
image_files = [os.path.join(tmpdirname, f) for f in image_files]
cmd_convert = [
"convert",
*image_files, # image files, unpacked into the list
"-append",
output_name
]
cmd_convert = ["convert", *image_files, "-append", output_name] # image files, unpacked into the list

run_command(cmd_convert)

Expand Down Expand Up @@ -435,12 +434,7 @@ def create_hls(friendly_token):
existing_output_dir = output_dir
output_dir = os.path.join(settings.HLS_DIR, p + produce_friendly_token())
files = " ".join([f.media_file.path for f in encodings if f.media_file])
cmd = [
settings.MP4HLS_COMMAND,
'--segment-duration=4',
f'--output-dir={output_dir}',
files
]
cmd = [settings.MP4HLS_COMMAND, '--segment-duration=4', f'--output-dir={output_dir}', files]
run_command(cmd)

if existing_output_dir:
Expand Down
1 change: 0 additions & 1 deletion files/templatetags/custom_filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,4 @@

@register.filter
def custom_translate(string, lang_code):

return translate_string(lang_code, string)
25 changes: 22 additions & 3 deletions files/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,24 @@
from drf_yasg.utils import swagger_auto_schema
from rest_framework import permissions, status
from rest_framework.exceptions import PermissionDenied
from rest_framework.parsers import FileUploadParser, FormParser, JSONParser, MultiPartParser
from rest_framework.parsers import (
FileUploadParser,
FormParser,
JSONParser,
MultiPartParser,
)
from rest_framework.response import Response
from rest_framework.settings import api_settings
from rest_framework.views import APIView

from actions.models import USER_MEDIA_ACTIONS, MediaAction
from cms.custom_pagination import FastPaginationWithoutCount
from cms.permissions import IsAuthorizedToAdd, IsAuthorizedToAddComment, IsUserOrEditor, user_allowed_to_upload
from cms.permissions import (
IsAuthorizedToAdd,
IsAuthorizedToAddComment,
IsUserOrEditor,
user_allowed_to_upload,
)
from users.models import User

from .forms import ContactForm, MediaForm, SubtitleForm
Expand All @@ -36,7 +46,16 @@
show_related_media,
update_user_ratings,
)
from .models import Category, Comment, EncodeProfile, Encoding, Media, Playlist, PlaylistMedia, Tag
from .models import (
Category,
Comment,
EncodeProfile,
Encoding,
Media,
Playlist,
PlaylistMedia,
Tag,
)
from .serializers import (
CategorySerializer,
CommentSerializer,
Expand Down
4 changes: 2 additions & 2 deletions users/adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ def get_email_confirmation_url_stub(self, request, emailconfirmation):
return settings.SSL_FRONTEND_HOST + url

def clean_email(self, email):
if hasattr(settings,"ALLOWED_DOMAINS_FOR_USER_REGISTRATION") and settings.ALLOWED_DOMAINS_FOR_USER_REGISTRATION:
if hasattr(settings, "ALLOWED_DOMAINS_FOR_USER_REGISTRATION") and settings.ALLOWED_DOMAINS_FOR_USER_REGISTRATION:
if email.split("@")[1] not in settings.ALLOWED_DOMAINS_FOR_USER_REGISTRATION:
raise ValidationError("Domain is not in the permitted list")

if email.split("@")[1] in settings.RESTRICTED_DOMAINS_FOR_USER_REGISTRATION:
raise ValidationError("Domain is restricted from registering")
return email
Expand Down

0 comments on commit b8ee2e9

Please sign in to comment.