From 95c8dc1d6728d2cdfe192439f00e6b8e1558426c Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Sat, 7 Mar 2020 13:29:57 -0800 Subject: [PATCH] Urlencode tag names as identifiers Fixes #37 --- fedireads/models/status.py | 8 ++++---- fedireads/templates/snippets/tag.html | 2 +- fedireads/urls.py | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/fedireads/models/status.py b/fedireads/models/status.py index 486ac238..01acdae3 100644 --- a/fedireads/models/status.py +++ b/fedireads/models/status.py @@ -2,9 +2,8 @@ from datetime import datetime from django.core.validators import MaxValueValidator, MinValueValidator from django.db import models -from django.dispatch import receiver from model_utils.managers import InheritanceManager -import re +import urllib.parse from fedireads.utils.models import FedireadsModel @@ -20,7 +19,7 @@ class Status(FedireadsModel): local = models.BooleanField(default=True) privacy = models.CharField(max_length=255, default='public') sensitive = models.BooleanField(default=False) - # the created date can't double as this, because of receiving federated posts + # the created date can't be this, because of receiving federated posts published_date = models.DateTimeField(default=datetime.now) favorites = models.ManyToManyField( 'User', @@ -51,6 +50,7 @@ class Review(Status): self.activity_type = 'Article' super().save(*args, **kwargs) + class Favorite(FedireadsModel): ''' fav'ing a post ''' user = models.ForeignKey('User', on_delete=models.PROTECT) @@ -70,7 +70,7 @@ class Tag(FedireadsModel): def save(self, *args, **kwargs): if not self.id: # add identifiers to new tags - self.identifier = re.sub(r'\W+', '-', self.name).lower() + self.identifier = urllib.parse.quote_plus(self.name) super().save(*args, **kwargs) class Meta: diff --git a/fedireads/templates/snippets/tag.html b/fedireads/templates/snippets/tag.html index ab32419d..48822a92 100644 --- a/fedireads/templates/snippets/tag.html +++ b/fedireads/templates/snippets/tag.html @@ -1,5 +1,5 @@
- {{ tag.name }} + {{ tag.name }} {% if tag.identifier in user_tags %}
{% csrf_token %} diff --git a/fedireads/urls.py b/fedireads/urls.py index 650adc45..61cb48da 100644 --- a/fedireads/urls.py +++ b/fedireads/urls.py @@ -45,7 +45,7 @@ urlpatterns = [ re_path(r'^book/(?P\w+)/?$', views.book_page), re_path(r'^book/(?P\w+)/(?Pfriends|local|federated)?$', views.book_page), re_path(r'^author/(?P\w+)/?$', views.author_page), - re_path(r'^tag/(?P[\w-]+)/?$', views.tag_page), + re_path(r'^tag/(?P.+)/?$', views.tag_page), re_path(r'^shelf/%s/(?P[\w-]+)/?$' % username_regex, views.shelf_page), # internal action endpoints