Skip to content

Commit

Permalink
allow tags to contain chars, not only English alphabet (#801)
Browse files Browse the repository at this point in the history
* allow tags to contain chars, not only English alphabet
  • Loading branch information
mgogoulos authored Jun 13, 2023
1 parent 5b60169 commit c866fdd
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
8 changes: 8 additions & 0 deletions files/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -785,3 +785,11 @@ def clean_query(query):
query = query.replace(char, "")

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()
7 changes: 2 additions & 5 deletions files/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
from django.db import connection, models
from django.db.models.signals import m2m_changed, post_delete, post_save, pre_delete
from django.dispatch import receiver
from django.template.defaultfilters import slugify
from django.urls import reverse
from django.utils import timezone
from django.utils.html import strip_tags
Expand Down Expand Up @@ -1000,10 +999,8 @@ def update_tag_media(self):
return True

def save(self, *args, **kwargs):
self.title = slugify(self.title[:99])
strip_text_items = ["title"]
for item in strip_text_items:
setattr(self, item, strip_tags(getattr(self, item, None)))
self.title = helpers.get_alphanumeric_only(self.title)
self.title = self.title[:99]
super(Tag, self).save(*args, **kwargs)

@property
Expand Down
6 changes: 3 additions & 3 deletions files/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
from django.db.models import Q
from django.http import HttpResponseRedirect
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.utils import swagger_auto_schema
from rest_framework import permissions, status
Expand All @@ -30,7 +29,7 @@
from users.models import User

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 (
check_comment_for_mention,
get_user_or_session,
Expand Down Expand Up @@ -182,7 +181,8 @@ def edit_media(request):
media.tags.remove(tag)
if form.cleaned_data.get("new_tags"):
for tag in form.cleaned_data.get("new_tags").split(","):
tag = slugify(tag)
tag = get_alphanumeric_only(tag)
tag = tag[:99]
if tag:
try:
tag = Tag.objects.get(title=tag)
Expand Down

0 comments on commit c866fdd

Please sign in to comment.