mirror of
https://github.com/mediacms-io/mediacms.git
synced 2024-12-03 13:43:17 +01:00
fix: pre-commit
This commit is contained in:
parent
99be0f07dd
commit
b8ee2e9fb8
@ -132,7 +132,7 @@ RESTRICTED_DOMAINS_FOR_USER_REGISTRATION = ["xxx.com", "emaildomainwhatever.com"
|
||||
|
||||
# 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 = {
|
||||
@ -538,4 +538,7 @@ LANGUAGE_CODE = 'en' # default language
|
||||
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
|
||||
|
@ -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):
|
||||
|
@ -32,7 +32,6 @@ for translation_file in files:
|
||||
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):
|
||||
|
@ -18,7 +18,10 @@ class Command(BaseCommand):
|
||||
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)
|
||||
|
@ -780,13 +780,13 @@ class Media(models.Model):
|
||||
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 = [
|
||||
{
|
||||
@ -795,12 +795,21 @@ class Media(models.Model):
|
||||
"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
|
||||
|
@ -145,7 +145,7 @@ class SingleMediaSerializer(serializers.ModelSerializer):
|
||||
"ratings_info",
|
||||
"add_subtitle_url",
|
||||
"allow_download",
|
||||
"slideshow_items"
|
||||
"slideshow_items",
|
||||
)
|
||||
|
||||
|
||||
|
@ -23,7 +23,17 @@ from users.models import User
|
||||
|
||||
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
|
||||
|
||||
@ -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)
|
||||
|
||||
@ -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:
|
||||
|
@ -7,5 +7,4 @@ register = template.Library()
|
||||
|
||||
@register.filter
|
||||
def custom_translate(string, lang_code):
|
||||
|
||||
return translate_string(lang_code, string)
|
||||
|
@ -12,14 +12,24 @@ from drf_yasg import openapi as openapi
|
||||
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
|
||||
@ -36,7 +46,16 @@ from .methods import (
|
||||
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,
|
||||
|
@ -10,10 +10,10 @@ class MyAccountAdapter(DefaultAccountAdapter):
|
||||
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
|
||||
|
Loading…
Reference in New Issue
Block a user