From 004171f7cc1881da1fbc9d6f5e9d10f0626c5bd7 Mon Sep 17 00:00:00 2001 From: erjemin Date: Thu, 26 Aug 2021 15:54:27 +0300 Subject: [PATCH] =?UTF-8?q?=D0=BD=D0=B0=D0=B2=D0=B8=D0=B3=D0=B0=D1=86?= =?UTF-8?q?=D0=B8=D1=8F=20=D0=BF=D0=BE=20=D1=82=D0=B5=D0=B3=D0=B0=D0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cadpoint/cadpoint/urls.py | 3 + cadpoint/templates/blocks/tags-cloud.jinja2 | 20 +++---- cadpoint/templates/index.jinja2 | 16 +++--- cadpoint/templates/item.jinja2 | 7 +-- cadpoint/web/templatetags/slug_ru.py | 23 ++++++++ cadpoint/web/views.py | 64 +++++++++++++++++---- public/static/css/cadpoint.css | 8 ++- 7 files changed, 102 insertions(+), 39 deletions(-) diff --git a/cadpoint/cadpoint/urls.py b/cadpoint/cadpoint/urls.py index 7d4cc38..66e19c5 100644 --- a/cadpoint/cadpoint/urls.py +++ b/cadpoint/cadpoint/urls.py @@ -24,6 +24,8 @@ urlpatterns = [ path('admin/', admin.site.urls), url(r'^$', views.index), url(r'^p(?P\d*)$', views.index), + url(r'^tag_(?P[^/]*)$', views.index), + url(r'^tag_(?P[^/]*)[^/]*/p(?P\d*)$', views.index), url(r'^publication/32-hardware/(?P\d*)-\S*$', views.redirect_item), url(r'^publication/39-interview/(?P\d*)-\S*$', views.redirect_item), @@ -40,6 +42,7 @@ urlpatterns = [ url(r'^aboutcadpoint.html/(?P\d*)-\S*$', views.redirect_item), url(r'^item/(?P\d*)-\S*$', views.show_item), + url(r'^sitemap.xml$', views.sitemap), ] diff --git a/cadpoint/templates/blocks/tags-cloud.jinja2 b/cadpoint/templates/blocks/tags-cloud.jinja2 index adfeaf2..c346e52 100644 --- a/cadpoint/templates/blocks/tags-cloud.jinja2 +++ b/cadpoint/templates/blocks/tags-cloud.jinja2 @@ -16,23 +16,19 @@ ------------ Необязательные параметры: + TAGS_L -- лист из слагов (slug), которые должны быть помечены как активные. - ACTIVE_TAG_ID -- id тега, который должен быть помечен как активный. - - HIDEN_TAG_ID -- id тега, который надо "погасить" и не отображать в облаке. - - SEC -- ID таблицы tbSection для работы облака тегов при включеном фильтре по Разделам - - CAT -- ID таблицы tbCategories для работы облака тегов при включеном фильтре Категорий - -{% endcomment %} -

{% for I in TAGS_IN_PAGE %}{% if I.id != HIDEN_TAG_ID %}{% if I.NumInPage > 0%} - +{% endcomment %}{% load slug_ru %} +

{% for I in TAGS_IN_PAGE %}{% if I.NumInPage > 0 %}{% if I.slug in TAGS_L %} + {{ I.name }}   {{ I.NumInPage }}/{{ I.NumTotal }} {% else %} + + {{ I.name }}   {{ I.NumInPage }}/{{ I.NumTotal }} + {% endif %}{% else %} {{ I.name }}   {{ I.NumInPage }}/{{ I.NumTotal }} - {% endif %}{% endif %}{% endfor %}{% if ACTIVE_TAG_SLUG %} + {% endif %}{% endfor %}{% if TAGS_L %} {% endif %}

\ No newline at end of file diff --git a/cadpoint/templates/index.jinja2 b/cadpoint/templates/index.jinja2 index 8e31344..4c66b88 100644 --- a/cadpoint/templates/index.jinja2 +++ b/cadpoint/templates/index.jinja2 @@ -77,17 +77,17 @@ {% if PAGE_OF_LIST == 0 %}
  •  1
  • {% else %}
  • -  1 +  1
  • - {% endif %}{% if PAGE_OF_LIST|add:'-3' > 0 and PAGE_OF_LIST|add:'-2' <= TOTAL_PAGE %}
  • - {% endif %}{% if PAGE_OF_LIST|add:'-2' > 0 and PAGE_OF_LIST|add:'-1' <= TOTAL_PAGE %}
  • {{ PAGE_OF_LIST|add:'-1' }}
  • - {% endif %}{% if PAGE_OF_LIST|add:'-1' > 0 and PAGE_OF_LIST <= TOTAL_PAGE %}
  • {{ PAGE_OF_LIST }}
  • + {% endif %}{% if PAGE_OF_LIST|add:'-3' > 0 and PAGE_OF_LIST|add:'-2' <= TOTAL_PAGE %}
  • + {% endif %}{% if PAGE_OF_LIST|add:'-2' > 0 and PAGE_OF_LIST|add:'-1' <= TOTAL_PAGE %}
  • {{ PAGE_OF_LIST|add:'-1' }}
  • + {% endif %}{% if PAGE_OF_LIST|add:'-1' > 0 and PAGE_OF_LIST <= TOTAL_PAGE %}
  • {{ PAGE_OF_LIST }}
  • {% endif %}{% if PAGE_OF_LIST != 0 and PAGE_OF_LIST != TOTAL_PAGE %}
  • {{ PAGE_OF_LIST|add:'1' }}
  • - {% endif %}{% if PAGE_OF_LIST|add:'1' > 0 and PAGE_OF_LIST|add:'2' <= TOTAL_PAGE %}
  • {{ PAGE_OF_LIST|add:'2' }}
  • - {% endif %}{% if PAGE_OF_LIST|add:'2' > 0 and PAGE_OF_LIST|add:'3' <= TOTAL_PAGE %}
  • {{ PAGE_OF_LIST|add:'3' }}
  • - {% endif %}{% if PAGE_OF_LIST|add:'3' > 0 and PAGE_OF_LIST|add:'4' <= TOTAL_PAGE %}
  • + {% endif %}{% if PAGE_OF_LIST|add:'1' > 0 and PAGE_OF_LIST|add:'2' <= TOTAL_PAGE %}
  • {{ PAGE_OF_LIST|add:'2' }}
  • + {% endif %}{% if PAGE_OF_LIST|add:'2' > 0 and PAGE_OF_LIST|add:'3' <= TOTAL_PAGE %}
  • {{ PAGE_OF_LIST|add:'3' }}
  • + {% endif %}{% if PAGE_OF_LIST|add:'3' > 0 and PAGE_OF_LIST|add:'4' <= TOTAL_PAGE %}
  • {% endif %}{% if PAGE_OF_LIST < TOTAL_PAGE %}
  • - {{ TOTAL_PAGE|add:'1' }}  + {{ TOTAL_PAGE|add:'1' }} 
  • {% else %}
  • {{ TOTAL_PAGE|add:'1' }} 
  • {% endif %} diff --git a/cadpoint/templates/item.jinja2 b/cadpoint/templates/item.jinja2 index 2c2291d..4dbe0f8 100644 --- a/cadpoint/templates/item.jinja2 +++ b/cadpoint/templates/item.jinja2 @@ -58,7 +58,7 @@ {{ ITEM.szContentBody|safe }} {{ ITEM.szPointDes|safe }}{# Текст страницы или приамбула перед списком #}
    - + {##}{# #}{% endif %} {##} - - {% endblock %} - -{% block Top_JS1 %}{% endblock %} diff --git a/cadpoint/web/templatetags/slug_ru.py b/cadpoint/web/templatetags/slug_ru.py index 74620ad..49e9f34 100644 --- a/cadpoint/web/templatetags/slug_ru.py +++ b/cadpoint/web/templatetags/slug_ru.py @@ -8,6 +8,12 @@ register = template.Library() @register.filter def slug_ru(value: str, arg: int) -> str: + """ ДЕЛАЕТ СЛАГ (slug) ИЗ РУССКОЯЗЫЧНОЙ СТРОКИ + + :param value: получает русскоязычную (любую) строку + :param arg: сколько символов оставить (остальные обрежет) + :return: value: возвращает слугофицированную строку в нижнем регистре + """ try: arg = int(arg) return pytils.translit.slugify(str(value).lower())[:int(arg)] @@ -18,3 +24,20 @@ def slug_ru(value: str, arg: int) -> str: @register.filter def safe_html_ss(value: str) -> str: return safe_html_special_symbols(value) + + +@register.filter +def rm_tag(value: str, arg: str = "") -> str: + """ УДАЛЯТЕЛЬ ТЕГОВ + + :param value: получает строку типа "/tag_slug-1_slug-2_slug-A_slug-NN" (разделитель "_") + :param arg: слаг (slug) тега, который надо удалить, например "slug-2" + :return: value: возвращает строку "/tag_slug-1_slug-A_slug-NN" + """ + value = value.replace(arg, "") + value = value.replace("__", "_") + if value == "/tag_": + return "/" + if value[-1] == "_": + return value[0:-1] + return value diff --git a/cadpoint/web/views.py b/cadpoint/web/views.py index 1272583..286cd65 100644 --- a/cadpoint/web/views.py +++ b/cadpoint/web/views.py @@ -33,11 +33,13 @@ def handler500(request) -> render: def index(request, + slug_tags: str = "", ppage: int = 0) -> render: """ Главная страница :param request: :param ppage: текущая страница ленты + :param slug_tags: текущие slug-таги, разделитель "_" (в формате tag-1_tag-2_tag-eshe-odin :return: response: """ template = "index.jinja2" # шаблон @@ -46,12 +48,56 @@ def index(request, # query.add(Q(tdContentPublishDown__gt=timezone.now()), Q.OR) # query.add(Q(bContentPublish=True), Q.AND) # q_content = TbContent.objects.filter(query)[:5] - query = "SELECT web_tbcontent.* FROM web_tbcontent " \ - "WHERE (web_tbcontent.tdContentPublishDown IS NULL" \ - " OR web_tbcontent.tdContentPublishDown > NOW())" \ - " AND web_tbcontent.bContentPublish " \ - "ORDER BY web_tbcontent.tdContentPublishUp DESC " \ - "LIMIT 7 OFFSET %d" % (int(ppage) * 7, ) + if slug_tags == "": + query = "SELECT web_tbcontent.* FROM web_tbcontent " \ + "WHERE (web_tbcontent.tdContentPublishDown IS NULL" \ + " OR web_tbcontent.tdContentPublishDown > NOW())" \ + " AND web_tbcontent.tdContentPublishUp <= NOW() " \ + " AND web_tbcontent.bContentPublish " \ + "ORDER BY web_tbcontent.tdContentPublishUp DESC " \ + "LIMIT 7 OFFSET %d" % (int(ppage) * 7, ) + query_count = "SELECT 1 AS id," \ + " COUNT(web_tbcontent.id) AS tot_item " \ + "FROM web_tbcontent " \ + "WHERE (web_tbcontent.tdContentPublishDown IS NULL" \ + " OR web_tbcontent.tdContentPublishDown > NOW())" \ + " AND web_tbcontent.tdContentPublishUp <= NOW()" \ + " AND web_tbcontent.bContentPublish" + else: + l_tags = slug_tags.split("_") + s_tags = slug_tags.replace("_", "\', \'") + query = "SELECT web_tbcontent.* FROM taggit_taggeditem" \ + " INNER JOIN taggit_tag" \ + " ON taggit_taggeditem.tag_id = taggit_tag.id" \ + " AND taggit_taggeditem.content_type_id = 21" \ + " AND taggit_tag.slug IN ('%s')" \ + " RIGHT OUTER JOIN web_tbcontent" \ + " ON web_tbcontent.id = taggit_taggeditem.object_id " \ + "WHERE (web_tbcontent.tdContentPublishDown IS NULL" \ + " OR web_tbcontent.tdContentPublishDown > NOW())" \ + " AND web_tbcontent.tdContentPublishUp <= NOW() " \ + " AND web_tbcontent.bContentPublish " \ + "GROUP BY web_tbcontent.szContentHead " \ + "HAVING COUNT(DISTINCT taggit_tag.id) = %d " \ + "ORDER BY web_tbcontent.tdContentPublishUp DESC " \ + "LIMIT 7 OFFSET %d" % (s_tags, len(l_tags), int(ppage) * 7) + query_count = "SELECT 1 AS id," \ + " COUNT(SubQuery.id) AS tot_item " \ + "FROM (SELECT web_tbcontent.id" \ + " FROM taggit_taggeditem" \ + " INNER JOIN taggit_tag" \ + " ON taggit_taggeditem.tag_id = taggit_tag.id" \ + " AND taggit_taggeditem.content_type_id = 21" \ + " AND taggit_tag.slug IN ('%s')" \ + " RIGHT OUTER JOIN web_tbcontent" \ + " ON web_tbcontent.id = taggit_taggeditem.object_id" \ + " WHERE (web_tbcontent.tdContentPublishDown IS NULL" \ + " OR web_tbcontent.tdContentPublishDown > NOW())" \ + " AND web_tbcontent.tdContentPublishUp <= NOW()" \ + " AND web_tbcontent.bContentPublish" \ + " GROUP BY web_tbcontent.id" \ + " HAVING COUNT(DISTINCT taggit_tag.id) = %d) SubQuery" % (s_tags, len(l_tags)) + to_template.update({"TAGS_S": "/tag_" + slug_tags, "TAGS_L": l_tags}) q_content = TbContent.objects.raw(query) q_tags = TbContent.objects.raw("SELECT DISTINCT tTotalInfo.*," " IF (tPageInfo.NumInPage IS UNKNOWN, 0, tPageInfo.NumInPage) AS NumInPage " @@ -79,12 +125,6 @@ def index(request, "tTotalInfo.name LIMIT 20" % (query,)) to_template.update({"LENTA": q_content, "TAGS_IN_PAGE": q_tags}) to_template.update({"PAGE_OF_LIST": int(ppage)}) - query_count = "SELECT 1 AS id," \ - " COUNT(web_tbcontent.id) AS tot_item " \ - "FROM web_tbcontent " \ - "WHERE (web_tbcontent.tdContentPublishDown IS NULL" \ - " OR web_tbcontent.tdContentPublishDown > NOW())" \ - " AND web_tbcontent.bContentPublish" q_count = TbContent.objects.raw(query_count) # print("--", (q_count[0].tot_item - 1) // 7, q_count[0].tot_item) to_template.update({"TOTAL_PAGE": (q_count[0].tot_item - 1) // 7}) diff --git a/public/static/css/cadpoint.css b/public/static/css/cadpoint.css index 8cccab3..26a710a 100644 --- a/public/static/css/cadpoint.css +++ b/public/static/css/cadpoint.css @@ -62,6 +62,9 @@ div.lenta > div.row > div[class^="col"] > div.row > div[class^="col"] > p > ifra border: solid #006799 1px; border-radius: 4px; } +div.lenta > div.row > div[class^="col"] > div.row > div[class^="col"] > p > iframe { + aspect-ratio: calc( 19 / 9); +} div.lenta > div.row > div[class^="col"] div.row > div[class^="col"] > a:hover > img { border: solid #008DD2 1px; transition:0.6s; @@ -153,7 +156,9 @@ div.news > div.row > div[class^="col"] > time > small > small { color: #006799; padding-left: 4em; } -div.news > div.row > div[class^="col"] > p { +div.news > div.row > div[class^="col"] > p, +div.news > div.row > div[class^="col"] > ul > li, +div.news > div.row > div[class^="col"] > ol > li { font-size: 115%; font-weight: 100; } @@ -165,6 +170,7 @@ div.news > div.row > div[class^="col"] > p > iframe { border-bottom: solid white 12px; border-image: url('/static/svgs/logo_cadpoint-2021-border.svg') 0 0 600 0 round; } +div.news > div.row > div[class^="col"] > p > iframe { aspect-ratio: calc( 19 / 9); } div.news > div.row > div[class^="col"] > blockquote { font-family: 'Ubuntu Condensed', sans-serif; font-weight: 100;