allow tags to contain chars, not only English alphabet (#801)

* allow tags to contain chars, not only English alphabet
pull/802/head
Markos Gogoulos 2023-06-13 15:41:13 +03:00 zatwierdzone przez GitHub
rodzic 5b601698a4
commit c866fdd6ba
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 4AEE18F83AFDEB23
3 zmienionych plików z 13 dodań i 8 usunięć

Wyświetl plik

@ -785,3 +785,11 @@ def clean_query(query):
query = query.replace(char, "") query = query.replace(char, "")
return query.lower() return query.lower()
def get_alphanumeric_only(string):
"""Returns a query that contains only alphanumeric characters
This include characters other than the English alphabet too
"""
string = "".join([char for char in string if char.isalnum()])
return string.lower()

Wyświetl plik

@ -16,7 +16,6 @@ from django.core.files import File
from django.db import connection, models from django.db import connection, models
from django.db.models.signals import m2m_changed, post_delete, post_save, pre_delete from django.db.models.signals import m2m_changed, post_delete, post_save, pre_delete
from django.dispatch import receiver from django.dispatch import receiver
from django.template.defaultfilters import slugify
from django.urls import reverse from django.urls import reverse
from django.utils import timezone from django.utils import timezone
from django.utils.html import strip_tags from django.utils.html import strip_tags
@ -1000,10 +999,8 @@ class Tag(models.Model):
return True return True
def save(self, *args, **kwargs): def save(self, *args, **kwargs):
self.title = slugify(self.title[:99]) self.title = helpers.get_alphanumeric_only(self.title)
strip_text_items = ["title"] self.title = self.title[:99]
for item in strip_text_items:
setattr(self, item, strip_tags(getattr(self, item, None)))
super(Tag, self).save(*args, **kwargs) super(Tag, self).save(*args, **kwargs)
@property @property

Wyświetl plik

@ -9,7 +9,6 @@ from django.core.mail import EmailMessage
from django.db.models import Q from django.db.models import Q
from django.http import HttpResponseRedirect from django.http import HttpResponseRedirect
from django.shortcuts import get_object_or_404, render from django.shortcuts import get_object_or_404, render
from django.template.defaultfilters import slugify
from drf_yasg import openapi as openapi from drf_yasg import openapi as openapi
from drf_yasg.utils import swagger_auto_schema from drf_yasg.utils import swagger_auto_schema
from rest_framework import permissions, status from rest_framework import permissions, status
@ -30,7 +29,7 @@ from cms.permissions import IsAuthorizedToAdd, IsUserOrEditor, user_allowed_to_u
from users.models import User from users.models import User
from .forms import ContactForm, MediaForm, SubtitleForm from .forms import ContactForm, MediaForm, SubtitleForm
from .helpers import clean_query, produce_ffmpeg_commands from .helpers import clean_query, get_alphanumeric_only, produce_ffmpeg_commands
from .methods import ( from .methods import (
check_comment_for_mention, check_comment_for_mention,
get_user_or_session, get_user_or_session,
@ -182,7 +181,8 @@ def edit_media(request):
media.tags.remove(tag) media.tags.remove(tag)
if form.cleaned_data.get("new_tags"): if form.cleaned_data.get("new_tags"):
for tag in form.cleaned_data.get("new_tags").split(","): for tag in form.cleaned_data.get("new_tags").split(","):
tag = slugify(tag) tag = get_alphanumeric_only(tag)
tag = tag[:99]
if tag: if tag:
try: try:
tag = Tag.objects.get(title=tag) tag = Tag.objects.get(title=tag)