From 3dd445bf96aa410ce7accf017ea4f76108812c78 Mon Sep 17 00:00:00 2001 From: pacoccino Date: Mon, 4 Sep 2023 14:58:57 +0200 Subject: [PATCH] Add a validator for sub_lang --- tubesync/sync/models.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/tubesync/sync/models.py b/tubesync/sync/models.py index 97d76cb..874524c 100644 --- a/tubesync/sync/models.py +++ b/tubesync/sync/models.py @@ -8,6 +8,7 @@ from pathlib import Path from django.conf import settings from django.db import models from django.core.files.storage import FileSystemStorage +from django.core.validators import RegexValidator from django.utils.text import slugify from django.utils import timezone from django.utils.translation import gettext_lazy as _ @@ -364,7 +365,13 @@ class Source(models.Model): _('subs langs'), max_length=30, default='en', - help_text=_('List of subtitles langs to download, comma-separated. Example: en,fr') + help_text=_('List of subtitles langs to download, comma-separated. Example: en,fr or all,-fr,-live_chat'), + validators=[ + RegexValidator( + regex=r"^(\-?[\_\.a-zA-Z]+,)*(\-?[\_\.a-zA-Z]+){1}$", + message=_('Subtitle langs must be a comma-separated list of langs. example: en,fr or all,-fr,-live_chat') + ) + ] ) def __str__(self):