mirror of
https://github.com/mediacms-io/mediacms.git
synced 2024-11-22 08:13:33 +01:00
allow tags to contain chars, not only English alphabet (#801)
* allow tags to contain chars, not only English alphabet
This commit is contained in:
parent
5b601698a4
commit
c866fdd6ba
@ -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()
|
||||||
|
@ -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
|
||||||
|
@ -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)
|
||||||
|
Loading…
Reference in New Issue
Block a user