Merge remote-tracking branch 'origin/main'
This commit is contained in:
35
ArticlesApp/funcs.py
Normal file
35
ArticlesApp/funcs.py
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
from .models import *
|
||||||
|
|
||||||
|
|
||||||
|
def get_articles(art_kwargs, request_Data=None, from_el=None, to_el=None):
|
||||||
|
|
||||||
|
if request_Data:
|
||||||
|
if not from_el and 'from_el' in request_Data:
|
||||||
|
from_el = request_Data['from_el']
|
||||||
|
|
||||||
|
if not to_el and 'to_el' in request_Data:
|
||||||
|
to_el = request_Data['to_el']
|
||||||
|
|
||||||
|
arts = ArticleModel.objects.filter(**art_kwargs).order_by('-createDT')
|
||||||
|
el_count = arts.count()
|
||||||
|
|
||||||
|
if from_el and to_el:
|
||||||
|
arts = arts[from_el:to_el]
|
||||||
|
elif from_el:
|
||||||
|
arts = arts[from_el:]
|
||||||
|
elif to_el:
|
||||||
|
arts = arts[:to_el]
|
||||||
|
else:
|
||||||
|
to_el = 3
|
||||||
|
arts = arts[:3]
|
||||||
|
|
||||||
|
last_block = False
|
||||||
|
if not to_el or to_el >= el_count:
|
||||||
|
last_block = True
|
||||||
|
|
||||||
|
Dict = {
|
||||||
|
'articles': arts,
|
||||||
|
'last_block': last_block
|
||||||
|
}
|
||||||
|
|
||||||
|
return Dict
|
||||||
10
ArticlesApp/js_urls.py
Normal file
10
ArticlesApp/js_urls.py
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
# coding=utf-8
|
||||||
|
from django.urls import path
|
||||||
|
# from AuthApp.js_views import *
|
||||||
|
# from AuthApp.import_funcs import *
|
||||||
|
from .js_views import *
|
||||||
|
|
||||||
|
urlpatterns = [
|
||||||
|
path('get_articles_block/', get_articles_block_ajax, name='get_articles_block_ajax'),
|
||||||
|
|
||||||
|
]
|
||||||
53
ArticlesApp/js_views.py
Normal file
53
ArticlesApp/js_views.py
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
import json
|
||||||
|
|
||||||
|
from django.shortcuts import render
|
||||||
|
|
||||||
|
from uuid import uuid1
|
||||||
|
from .models import *
|
||||||
|
from django.contrib import auth
|
||||||
|
from django.http import HttpResponse, Http404, JsonResponse
|
||||||
|
from django.template import loader, RequestContext
|
||||||
|
from django.contrib.auth.decorators import login_required
|
||||||
|
from BaseModels.mailSender import techSendMail
|
||||||
|
from django.utils.translation import gettext as _
|
||||||
|
from datetime import datetime
|
||||||
|
from django.template.loader import render_to_string
|
||||||
|
from django.urls import reverse
|
||||||
|
# from .forms import *
|
||||||
|
from .funcs import *
|
||||||
|
|
||||||
|
def get_articles_block_ajax(request):
|
||||||
|
|
||||||
|
if request.method != 'POST':
|
||||||
|
raise Http404
|
||||||
|
|
||||||
|
try:
|
||||||
|
|
||||||
|
data = request.POST.dict()
|
||||||
|
if not data and request.body:
|
||||||
|
data = json.loads(request.body)
|
||||||
|
|
||||||
|
art_kwargs = {}
|
||||||
|
|
||||||
|
Dict = get_articles(art_kwargs=art_kwargs, request_Data=data)
|
||||||
|
if 'errors' in Dict:
|
||||||
|
return JsonResponse(Dict, status=400)
|
||||||
|
|
||||||
|
html = render_to_string('blocks/b_news_elements.html', Dict, request=request)
|
||||||
|
|
||||||
|
res_Dict = {
|
||||||
|
'html': html,
|
||||||
|
'last_block': Dict['last_block']
|
||||||
|
# 'form': RouteForm(initial=data)
|
||||||
|
}
|
||||||
|
|
||||||
|
return JsonResponse(res_Dict)
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
|
||||||
|
errors_Dict = {
|
||||||
|
'errors': {
|
||||||
|
'all__': f'ошибка в запросе = {str(e)}'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return JsonResponse(errors_Dict, status=400)
|
||||||
@@ -5,6 +5,7 @@ from .models import *
|
|||||||
from datetime import datetime, date
|
from datetime import datetime, date
|
||||||
from django.http import Http404, HttpResponse
|
from django.http import Http404, HttpResponse
|
||||||
from django.template import loader
|
from django.template import loader
|
||||||
|
from .funcs import *
|
||||||
|
|
||||||
# from django.contrib.auth.decorators import login_required
|
# from django.contrib.auth.decorators import login_required
|
||||||
# from BaseModels.search_optimization.ld_json.ld_article_news import get_ld_article_news
|
# from BaseModels.search_optimization.ld_json.ld_article_news import get_ld_article_news
|
||||||
@@ -76,11 +77,7 @@ def ArticlesPageView(request, year=None):
|
|||||||
raise Http404
|
raise Http404
|
||||||
|
|
||||||
|
|
||||||
arts = ArticleModel.objects.filter(**kwargs).order_by('-createDT')
|
Dict = get_articles(art_kwargs=kwargs)
|
||||||
|
|
||||||
Dict = {
|
|
||||||
'articles': arts
|
|
||||||
}
|
|
||||||
|
|
||||||
t = loader.get_template('pages/p_articles.html')
|
t = loader.get_template('pages/p_articles.html')
|
||||||
return HttpResponse(t.render(Dict, request))
|
return HttpResponse(t.render(Dict, request))
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ urlpatterns += i18n_patterns(
|
|||||||
path('reference_data/', include('ReferenceDataApp.js_urls')),
|
path('reference_data/', include('ReferenceDataApp.js_urls')),
|
||||||
|
|
||||||
path('', include('ArticlesApp.urls_translate')),
|
path('', include('ArticlesApp.urls_translate')),
|
||||||
|
path('', include('ArticlesApp.js_urls')),
|
||||||
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -14,7 +14,7 @@
|
|||||||
|
|
||||||
<div class="three_pinned_news">
|
<div class="three_pinned_news">
|
||||||
{% for art in articles %}
|
{% for art in articles %}
|
||||||
|
{% if forloop.counter0 < 3 %}
|
||||||
<div class="news_item">
|
<div class="news_item">
|
||||||
<a href="{% url "article_one" art.url %}">
|
<a href="{% url "article_one" art.url %}">
|
||||||
<div class="news_img"><img src="{{ MEDIA_URL }}{{ art.picture }}" /></div>
|
<div class="news_img"><img src="{{ MEDIA_URL }}{{ art.picture }}" /></div>
|
||||||
@@ -25,6 +25,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
{#<div>{{ art.text|safe }}</div>#}
|
{#<div>{{ art.text|safe }}</div>#}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|||||||
Reference in New Issue
Block a user