Add package files

This commit is contained in:
2022-06-20 11:53:11 +03:00
parent 37b3fed091
commit 1dfa7b36b3
15 changed files with 251 additions and 52 deletions

25
extend/utils.py Normal file
View File

@@ -0,0 +1,25 @@
import re
from django.core.exceptions import ValidationError
from django.utils.crypto import get_random_string
from django.utils.translation import gettext_lazy as _
def validate_url(value):
"""
Валидация ссылок на видео с видеохостинга YouTube
"""
video_url = value
regex = re.compile(
r"(https?://)?(www\.)?(youtube|youtu|youtube-nocookie)\.(com|be)/(watch\?v=|embed/|v/|.+\?v=)?(?P<id>[A-Za-z0-9\-=_]{11})"
)
match = regex.match(video_url)
if not match:
raise ValidationError(
_("%(value)s не является корректной YouTube ссылкой"),
params={"value": value},
)
def generate_secret_key():
chars = "abcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*(-_=+)"
return get_random_string(50, chars)