готов список новостей на главной странице
This commit is contained in:
@@ -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