Add package files
This commit is contained in:
25
extend/utils.py
Normal file
25
extend/utils.py
Normal 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)
|
||||
Reference in New Issue
Block a user