diff --git a/links/__pycache__/views.cpython-312.pyc b/links/__pycache__/views.cpython-312.pyc index e77f540..40b9a92 100644 Binary files a/links/__pycache__/views.cpython-312.pyc and b/links/__pycache__/views.cpython-312.pyc differ diff --git a/links/templates/links/link_list.html b/links/templates/links/link_list.html index cf6b6f7..82e5f6b 100644 --- a/links/templates/links/link_list.html +++ b/links/templates/links/link_list.html @@ -22,14 +22,52 @@ - {% trans "Alias" %} + + + {% trans "Alias" %} + {% if current_sort == 'alias' %} + + + + {% endif %} + + {% trans "Original URL" %} - {% trans "Clicks" %} + + + {% trans "Clicks" %} + {% if current_sort == 'clicks' %} + + + + {% endif %} + + + + + {% trans "Created At" %} + {% if current_sort == 'created_at' %} + + + + {% endif %} + + + + + {% trans "Updated At" %} + {% if current_sort == 'updated_at' %} + + + + {% endif %} + + {% trans "Actions" %} - {% for link in object_list %} + {% for link in links %} @@ -41,6 +79,8 @@ {{ link.original_url }} {{ link.click_count }} + {{ link.created_at|date:"Y-m-d H:i" }} + {{ link.updated_at|date:"Y-m-d H:i" }} {% trans "Edit" %} {% trans "Delete" %} diff --git a/links/views.py b/links/views.py index 78f79e4..4bcad98 100644 --- a/links/views.py +++ b/links/views.py @@ -16,6 +16,31 @@ from django.http import JsonResponse class LinkListView(ListView): model = Link template_name = 'links/link_list.html' + context_object_name = 'links' + + def get_queryset(self): + queryset = super().get_queryset() + sort_by = self.request.GET.get('sort', 'alias') + order = self.request.GET.get('order', 'asc') + + if sort_by == 'alias': + ordering = F('alias').asc(nulls_last=True) if order == 'asc' else F('alias').desc(nulls_last=True) + elif sort_by == 'clicks': + ordering = F('click_count').asc(nulls_last=True) if order == 'asc' else F('click_count').desc(nulls_last=True) + elif sort_by == 'created_at': + ordering = F('created_at').asc(nulls_last=True) if order == 'asc' else F('created_at').desc(nulls_last=True) + elif sort_by == 'updated_at': + ordering = F('updated_at').asc(nulls_last=True) if order == 'asc' else F('updated_at').desc(nulls_last=True) + else: + ordering = F('alias').asc(nulls_last=True) + + return queryset.order_by(ordering) + + def get_context_data(self, **kwargs): + context = super().get_context_data(**kwargs) + context['current_sort'] = self.request.GET.get('sort', 'alias') + context['current_order'] = self.request.GET.get('order', 'asc') + return context class LinkCreateView(CreateView): model = Link diff --git a/locale/zh_Hans/LC_MESSAGES/django.mo b/locale/zh_Hans/LC_MESSAGES/django.mo index 67b041e..031bc91 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 c74f259..53f4492 100644 --- a/locale/zh_Hans/LC_MESSAGES/django.po +++ b/locale/zh_Hans/LC_MESSAGES/django.po @@ -78,8 +78,8 @@ msgstr "总点击次数" msgid "Created At" msgstr "创建时间" -msgid "Last Updated" -msgstr "最后更新" +msgid "Updated At" +msgstr "更新时间" msgid "Click Statistics" msgstr "点击统计" diff --git a/new_theme/static/css/dist/styles.css b/new_theme/static/css/dist/styles.css index 465b746..083b96a 100644 --- a/new_theme/static/css/dist/styles.css +++ b/new_theme/static/css/dist/styles.css @@ -900,6 +900,18 @@ select { margin-bottom: 0.5rem; } +.ml-1 { + margin-left: 0.25rem; +} + +.mr-1 { + margin-right: 0.25rem; +} + +.mr-4 { + margin-right: 1rem; +} + .block { display: block; } @@ -952,6 +964,10 @@ select { width: 1rem; } +.w-64 { + width: 16rem; +} + .min-w-full { min-width: 100%; } @@ -1020,6 +1036,12 @@ select { margin-left: calc(0.75rem * calc(1 - var(--tw-space-x-reverse))); } +.space-x-4 > :not([hidden]) ~ :not([hidden]) { + --tw-space-x-reverse: 0; + margin-right: calc(1rem * var(--tw-space-x-reverse)); + margin-left: calc(1rem * calc(1 - var(--tw-space-x-reverse))); +} + .divide-y > :not([hidden]) ~ :not([hidden]) { --tw-divide-y-reverse: 0; border-top-width: calc(1px * calc(1 - var(--tw-divide-y-reverse))); diff --git a/templates/base.html b/templates/base.html index 9a2d795..6fa6d2d 100644 --- a/templates/base.html +++ b/templates/base.html @@ -7,6 +7,7 @@ {% trans "URL Manager" %} +