готов список новостей на главной странице
This commit is contained in:
@@ -36,4 +36,4 @@ def safe_html_special_symbols(s: str) -> str:
|
||||
result = result.replace('№', '№')
|
||||
result = result.replace('<br />', ' ')
|
||||
result = result.replace('<br>', ' ')
|
||||
return result
|
||||
return result
|
||||
|
||||
@@ -68,7 +68,7 @@ class TbContent(models.Model):
|
||||
help_text=u"Дата публикации, с её момента новость появится на сайте."
|
||||
)
|
||||
tdContentPublishDown = models.DateTimeField(
|
||||
db_index=True, null=True, blank=True, # default=datetime.datetime(2035, 12, 31, 23, 59, 59, 0), # default=0,
|
||||
db_index=True, null=True, blank=True, # default=datetime.datetime(2035, 12, 31, 23, 59, 59, 0), # default=0,
|
||||
verbose_name="Окончания публикации",
|
||||
help_text=u"Дата окончания публикации, с её момента новость исчезнет с сайта."
|
||||
)
|
||||
@@ -165,7 +165,7 @@ class TbContent(models.Model):
|
||||
def save(self, *args, **kwargs):
|
||||
# переопределяем метод save() чтобы "проверуть" тексты через типографы...
|
||||
if self.szContentSlug is None or self.szContentSlug == "" or " " in self.szContentSlug:
|
||||
print("ку-ку", self.szContentHead)
|
||||
# print("ку-ку", self.szContentHead)
|
||||
result_slug = pytils.translit.slugify(
|
||||
safe_html_special_symbols(self.szContentHead)).lower()
|
||||
while TbContent.objects.filter(szContentSlug=result_slug).count() != 0:
|
||||
|
||||
20
cadpoint/web/templatetags/slug_ru.py
Normal file
20
cadpoint/web/templatetags/slug_ru.py
Normal file
@@ -0,0 +1,20 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from django import template
|
||||
from web.add_function import safe_html_special_symbols
|
||||
import pytils
|
||||
|
||||
register = template.Library()
|
||||
|
||||
|
||||
@register.filter
|
||||
def slug_ru(value: str, arg: int) -> str:
|
||||
try:
|
||||
arg = int(arg)
|
||||
return pytils.translit.slugify(str(value).lower())[:int(arg)]
|
||||
except ValueError:
|
||||
return pytils.translit.slugify(str(value).lower())
|
||||
|
||||
|
||||
@register.filter
|
||||
def safe_html_ss(value: str) -> str:
|
||||
return safe_html_special_symbols(value)
|
||||
@@ -1,6 +1,11 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from django.shortcuts import render
|
||||
from django.db.models import Q
|
||||
from datetime import datetime
|
||||
from django.utils import timezone
|
||||
from web.models import TbContent
|
||||
from web.add_function import *
|
||||
import pytz
|
||||
|
||||
# Create your views here.
|
||||
def handler404(request, exception: str) -> render:
|
||||
@@ -34,4 +39,40 @@ def index(request) -> render:
|
||||
"""
|
||||
template = "index.jinja2" # шаблон
|
||||
to_template = {"COOKIES": check_cookies(request)}
|
||||
# query = Q(tdContentPublishDown__isnull=True)
|
||||
# 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 5 OFFSET 0"
|
||||
q_content = TbContent.objects.raw(query)
|
||||
q_tags = TbContent.objects.raw("SELECT DISTINCT tTotalInfo.*,"
|
||||
" IF (tPageInfo.NumInPage IS UNKNOWN, 0, tPageInfo.NumInPage) AS NumInPage "
|
||||
"FROM (SELECT DISTINCT taggit_tag.id, COUNT(tPage.id) AS NumInPage "
|
||||
" FROM taggit_taggeditem"
|
||||
" INNER JOIN taggit_tag"
|
||||
" ON taggit_taggeditem.tag_id = taggit_tag.id"
|
||||
" INNER JOIN (%s) tPage"
|
||||
" ON taggit_taggeditem.object_id = tPage.id"
|
||||
" GROUP BY taggit_tag.id) tPageInfo"
|
||||
" RIGHT OUTER JOIN (SELECT DISTINCT"
|
||||
" taggit_tag.*,"
|
||||
" COUNT(web_tbcontent.id) AS NumTotal"
|
||||
" FROM taggit_taggeditem"
|
||||
" INNER JOIN taggit_tag"
|
||||
" ON taggit_taggeditem.tag_id = taggit_tag.id"
|
||||
" INNER JOIN web_tbcontent"
|
||||
" ON taggit_taggeditem.object_id = web_tbcontent.id"
|
||||
" GROUP BY taggit_tag.id, taggit_tag.name, taggit_tag.slug) tTotalInfo"
|
||||
" ON tPageInfo.id = tTotalInfo.id"
|
||||
" GROUP BY tPageInfo.id, tPageInfo.NumInPage,"
|
||||
" tTotalInfo.id, tTotalInfo.NumTotal,"
|
||||
" tTotalInfo.name, tTotalInfo.slug "
|
||||
"ORDER BY tPageInfo.NumInPage DESC, tTotalInfo.name,"
|
||||
" tTotalInfo.NumTotal DESC" % (query,))
|
||||
to_template.update({"LENTA": q_content, "TAGS_IN_PAGE": q_tags})
|
||||
return render(request, template, to_template)
|
||||
|
||||
Reference in New Issue
Block a user