diff --git a/cadpoint/cadpoint/urls.py b/cadpoint/cadpoint/urls.py index d539d22..6418d78 100644 --- a/cadpoint/cadpoint/urls.py +++ b/cadpoint/cadpoint/urls.py @@ -30,6 +30,7 @@ urlpatterns = [ re_path(r'^p(?P\d*)$', views.index), re_path(r'^tag_(?P[^/]*)$', views.index), re_path(r'^tag_(?P[^/]*)[^/]*/p(?P\d*)$', views.index), + re_path(r'^alltags$', views.alltags, name='web_alltags'), # Статья re_path(r'^item/(?P\d*)-\S*$', views.show_item), # После чистки кросс-ссылок в контенте legacy Joomla-редиректы временно diff --git a/cadpoint/templates/alltags.jinja2 b/cadpoint/templates/alltags.jinja2 new file mode 100644 index 0000000..272d141 --- /dev/null +++ b/cadpoint/templates/alltags.jinja2 @@ -0,0 +1,32 @@ +{% extends "base.jinja2" %}{% load slug_ru %} + +{% block Title %}Все теги{% endblock %} +{% block canonical %}https://cadpoint.ru/alltags{% endblock %} +{% block Description %}Все теги сайта CADpoint{% endblock %} +{% block Keywords %}cadpoint, теги, alltags, новости{% endblock %} + +{% block CONTENT %} + + +
+
+
+

Все теги сайта

+

{% if TAGS_IN_PAGE %}{% for I in TAGS_IN_PAGE %} + + {{ I.name }}   {{ I.NumTotal }} + {% endfor %} + {% else %}Тегов пока нет{% endif %}

+
+
+
+{% endblock %} \ No newline at end of file diff --git a/cadpoint/web/tests.py b/cadpoint/web/tests.py index eaeb953..f547047 100644 --- a/cadpoint/web/tests.py +++ b/cadpoint/web/tests.py @@ -143,6 +143,44 @@ class TagAutocompleteTests(TestCase): self.assertEqual(payload['pagination']['more'], False) +class AllTagsPageTests(TestCase): + def setUp(self): + user_model = get_user_model() + self.user = user_model.objects.create_superuser( + username='admin', + email='admin@example.com', + password='password', + ) + self.client.force_login(self.user) + + item1 = TbContent.objects.create( + szContentHead='Тест 1', + szContentIntro='Анонс 1', + szContentBody='Тело 1', + szContentSlug='test-1', + bContentPublish=True, + ) + item2 = TbContent.objects.create( + szContentHead='Тест 2', + szContentIntro='Анонс 2', + szContentBody='Тело 2', + szContentSlug='test-2', + bContentPublish=True, + ) + item1.tags.add('alpha', 'beta') + item2.tags.add('alpha') + + def test_alltags_page_lists_all_tags_with_counts(self): + response = self.client.get(reverse('web_alltags')) + + self.assertEqual(response.status_code, 200) + self.assertContains(response, 'Все теги сайта') + self.assertContains(response, '/tag_alpha') + self.assertContains(response, '/tag_beta') + self.assertContains(response, '2') + self.assertContains(response, '1') + + class TypographTests(TestCase): def test_save_generates_slug_from_clean_text(self): item = TbContent(szContentHead='Привет мир') diff --git a/cadpoint/web/views.py b/cadpoint/web/views.py index 6876e31..678b3a6 100644 --- a/cadpoint/web/views.py +++ b/cadpoint/web/views.py @@ -60,6 +60,24 @@ def tag_autocomplete(request): return JsonResponse({"results": results, "pagination": {"more": more}}) +@require_GET +def alltags(request): + """Показывает все теги сайта и число их вхождений во всех публикациях.""" + template = "alltags.jinja2" + to_template: dict[str, object] = {"COOKIES": check_cookies(request)} + + q_tags = ( + Tag.objects.annotate( + NumTotal=Count("taggit_taggeditem_items", distinct=True), + ) + .filter(NumTotal__gt=0) + .order_by("-NumTotal", "name") + ) + + to_template["TAGS_IN_PAGE"] = q_tags + return render(request, template, to_template) + + def index(request, slug_tags: str = "", ppage: int = 0): diff --git a/public/static/css/cadpoint.css b/public/static/css/cadpoint.css index 2947d31..015777e 100644 --- a/public/static/css/cadpoint.css +++ b/public/static/css/cadpoint.css @@ -319,7 +319,7 @@ div.news > nav.row { margin: 0; } } /* левые треугольные хвостики не активного тега (с ненулевой представленностью на странице) серые */ .tags > a.tag-not-active:before { - background: -moz-linear-gradient(45deg, #ccc 0%, #888 100%);7 + background: -moz-linear-gradient(45deg, #ccc 0%, #888 100%); background: -webkit-gradient(linear, left bottom, right top, color-stop(0%,#ccc), color-stop(100%,#888)); background: -webkit-linear-gradient(-45deg, #ccc 0%,#888 100%); background: -o-linear-gradient(45deg, #ccc 0%,#888 100%); @@ -357,6 +357,10 @@ div.news > nav.row { margin: 0; } .tags > a.tag-not-active:hover .tag-note { color: #008DD2; } .tags > a:not(:hover), .tags > a:not(:hover) .tag-note { transition:1s; } +/* Для страницы всех тегов */ +a.tag-active > .tag-note > ._tag { color: #fee; transition:0.5s;} +a.tag-active:hover > .tag-note > ._tag { color: #008DD2; transition:0.5s;} + /**************************** ** ОФОРМЛЕНИЕ ТЕГОВ ********* ****************************/