0.7.52
articles page
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 django.http import Http404, HttpResponse
|
||||
from django.template import loader
|
||||
from .funcs import *
|
||||
|
||||
# from django.contrib.auth.decorators import login_required
|
||||
# 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
|
||||
|
||||
|
||||
arts = ArticleModel.objects.filter(**kwargs).order_by('-createDT')
|
||||
|
||||
Dict = {
|
||||
'articles': arts
|
||||
}
|
||||
Dict = get_articles(art_kwargs=kwargs)
|
||||
|
||||
t = loader.get_template('pages/p_articles.html')
|
||||
return HttpResponse(t.render(Dict, request))
|
||||
|
||||
@@ -31,6 +31,7 @@ urlpatterns += i18n_patterns(
|
||||
path('reference_data/', include('ReferenceDataApp.js_urls')),
|
||||
|
||||
path('', include('ArticlesApp.urls_translate')),
|
||||
path('', include('ArticlesApp.js_urls')),
|
||||
|
||||
)
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
|
||||
<div class="three_pinned_news">
|
||||
{% for art in articles %}
|
||||
|
||||
{% if forloop.counter0 < 3 %}
|
||||
<div class="news_item">
|
||||
<a href="{% url "article_one" art.url %}">
|
||||
<div class="news_img"><img src="{{ MEDIA_URL }}{{ art.picture }}" /></div>
|
||||
@@ -23,6 +23,7 @@
|
||||
</div>
|
||||
</a>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
{#<div>{{ art.text|safe }}</div>#}
|
||||
{% endfor %}
|
||||
@@ -31,18 +32,20 @@
|
||||
|
||||
<div class="news_block_pagination">
|
||||
{% for art in articles %}
|
||||
<div class="news_item_pagination">
|
||||
<div class="pag_news_img"><img src="{{ MEDIA_URL }}{{ art.picture }}" /></div>
|
||||
<div class="pag_news_item_text">
|
||||
<div class="news_header">{{ art.name }}</div>
|
||||
<div class="news_description">
|
||||
{{ art.description|truncatechars:400 }}
|
||||
{# <div class="news_gradient"></div>#}
|
||||
</div>
|
||||
</div>
|
||||
<div class="clear_both"></div>
|
||||
{% if forloop.counter0 > 2 %}
|
||||
<div class="news_item_pagination">
|
||||
<div class="pag_news_img"><img src="{{ MEDIA_URL }}{{ art.picture }}" /></div>
|
||||
<div class="pag_news_item_text">
|
||||
<div class="news_header">{{ art.name }}</div>
|
||||
<div class="news_description">
|
||||
{{ art.description|truncatechars:400 }}
|
||||
{# <div class="news_gradient"></div>#}
|
||||
</div>
|
||||
</div>
|
||||
<div class="clear_both"></div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
{#<div>{{ art.text|safe }}</div>#}
|
||||
{% endfor %}
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user