Urlencode tag names as identifiers

Fixes #37
This commit is contained in:
Mouse Reeve 2020-03-07 13:29:57 -08:00
parent c07aa387fa
commit 95c8dc1d67
3 changed files with 6 additions and 6 deletions

View file

@ -2,9 +2,8 @@
from datetime import datetime from datetime import datetime
from django.core.validators import MaxValueValidator, MinValueValidator from django.core.validators import MaxValueValidator, MinValueValidator
from django.db import models from django.db import models
from django.dispatch import receiver
from model_utils.managers import InheritanceManager from model_utils.managers import InheritanceManager
import re import urllib.parse
from fedireads.utils.models import FedireadsModel from fedireads.utils.models import FedireadsModel
@ -20,7 +19,7 @@ class Status(FedireadsModel):
local = models.BooleanField(default=True) local = models.BooleanField(default=True)
privacy = models.CharField(max_length=255, default='public') privacy = models.CharField(max_length=255, default='public')
sensitive = models.BooleanField(default=False) 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) published_date = models.DateTimeField(default=datetime.now)
favorites = models.ManyToManyField( favorites = models.ManyToManyField(
'User', 'User',
@ -51,6 +50,7 @@ class Review(Status):
self.activity_type = 'Article' self.activity_type = 'Article'
super().save(*args, **kwargs) super().save(*args, **kwargs)
class Favorite(FedireadsModel): class Favorite(FedireadsModel):
''' fav'ing a post ''' ''' fav'ing a post '''
user = models.ForeignKey('User', on_delete=models.PROTECT) user = models.ForeignKey('User', on_delete=models.PROTECT)
@ -70,7 +70,7 @@ class Tag(FedireadsModel):
def save(self, *args, **kwargs): def save(self, *args, **kwargs):
if not self.id: if not self.id:
# add identifiers to new tags # 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) super().save(*args, **kwargs)
class Meta: class Meta:

View file

@ -1,5 +1,5 @@
<div class="tag"> <div class="tag">
<a href="/tag/{{ tag.identifier }}">{{ tag.name }}</a> <a href="/tag/{{ tag.identifier|urlencode }}">{{ tag.name }}</a>
{% if tag.identifier in user_tags %} {% if tag.identifier in user_tags %}
<form class="tag-form" name="tag" action="/untag/" method="post"> <form class="tag-form" name="tag" action="/untag/" method="post">
{% csrf_token %} {% csrf_token %}

View file

@ -45,7 +45,7 @@ urlpatterns = [
re_path(r'^book/(?P<book_identifier>\w+)/?$', views.book_page), re_path(r'^book/(?P<book_identifier>\w+)/?$', views.book_page),
re_path(r'^book/(?P<book_identifier>\w+)/(?P<tab>friends|local|federated)?$', views.book_page), re_path(r'^book/(?P<book_identifier>\w+)/(?P<tab>friends|local|federated)?$', views.book_page),
re_path(r'^author/(?P<author_identifier>\w+)/?$', views.author_page), re_path(r'^author/(?P<author_identifier>\w+)/?$', views.author_page),
re_path(r'^tag/(?P<tag_id>[\w-]+)/?$', views.tag_page), re_path(r'^tag/(?P<tag_id>.+)/?$', views.tag_page),
re_path(r'^shelf/%s/(?P<shelf_identifier>[\w-]+)/?$' % username_regex, views.shelf_page), re_path(r'^shelf/%s/(?P<shelf_identifier>[\w-]+)/?$' % username_regex, views.shelf_page),
# internal action endpoints # internal action endpoints