отображение отдельной новости (item)
This commit is contained in:
@@ -26,7 +26,7 @@ BASE_DIR = Path(__file__).resolve().parent.parent
|
|||||||
SECRET_KEY = MY_SECRET_KEY
|
SECRET_KEY = MY_SECRET_KEY
|
||||||
|
|
||||||
# SECURITY WARNING: don't run with debug turned on in production!
|
# SECURITY WARNING: don't run with debug turned on in production!
|
||||||
if socket.gethostname() == MY_HOST_HOME:
|
if socket.gethostname() in (MY_HOST_HOME, MY_HOST_WORK):
|
||||||
DEBUG = True
|
DEBUG = True
|
||||||
else:
|
else:
|
||||||
# Все остальные хосты (подразумевается продакшн)
|
# Все остальные хосты (подразумевается продакшн)
|
||||||
@@ -218,7 +218,7 @@ if DEBUG: # DEBUG: заменяем настройки прода, на на
|
|||||||
}
|
}
|
||||||
MIDDLEWARE += ['debug_toolbar.middleware.DebugToolbarMiddleware', ]
|
MIDDLEWARE += ['debug_toolbar.middleware.DebugToolbarMiddleware', ]
|
||||||
INSTALLED_APPS += ['debug_toolbar', ]
|
INSTALLED_APPS += ['debug_toolbar', ]
|
||||||
INTERNAL_IPS = ['127.0.0.1', '192.168.1.30']
|
INTERNAL_IPS = ['127.0.0.1', '192.168.1.30', '10.10.5.6']
|
||||||
# this is the main reason for not showing up the toolbar
|
# this is the main reason for not showing up the toolbar
|
||||||
import mimetypes
|
import mimetypes
|
||||||
mimetypes.add_type("application/javascript", ".js", True)
|
mimetypes.add_type("application/javascript", ".js", True)
|
||||||
|
|||||||
@@ -22,13 +22,18 @@ from web import views
|
|||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path('admin/', admin.site.urls),
|
path('admin/', admin.site.urls),
|
||||||
# /publication/32-hardware/
|
|
||||||
# /news/3-newsflash/
|
|
||||||
# /news/1-latest-news/
|
|
||||||
# /runet-cad/37-runet-cad/
|
|
||||||
# /video/
|
|
||||||
# /aboutcadpoint.html
|
|
||||||
url(r'^$', views.index),
|
url(r'^$', views.index),
|
||||||
|
|
||||||
|
url(r'^publication/32-hardware/(?P<content_id>\d*)-\S*$', views.redirect_item),
|
||||||
|
url(r'^news/3-newsflash/(?P<content_id>\d*)-\S*$', views.redirect_item),
|
||||||
|
url(r'^news/1-latest-news/(?P<content_id>\d*)-\S*$', views.redirect_item),
|
||||||
|
url(r'^runet-cad/37-runet-cad/(?P<content_id>\d*)-\S*$', views.redirect_item),
|
||||||
|
url(r'^video/(?P<content_id>\d*)-\S*$', views.redirect_item),
|
||||||
|
url(r'^component/content/article/(?P<content_id>\d*)-\S*$', views.redirect_item),
|
||||||
|
url(r'^aboutcadpoint.html/(?P<content_id>\d*)-\S*$', views.redirect_item),
|
||||||
|
|
||||||
|
url(r'^item/(?P<content_id>\d*)-\S*$', views.show_item),
|
||||||
|
|
||||||
]
|
]
|
||||||
|
|
||||||
handler404 = 'web.views.handler404'
|
handler404 = 'web.views.handler404'
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
from django.shortcuts import render
|
from django.shortcuts import render, HttpResponseRedirect
|
||||||
|
from django.http import Http404
|
||||||
from django.db.models import Q
|
from django.db.models import Q
|
||||||
from datetime import datetime
|
# from datetime import datetime
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
from web.models import TbContent
|
from web.models import TbContent
|
||||||
from web.add_function import *
|
from web.add_function import *
|
||||||
@@ -31,10 +32,12 @@ def handler500(request) -> render:
|
|||||||
return response
|
return response
|
||||||
|
|
||||||
|
|
||||||
def index(request) -> render:
|
def index(request,
|
||||||
|
ppage: int = 0) -> render:
|
||||||
""" Главная страница
|
""" Главная страница
|
||||||
|
|
||||||
:param request:
|
:param request:
|
||||||
|
:param ppage: текущая страница ленты
|
||||||
:return: response:
|
:return: response:
|
||||||
"""
|
"""
|
||||||
template = "index.jinja2" # шаблон
|
template = "index.jinja2" # шаблон
|
||||||
@@ -48,7 +51,7 @@ def index(request) -> render:
|
|||||||
" OR web_tbcontent.tdContentPublishDown > NOW())" \
|
" OR web_tbcontent.tdContentPublishDown > NOW())" \
|
||||||
" AND web_tbcontent.bContentPublish " \
|
" AND web_tbcontent.bContentPublish " \
|
||||||
"ORDER BY web_tbcontent.tdContentPublishUp DESC " \
|
"ORDER BY web_tbcontent.tdContentPublishUp DESC " \
|
||||||
"LIMIT 5 OFFSET 0"
|
"LIMIT 7 OFFSET %d" % (int(ppage) * 7, )
|
||||||
q_content = TbContent.objects.raw(query)
|
q_content = TbContent.objects.raw(query)
|
||||||
q_tags = TbContent.objects.raw("SELECT DISTINCT tTotalInfo.*,"
|
q_tags = TbContent.objects.raw("SELECT DISTINCT tTotalInfo.*,"
|
||||||
" IF (tPageInfo.NumInPage IS UNKNOWN, 0, tPageInfo.NumInPage) AS NumInPage "
|
" IF (tPageInfo.NumInPage IS UNKNOWN, 0, tPageInfo.NumInPage) AS NumInPage "
|
||||||
@@ -75,4 +78,83 @@ def index(request) -> render:
|
|||||||
"ORDER BY tPageInfo.NumInPage DESC, tTotalInfo.name,"
|
"ORDER BY tPageInfo.NumInPage DESC, tTotalInfo.name,"
|
||||||
" tTotalInfo.NumTotal DESC" % (query,))
|
" tTotalInfo.NumTotal DESC" % (query,))
|
||||||
to_template.update({"LENTA": q_content, "TAGS_IN_PAGE": q_tags})
|
to_template.update({"LENTA": q_content, "TAGS_IN_PAGE": q_tags})
|
||||||
|
to_template.update({"PAGE_OF_LIST": int(ppage)})
|
||||||
return render(request, template, to_template)
|
return render(request, template, to_template)
|
||||||
|
|
||||||
|
|
||||||
|
def redirect_item(request,
|
||||||
|
content_id: int = 0) -> render:
|
||||||
|
""" Переадресация URL для обеспечения переходов из поисковиков по уже проиндексированным страницам
|
||||||
|
|
||||||
|
:param request:
|
||||||
|
:param point: str_id блока, в которой находится контент
|
||||||
|
:param item: str_id страницы/категории, в которой находится контент
|
||||||
|
:param content_id: id контента которую надо отобразить
|
||||||
|
:return: response:
|
||||||
|
"""
|
||||||
|
return HttpResponseRedirect("/item/%d-" % int(content_id))
|
||||||
|
|
||||||
|
|
||||||
|
def show_item(request,
|
||||||
|
content_id: int = 0,
|
||||||
|
ppage: int = 0) -> render:
|
||||||
|
""" Формирование "ленты" о предприятии
|
||||||
|
|
||||||
|
:param request:
|
||||||
|
:param content_id: id контента которую надо отобразить
|
||||||
|
:return: response:
|
||||||
|
"""
|
||||||
|
template = "item.jinja2" # шаблон
|
||||||
|
to_template = {"COOKIES": check_cookies(request)}
|
||||||
|
try:
|
||||||
|
q_item = TbContent.objects.filter(id=int(content_id)).first()
|
||||||
|
if not q_item.bContentPublish:
|
||||||
|
raise Http404("Контент не опубликован")
|
||||||
|
to_template.update({"ITEM": q_item})
|
||||||
|
# query = Q(tdContentPublishDown__isnull=True)
|
||||||
|
# query.add(Q(tdContentPublishDown__gt=timezone.now()), Q.OR)
|
||||||
|
# query.add(Q(bContentPublish=True), Q.AND)
|
||||||
|
# query.add(Q(tdContentPublishUp__lte=q_item.tdContentPublishUp), Q.AND)
|
||||||
|
q_items_after = TbContent.objects.filter(
|
||||||
|
Q(tdContentPublishDown__isnull=True) | Q(tdContentPublishDown__gt=timezone.now()),
|
||||||
|
Q(bContentPublish=True),
|
||||||
|
Q(tdContentPublishUp__lte=q_item.tdContentPublishUp)
|
||||||
|
).order_by("-tdContentPublishUp", "id")[:4]
|
||||||
|
q_items_before = TbContent.objects.filter(
|
||||||
|
Q(tdContentPublishDown__isnull=True) | Q(tdContentPublishDown__gt=timezone.now()),
|
||||||
|
bContentPublish=True,
|
||||||
|
tdContentPublishUp__gt=q_item.tdContentPublishUp
|
||||||
|
).order_by("tdContentPublishUp", "id")[:3]
|
||||||
|
try:
|
||||||
|
p = 0 if "p" not in request.GET else int(request.GET["p"])
|
||||||
|
n = 0 if "n" not in request.GET else int(request.GET["n"])
|
||||||
|
count = 0
|
||||||
|
for i in q_items_before:
|
||||||
|
count += 1
|
||||||
|
if n-count < 1:
|
||||||
|
i.pp = p - 1
|
||||||
|
i.nn = n + 7 - count
|
||||||
|
else:
|
||||||
|
i.pp = p
|
||||||
|
i.nn = n - count
|
||||||
|
count = 0
|
||||||
|
for i in q_items_after:
|
||||||
|
if i.id != q_item.id:
|
||||||
|
count += 1
|
||||||
|
if n+count <= 7:
|
||||||
|
i.pp = p
|
||||||
|
i.nn = n + count
|
||||||
|
else:
|
||||||
|
i.pp = p + 1
|
||||||
|
i.nn = n+count - 7
|
||||||
|
to_template.update({"PER_PAGE": 7})
|
||||||
|
to_template.update({"PAGE": p})
|
||||||
|
except ValueError:
|
||||||
|
to_template.update({"PAGE": 0})
|
||||||
|
pass
|
||||||
|
to_template.update({"PAGE_OF_LIST": int(ppage)})
|
||||||
|
to_template.update({"ITEMS_AFTER": q_items_after})
|
||||||
|
to_template.update({"ITEMS_BEFORE": q_items_before})
|
||||||
|
return render(request, template, to_template)
|
||||||
|
except (ValueError, AttributeError, TbContent.DoesNotExist, TbContent.MultipleObjectsReturned):
|
||||||
|
raise Http404("Контента с таким id не существует")
|
||||||
|
|||||||
@@ -9,8 +9,13 @@ h1, h2, h3, h4, h5, h6 {color: #006799; font-family: 'Ubuntu Condensed', sans-se
|
|||||||
a { color: #006799; text-decoration: none; border-bottom: 1px dotted #006799; }
|
a { color: #006799; text-decoration: none; border-bottom: 1px dotted #006799; }
|
||||||
a:hover { color: #008DD2; border-bottom: 1px solid #008DD2; transition:0.6s; }
|
a:hover { color: #008DD2; border-bottom: 1px solid #008DD2; transition:0.6s; }
|
||||||
a:not(hover) { transition:1.2s; }
|
a:not(hover) { transition:1.2s; }
|
||||||
|
.s { font-size: small; }
|
||||||
|
.x { font-size: x-small; }
|
||||||
|
.xx { font-size: xx-small; }
|
||||||
|
.nw { white-space: nowrap; }
|
||||||
|
|
||||||
header > .navbar {background-color: white}
|
header > .navbar {background-color: white}
|
||||||
|
header > .navbar > .container > a.navbar-brand { border-bottom: none }
|
||||||
header > .navbar > .container > a.navbar-brand > img,
|
header > .navbar > .container > a.navbar-brand > img,
|
||||||
header.rastopiir > .container > a.navbar-brand > img { height: 42px; margin: 1ex 0; }
|
header.rastopiir > .container > a.navbar-brand > img { height: 42px; margin: 1ex 0; }
|
||||||
header > .navbar > .container > .navbar-nav > .nav-item > a {
|
header > .navbar > .container > .navbar-nav > .nav-item > a {
|
||||||
@@ -39,6 +44,14 @@ header > .navbar > .container > .navbar-nav > .nav-item > form > .input-group >
|
|||||||
}
|
}
|
||||||
header.rastopiir { height: 82px; z-index: 1;}
|
header.rastopiir { height: 82px; z-index: 1;}
|
||||||
|
|
||||||
|
/****************************
|
||||||
|
** ОФОРМЛЕНИЕ ХЛЕБНЫХ КРОШЕК *********
|
||||||
|
****************************/
|
||||||
|
div.bread-crumb > div.row > nav[class^="col"] > ol.breadcrumb {
|
||||||
|
font-family: 'Ubuntu Condensed', sans-serif;
|
||||||
|
margin-bottom: 2em !important;
|
||||||
|
}
|
||||||
|
|
||||||
/****************************
|
/****************************
|
||||||
** ОФОРМЛЕНИЕ ЛЕНТЫ *********
|
** ОФОРМЛЕНИЕ ЛЕНТЫ *********
|
||||||
****************************/
|
****************************/
|
||||||
@@ -69,7 +82,8 @@ div.lenta > div.row > div[class^="col"] div.row > div[class^="col"] > h3 > a {
|
|||||||
font-size: 130%;
|
font-size: 130%;
|
||||||
}
|
}
|
||||||
div.lenta > div.row > div[class^="col"] div.row > div[class^="col"] > nav.sm-tags { margin-bottom: 2ex; }
|
div.lenta > div.row > div[class^="col"] div.row > div[class^="col"] > nav.sm-tags { margin-bottom: 2ex; }
|
||||||
div.lenta > div.row > div[class^="col"] div.row > div[class^="col"] > nav.sm-tags > a {
|
div.lenta > div.row > div[class^="col"] div.row > div[class^="col"] > nav.sm-tags > a,
|
||||||
|
div.news > div.row > div[class^="col"] > nav.sm-tags > a {
|
||||||
font-family: 'Ubuntu Condensed', sans-serif;
|
font-family: 'Ubuntu Condensed', sans-serif;
|
||||||
font-size: smaller;
|
font-size: smaller;
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
@@ -78,12 +92,14 @@ div.lenta > div.row > div[class^="col"] div.row > div[class^="col"] > nav.sm-tag
|
|||||||
border-bottom: 1px dotted #006799;
|
border-bottom: 1px dotted #006799;
|
||||||
}
|
}
|
||||||
div.lenta > div.row > div[class^="col"] div.row > div[class^="col"] > h3 > a:hover,
|
div.lenta > div.row > div[class^="col"] div.row > div[class^="col"] > h3 > a:hover,
|
||||||
div.lenta > div.row > div[class^="col"] div.row > div[class^="col"] > nav.sm-tags > a:hover {
|
div.lenta > div.row > div[class^="col"] div.row > div[class^="col"] > nav.sm-tags > a:hover,
|
||||||
|
div.news > div.row > div[class^="col"] > nav.sm-tags > a:hover {
|
||||||
color: #008DD2;
|
color: #008DD2;
|
||||||
border-bottom: 1px solid #008DD2;
|
border-bottom: 1px solid #008DD2;
|
||||||
transition:0.6s;
|
transition:0.6s;
|
||||||
}
|
}
|
||||||
div.lenta > div.row > div[class^="col"] div.row > div[class^="col"] > nav.sm-tags > a:hover {
|
div.lenta > div.row > div[class^="col"] div.row > div[class^="col"] > nav.sm-tags > a:hover,
|
||||||
|
div.news > div.row > div[class^="col"] > nav.sm-tags > a:hover {
|
||||||
animation-name: scaleUpDown2;
|
animation-name: scaleUpDown2;
|
||||||
animation-duration: 0.6s;
|
animation-duration: 0.6s;
|
||||||
animation-timing-function: ease-in-out; -webkit-animation-timing-function: ease-in-out;
|
animation-timing-function: ease-in-out; -webkit-animation-timing-function: ease-in-out;
|
||||||
@@ -127,6 +143,70 @@ div.lenta > div.row > div[class^="col"] > div.row {
|
|||||||
95% { transform: rotate(-4deg); }
|
95% { transform: rotate(-4deg); }
|
||||||
100%{ transform: translateX(1); }
|
100%{ transform: translateX(1); }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/****************************
|
||||||
|
** ОФОРМЛЕНИЕ НОВОСТИ *********
|
||||||
|
****************************/
|
||||||
|
div.news > div.row > div[class^="col"] > time {
|
||||||
|
font-family: 'Ubuntu Condensed', sans-serif;
|
||||||
|
color: #888;
|
||||||
|
font-size: 120%;
|
||||||
|
font-weight: 100;
|
||||||
|
}
|
||||||
|
div.news > div.row > div[class^="col"] > p {
|
||||||
|
font-size: 115%;
|
||||||
|
font-weight: 100;
|
||||||
|
}
|
||||||
|
div.news > div.row > div[class^="col"] > p > img,
|
||||||
|
div.news > div.row > div[class^="col"] > p > iframe {
|
||||||
|
width: 100%;
|
||||||
|
border: solid #006799 1px;
|
||||||
|
border-radius: 4px;
|
||||||
|
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"] > hr {
|
||||||
|
margin: -30px auto 20px; padding: 0; color: transparent; height: 50px;
|
||||||
|
border: none; border-bottom: 1px dashed #006799; box-shadow: 0 20px 20px -20px gray;
|
||||||
|
}
|
||||||
|
div.news > div.row > div[class^="col"] > nav.sm-tags {
|
||||||
|
padding-bottom: 2em;
|
||||||
|
}
|
||||||
|
div.news > div.row > nav[class^="col"] {
|
||||||
|
font-family: 'Ubuntu Condensed', sans-serif;
|
||||||
|
font-weight: 100;
|
||||||
|
padding: 0;
|
||||||
|
background: whitesmoke;
|
||||||
|
background: linear-gradient(to bottom left, rgba(13,147,213,0.1), rgba(255,255,255,0) 45%);
|
||||||
|
border-radius: 10px 10px 0 0;
|
||||||
|
border-top: dotted 1px whitesmoke;
|
||||||
|
border-right: dotted 1px whitesmoke;
|
||||||
|
}
|
||||||
|
div.news > div.row > nav[class^="col"] > div {
|
||||||
|
padding: 1em;
|
||||||
|
background: transparent;
|
||||||
|
}
|
||||||
|
div.news > div.row > nav[class^="col"] > div > time {
|
||||||
|
font-family: 'Ubuntu', sans-serif;
|
||||||
|
display: inline-block;
|
||||||
|
margin-bottom: 0.5ex;
|
||||||
|
font-weight: 100;
|
||||||
|
font-size: smaller;
|
||||||
|
}
|
||||||
|
div.news > div.row > nav[class^="col"] > div > p > i.bi-newspaper { color: #006799 }
|
||||||
|
div.news > div.row > nav[class^="col"] > div.active > p > i.bi-newspaper { color: black; }
|
||||||
|
div.news > div.row > nav[class^="col"] > div.active {
|
||||||
|
color: black;
|
||||||
|
background: white;
|
||||||
|
background: linear-gradient(to top right, rgba(147,147,147,0.2) 15%, rgba(255,255,255,1) 50%);
|
||||||
|
margin-right: -1px;
|
||||||
|
border-radius: 10px 0 0 10px;
|
||||||
|
border-left: dotted 1px whitesmoke;
|
||||||
|
border-top: dotted 1px whitesmoke;
|
||||||
|
border-bottom: dotted 1px whitesmoke;
|
||||||
|
}
|
||||||
|
div.news > nav.row { margin: 0; }
|
||||||
|
|
||||||
/****************************
|
/****************************
|
||||||
** ОФОРМЛЕНИЕ ТЕГОВ *********
|
** ОФОРМЛЕНИЕ ТЕГОВ *********
|
||||||
****************************/
|
****************************/
|
||||||
|
|||||||
Reference in New Issue
Block a user