146 lines
3.9 KiB
Python
146 lines
3.9 KiB
Python
# -*- coding: utf8 -*-
|
|
|
|
from .models import *
|
|
|
|
from datetime import datetime, date
|
|
from django.http import Http404, HttpResponse
|
|
from django.template import loader
|
|
|
|
# from django.contrib.auth.decorators import login_required
|
|
# from BaseModels.search_optimization.ld_json.ld_article_news import get_ld_article_news
|
|
# from django.contrib.sites.shortcuts import get_current_site
|
|
|
|
|
|
|
|
def get_flat_pages_links_Dict(site):
|
|
|
|
flat_pages_links = UserPageModel.objects.filter(
|
|
url__in=('about-truenergy', 'for-partners', 'contacts'),
|
|
sites=site
|
|
).values_list('url', flat=True)
|
|
|
|
return {'flat_pages_links': flat_pages_links}
|
|
|
|
|
|
|
|
def get_article_breadcrumbs(request, art):
|
|
# print('get_article_breadcrumbs')
|
|
half_count = art.articlesCountInBlock / 2
|
|
|
|
art_List = ArticleModel.objects.filter(enable=True, article_DT__gte=art.article_DT).order_by(
|
|
'article_DT')[:half_count]
|
|
artListDown = ArticleModel.objects.filter(enable=True, article_DT__lt=art.article_DT).order_by(
|
|
'-article_DT')[:art.articlesCountInBlock-len(art_List)]
|
|
if len(artListDown)<half_count:
|
|
art_List = ArticleModel.objects.filter(enable=True, article_DT__gte=art.article_DT).order_by(
|
|
'article_DT')[:art.articlesCountInBlock-len(artListDown)]
|
|
|
|
art_List = list(art_List)
|
|
art_List.reverse()
|
|
artlist = art_List + list(artListDown)
|
|
# print('artlist',artlist)
|
|
return artlist
|
|
|
|
|
|
def get_user_pages_breadcrumbs(request, art):
|
|
from ArticlesApp.models import UserPageModel
|
|
# print('get_user_pages_breadcrumbs')
|
|
half_count = art.articlesCountInBlock / 2
|
|
|
|
art_List = UserPageModel.objects.filter(enable=True, article_DT__gte=art.article_DT).order_by(
|
|
'article_DT')[:half_count]
|
|
artListDown = UserPageModel.objects.filter(enable=True, article_DT__lt=art.article_DT).order_by(
|
|
'-article_DT')[:art.articlesCountInBlock-len(art_List)]
|
|
if len(artListDown)<half_count:
|
|
art_List = UserPageModel.objects.filter(enable=True, article_DT__gte=art.article_DT).order_by(
|
|
'article_DT')[:art.articlesCountInBlock-len(artListDown)]
|
|
|
|
art_List = list(art_List)
|
|
art_List.reverse()
|
|
artlist = art_List + list(artListDown)
|
|
# print('artlist',artlist)
|
|
return artlist
|
|
|
|
|
|
# @login_required(login_url='/admin/')
|
|
def ArticlesPageView(request, year=None):
|
|
|
|
kwargs = {}
|
|
|
|
if year:
|
|
try:
|
|
year = int(year)
|
|
kwargs.update({'createDT__year': year})
|
|
except:
|
|
raise Http404
|
|
|
|
|
|
arts = ArticleModel.objects.filter(**kwargs)
|
|
|
|
Dict = {
|
|
'articles': arts
|
|
}
|
|
|
|
t = loader.get_template('pages/p_articles.html')
|
|
return HttpResponse(t.render(Dict, request))
|
|
|
|
|
|
|
|
# @login_required(login_url='/admin/')
|
|
def UserPageView(request, page_url):
|
|
|
|
|
|
kwargs = {
|
|
'url': page_url
|
|
}
|
|
|
|
try:
|
|
art = UserPageModel.objects.get(**kwargs)
|
|
except UserPageModel.DoesNotExist:
|
|
raise Http404
|
|
|
|
# service = ServiceModel.objects.filter(enable=True, artDevs=art)[0]
|
|
|
|
# article_breadcrumbs = get_user_pages_breadcrumbs(request,art)
|
|
# print('article_breadcrumbs',article_breadcrumbs)
|
|
|
|
Dict = {
|
|
'art' : art,
|
|
'user_page' : True,
|
|
# 'service' : service,
|
|
# 'article_breadcrumbs' : article_breadcrumbs
|
|
}
|
|
|
|
|
|
|
|
t = loader.get_template('pages/p_article.html')
|
|
return HttpResponse(t.render(Dict, request))
|
|
|
|
|
|
|
|
# @login_required(login_url='/admin/')
|
|
def ArticlesOnePageView(request, art_url):
|
|
|
|
kwargs = {
|
|
'url': art_url
|
|
}
|
|
|
|
try:
|
|
art = ArticleModel.objects.get(**kwargs)
|
|
except ArticleModel.DoesNotExist:
|
|
raise Http404
|
|
|
|
|
|
# article_breadcrumbs = get_article_breadcrumbs(request, art)
|
|
# print('article_breadcrumbs',article_breadcrumbs)
|
|
|
|
Dict = {
|
|
'art' : art,
|
|
# 'article_breadcrumbs' : article_breadcrumbs
|
|
}
|
|
|
|
|
|
|
|
t = loader.get_template('pages/p_user_page.html')
|
|
return HttpResponse(t.render(Dict, request))
|