mirror of
https://github.com/wahyd4/links.git
synced 2026-08-08 21:04:53 +10:00
Update logic to handle - and _ between words
This commit is contained in:
@@ -69,3 +69,5 @@ coverage.xml
|
||||
/static/css/dist/
|
||||
node_modules/
|
||||
/data
|
||||
|
||||
**/__pycache__
|
||||
|
||||
Binary file not shown.
Binary file not shown.
@@ -42,6 +42,19 @@
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
<h2 class="text-xl font-semibold mt-8 mb-4">{% trans "Note:" %}</h2>
|
||||
<div class="bg-gray-100 p-4 rounded-lg mb-4">
|
||||
<p class="mt-2 text-sm text-gray-500">
|
||||
{% trans "Please note that special characters are not allowed in the alias when creating or updating a link." %}
|
||||
<br>
|
||||
{% trans "For example:" %}
|
||||
<ul class="list-disc list-inside mt-2 text-gray-600">
|
||||
<li>{% trans "Valid alias: helloworld" %}</li>
|
||||
<li>{% trans "Invalid alias: hello@world!" %}</li>
|
||||
<li>{% trans "Accessing 'helloworld' as: hello-world or hello_world" %}</li>
|
||||
</ul>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
+6
-3
@@ -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
|
||||
|
||||
Binary file not shown.
@@ -168,3 +168,13 @@ msgstr "热门链接"
|
||||
|
||||
msgid "No popular links available"
|
||||
msgstr "暂无热门链接"
|
||||
|
||||
msgid "Note:"
|
||||
msgstr "请注意"
|
||||
|
||||
msgid "Menu"
|
||||
msgstr "菜单"
|
||||
|
||||
|
||||
msgid "Alias cannot contain special characters."
|
||||
msgstr "链接别名中不能带有 - 或者 _ 以及其他任意特殊字符"
|
||||
|
||||
Reference in New Issue
Block a user