From 590942b1c2e9893ffe92d5d94e7fb070200b5f77 Mon Sep 17 00:00:00 2001 From: SDE Date: Sun, 26 Nov 2023 16:55:19 +0300 Subject: [PATCH] 0.0.8 Services --- ServicesApp/admin.py | 50 +++++++++++++++++++ ServicesApp/funcs.py | 2 +- ServicesApp/js_urls.py | 2 +- ServicesApp/js_views.py | 17 ++++--- .../pages/content/c_projectiing_section.html | 10 ++++ 5 files changed, 72 insertions(+), 9 deletions(-) create mode 100644 templates/pages/content/c_projectiing_section.html diff --git a/ServicesApp/admin.py b/ServicesApp/admin.py index 6fce285..d6b63ed 100644 --- a/ServicesApp/admin.py +++ b/ServicesApp/admin.py @@ -44,6 +44,8 @@ class Admin_Section(SuperModelAdmin, Admin_Trans_BaseModelViewPage): 'order', 'modifiedDT', 'createDT' ] + prepopulated_fields = {"url": ("name_en",)} + list_display_links = ['id'] list_editable = ['order'] @@ -64,3 +66,51 @@ admin.site.register(Section,Admin_Section) +class Admin_Service(SuperModelAdmin, Admin_Trans_BaseModelViewPage): + + + fieldsets = [ + (None, { + 'classes': ['wide'], + 'fields': ('name', + 'url', + 'title', 'description', 'text', + 'picture', + 'order', + ) + }), + ('SEO', { + 'classes': ['wide', 'collapse'], + 'fields': ( + 'seo_title', 'seo_description', 'seo_keywords', 'seo_text', + ) + }), + ] + + + list_display = [ + 'id', + 'name', 'url', 'title', + 'order', 'modifiedDT', 'createDT' + ] + + prepopulated_fields = {"url": ("name",)} + + list_display_links = ['id'] + list_editable = ['order'] + + list_filter = ['modifiedDT', 'createDT'] + search_fields = ['name', 'title'] + # filter_horizontal = ['options'] + + inlines = [Admin_StackedInline_Block] + + def has_delete_permission(self, request, obj=None): + if request.user.is_superuser: + return True + + if obj.url in ('main', 'spec_technics', 'works'): + return False + +admin.site.register(Service, Admin_Service) + diff --git a/ServicesApp/funcs.py b/ServicesApp/funcs.py index f054e88..7a3ba9c 100644 --- a/ServicesApp/funcs.py +++ b/ServicesApp/funcs.py @@ -2,5 +2,5 @@ from .models import * def get_sections(): - sections = Section.objects.filter(enable=True) + sections = Section.objects.filter(enable=True).order_by('order') return sections \ No newline at end of file diff --git a/ServicesApp/js_urls.py b/ServicesApp/js_urls.py index ce76406..c4c3606 100644 --- a/ServicesApp/js_urls.py +++ b/ServicesApp/js_urls.py @@ -5,7 +5,7 @@ from django.conf import settings from .js_views import * urlpatterns = [ - path('get_content_for_section', get_content_for_section_ajax, name='main'), + path('get_content_for_section', get_content_for_section_ajax, name='get_content_for_section_ajax'), # path('page//', StaticPageView, name='static_page'), # path('test_code', test_code, name='test_code'), ] \ No newline at end of file diff --git a/ServicesApp/js_views.py b/ServicesApp/js_views.py index 95cac09..c1d49d6 100644 --- a/ServicesApp/js_views.py +++ b/ServicesApp/js_views.py @@ -16,6 +16,7 @@ from django.urls import reverse from .funcs import * def get_content_for_section_ajax(request): + if request.method != 'POST': raise Http404 @@ -26,6 +27,9 @@ def get_content_for_section_ajax(request): if not data and request.body: data = json.loads(request.body) + if 'screen_width' in data and data['screen_width']: + request.session['screen_width'] = data['screen_width'] + if not 'section_url' in data or not data['section_url']: msg = _("Не найден section_url в data") err_Dict = { @@ -35,22 +39,21 @@ def get_content_for_section_ajax(request): section = Section.objects.get(url=data['section_url']) + Dict = { + 'section': section + } - html = render_to_string('blocks/b_search_routes.html', routes_Dict, request=request) + html = render_to_string('pages/content/c_projectiing_section.html', Dict, request=request) res_Dict = { 'html': html, - 'last_block': routes_Dict['last_block'] - # 'form': RouteForm(initial=data) } return JsonResponse(res_Dict) except Exception as e: - + msg = f' get_content_for_section_ajax ошибка в запросе = {str(e)}' errors_Dict = { - 'errors': { - 'all__': f'ошибка в запросе = {str(e)}' - } + 'errors': msg } return JsonResponse(errors_Dict, status=400) diff --git a/templates/pages/content/c_projectiing_section.html b/templates/pages/content/c_projectiing_section.html new file mode 100644 index 0000000..566549b --- /dev/null +++ b/templates/pages/content/c_projectiing_section.html @@ -0,0 +1,10 @@ + + + + + Title + + + + + \ No newline at end of file