diff --git a/.gitignore b/.gitignore index c37e91a..a83cc85 100644 --- a/.gitignore +++ b/.gitignore @@ -69,3 +69,5 @@ coverage.xml /static/css/dist/ node_modules/ /data + +**/__pycache__ diff --git a/data/db.sqlite3 b/data/db.sqlite3 index 1d31f3d..b7fc6bd 100644 Binary files a/data/db.sqlite3 and b/data/db.sqlite3 differ diff --git a/links/__pycache__/views.cpython-312.pyc b/links/__pycache__/views.cpython-312.pyc deleted file mode 100644 index 8fe5b6d..0000000 Binary files a/links/__pycache__/views.cpython-312.pyc and /dev/null differ diff --git a/links/templates/links/link_form.html b/links/templates/links/link_form.html index 43316b4..1010cda 100644 --- a/links/templates/links/link_form.html +++ b/links/templates/links/link_form.html @@ -42,6 +42,19 @@ +

{% trans "Note:" %}

+
+

+ {% trans "Please note that special characters are not allowed in the alias when creating or updating a link." %} +
+ {% trans "For example:" %} +

+

+
diff --git a/links/views.py b/links/views.py index 08d70ad..ee0347a 100644 --- a/links/views.py +++ b/links/views.py @@ -118,15 +118,18 @@ def delete_selected(request): return redirect('link_list') def redirect_to_original(request, alias): + # 移除别名中的特殊字符 + processed_alias = ''.join(e for e in alias if e.isalnum()) + try: - link = Link.objects.get(alias=alias) + link = Link.objects.get(alias=processed_alias) link.click_count = F('click_count') + 1 link.save() ClickLog.objects.create(link=link) # 记录点击 return redirect(link.original_url) except Link.DoesNotExist: - messages.warning(request, _("The alias '{}' doesn't exist. Do you want to create a new one?").format(alias)) - return redirect(reverse('link_create') + f'?alias={alias}') + messages.warning(request, _("The alias '{}' doesn't exist. Do you want to create a new one?").format(processed_alias)) + return redirect(reverse('link_create') + f'?alias={processed_alias}') class LinkDetailView(DetailView): model = Link diff --git a/locale/zh_Hans/LC_MESSAGES/django.mo b/locale/zh_Hans/LC_MESSAGES/django.mo index d53930d..6ab5e85 100644 Binary files a/locale/zh_Hans/LC_MESSAGES/django.mo and b/locale/zh_Hans/LC_MESSAGES/django.mo differ diff --git a/locale/zh_Hans/LC_MESSAGES/django.po b/locale/zh_Hans/LC_MESSAGES/django.po index 8cf3054..27e1ea7 100644 --- a/locale/zh_Hans/LC_MESSAGES/django.po +++ b/locale/zh_Hans/LC_MESSAGES/django.po @@ -168,3 +168,13 @@ msgstr "热门链接" msgid "No popular links available" msgstr "暂无热门链接" + +msgid "Note:" +msgstr "请注意" + +msgid "Menu" +msgstr "菜单" + + +msgid "Alias cannot contain special characters." +msgstr "链接别名中不能带有 - 或者 _ 以及其他任意特殊字符"