tg-1783 #ready-for-test - Fix wiki links compatibility
parent
f37de85961
commit
ce88a60073
|
@ -15,20 +15,27 @@
|
||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
from django.utils import baseconv
|
from django.utils import baseconv
|
||||||
from django.template.defaultfilters import slugify
|
from django.template.defaultfilters import slugify as django_slugify
|
||||||
|
|
||||||
import time
|
import time
|
||||||
|
|
||||||
from unidecode import unidecode
|
from unidecode import unidecode
|
||||||
|
|
||||||
|
|
||||||
|
def slugify(value):
|
||||||
|
"""
|
||||||
|
Return a slug
|
||||||
|
"""
|
||||||
|
return django_slugify(unidecode(value or ""))
|
||||||
|
|
||||||
|
|
||||||
def slugify_uniquely(value, model, slugfield="slug"):
|
def slugify_uniquely(value, model, slugfield="slug"):
|
||||||
"""
|
"""
|
||||||
Returns a slug on a name which is unique within a model's table
|
Returns a slug on a name which is unique within a model's table
|
||||||
"""
|
"""
|
||||||
|
|
||||||
suffix = 0
|
suffix = 0
|
||||||
potential = base = slugify(unidecode(value))
|
potential = base = django_slugify(unidecode(value))
|
||||||
if len(potential) == 0:
|
if len(potential) == 0:
|
||||||
potential = 'null'
|
potential = 'null'
|
||||||
while True:
|
while True:
|
||||||
|
@ -45,7 +52,7 @@ def slugify_uniquely_for_queryset(value, queryset, slugfield="slug"):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
suffix = 0
|
suffix = 0
|
||||||
potential = base = slugify(unidecode(value))
|
potential = base = django_slugify(unidecode(value))
|
||||||
if len(potential) == 0:
|
if len(potential) == 0:
|
||||||
potential = 'null'
|
potential = 'null'
|
||||||
while True:
|
while True:
|
||||||
|
|
|
@ -22,6 +22,7 @@ from markdown.treeprocessors import Treeprocessor
|
||||||
from markdown.util import etree
|
from markdown.util import etree
|
||||||
|
|
||||||
from taiga.front import resolve
|
from taiga.front import resolve
|
||||||
|
from taiga.base.utils.slug import slugify
|
||||||
|
|
||||||
import re
|
import re
|
||||||
|
|
||||||
|
@ -48,7 +49,7 @@ class WikiLinksPattern(Pattern):
|
||||||
|
|
||||||
def handleMatch(self, m):
|
def handleMatch(self, m):
|
||||||
label = m.group(2).strip()
|
label = m.group(2).strip()
|
||||||
url = resolve("wiki", self.project.slug, label)
|
url = resolve("wiki", self.project.slug, slugify(label))
|
||||||
|
|
||||||
if m.group(3):
|
if m.group(3):
|
||||||
title = m.group(3).strip()[1:]
|
title = m.group(3).strip()[1:]
|
||||||
|
|
|
@ -101,6 +101,17 @@ def test_render_wikilink():
|
||||||
expected_result = "<p><a class=\"reference wiki\" href=\"http://localhost:9001/project/test/wiki/test\" title=\"test\">test</a></p>"
|
expected_result = "<p><a class=\"reference wiki\" href=\"http://localhost:9001/project/test/wiki/test\" title=\"test\">test</a></p>"
|
||||||
assert render(dummy_project, "[[test]]") == expected_result
|
assert render(dummy_project, "[[test]]") == expected_result
|
||||||
|
|
||||||
|
def test_render_wikilink_1():
|
||||||
|
expected_result = "<p><a class=\"reference wiki\" href=\"http://localhost:9001/project/test/wiki/test\" title=\"test\">test</a></p>"
|
||||||
|
assert render(dummy_project, "[[test]]") == expected_result
|
||||||
|
|
||||||
|
def test_render_wikilink_2():
|
||||||
|
expected_result = "<p><a class=\"reference wiki\" href=\"http://localhost:9001/project/test/wiki/test-page\" title=\"test page\">test page</a></p>"
|
||||||
|
assert render(dummy_project, "[[test page]]") == expected_result
|
||||||
|
|
||||||
|
def test_render_wikilink_3():
|
||||||
|
expected_result = "<p><a class=\"reference wiki\" href=\"http://localhost:9001/project/test/wiki/testpage\" title=\"TestPage\">TestPage</a></p>"
|
||||||
|
assert render(dummy_project, "[[TestPage]]") == expected_result
|
||||||
|
|
||||||
def test_render_wikilink_with_custom_title():
|
def test_render_wikilink_with_custom_title():
|
||||||
expected_result = "<p><a class=\"reference wiki\" href=\"http://localhost:9001/project/test/wiki/test\" title=\"custom\">custom</a></p>"
|
expected_result = "<p><a class=\"reference wiki\" href=\"http://localhost:9001/project/test/wiki/test\" title=\"custom\">custom</a></p>"
|
||||||
|
|
|
@ -18,10 +18,24 @@
|
||||||
from taiga.projects.models import Project
|
from taiga.projects.models import Project
|
||||||
from taiga.users.models import User
|
from taiga.users.models import User
|
||||||
|
|
||||||
|
from taiga.base.utils.slug import slugify
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
pytestmark = pytest.mark.django_db
|
pytestmark = pytest.mark.django_db
|
||||||
|
|
||||||
|
|
||||||
|
def test_slugify_1():
|
||||||
|
assert slugify("漢字") == "han-zi"
|
||||||
|
|
||||||
|
|
||||||
|
def test_slugify_2():
|
||||||
|
assert slugify("TestExamplePage") == "testexamplepage"
|
||||||
|
|
||||||
|
|
||||||
|
def test_slugify_3():
|
||||||
|
assert slugify(None) == ""
|
||||||
|
|
||||||
|
|
||||||
def test_project_slug_with_special_chars():
|
def test_project_slug_with_special_chars():
|
||||||
user = User.objects.create(username="test")
|
user = User.objects.create(username="test")
|
||||||
project = Project.objects.create(name="漢字", description="漢字", owner=user)
|
project = Project.objects.create(name="漢字", description="漢字", owner=user)
|
||||||
|
|
Loading…
Reference in New Issue