0.0.5 init, rm db

This commit is contained in:
SDE
2023-11-26 16:19:21 +03:00
parent bfac39ab49
commit 2fe32c496b
9 changed files with 159 additions and 10 deletions

View File

@@ -1,3 +1,66 @@
from sets.admin import *
from .models import *
from django.contrib import admin
from django.forms import widgets
# from nested_inline.admin import NestedStackedInline, NestedTabularInline, NestedModelAdmin, NestedInline
from super_inlines.admin import SuperInlineModelAdmin, SuperModelAdmin
from GeneralApp.admin import Admin_StackedInline_Block
def sets_for_formfield_for_dbfield(field, db_field):
if db_field.name == 'url' or db_field.name == 'name' or db_field.name == 'title' or db_field.name == 'name_plural':
field.widget = widgets.TextInput(attrs={'style': 'width: 30%; height: 20px;'})
if db_field.name == 'description':
field.widget = widgets.Textarea(attrs={'style': 'width: 30%; height: 100px;'})
return field
# class Admin_StaticPage(NestedModelAdmin, Admin_Trans_BaseModelViewPage):
class Admin_Section(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'
]
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(Section,Admin_Section)
# Register your models here.

6
ServicesApp/funcs.py Normal file
View File

@@ -0,0 +1,6 @@
from .models import *
def get_sections():
sections = Section.objects.filter(enable=True)
return sections

11
ServicesApp/js_urls.py Normal file
View File

@@ -0,0 +1,11 @@
from django.contrib import admin
from django.urls import path, include
from django.conf.urls.static import static
from django.conf import settings
from .js_views import *
urlpatterns = [
path('get_content_for_section', get_content_for_section_ajax, name='main'),
# path('page/<str:url>/', StaticPageView, name='static_page'),
# path('test_code', test_code, name='test_code'),
]

56
ServicesApp/js_views.py Normal file
View File

@@ -0,0 +1,56 @@
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 .funcs import *
def get_content_for_section_ajax(request):
if request.method != 'POST':
raise Http404
try:
data = request.POST.dict()
if not data and request.body:
data = json.loads(request.body)
if not 'section_url' in data or not data['section_url']:
msg = _("Не найден section_url в data")
err_Dict = {
'error': msg
}
return JsonResponse(err_Dict, status=400)
section = Section.objects.get(url=data['section_url'])
html = render_to_string('blocks/b_search_routes.html', routes_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:
errors_Dict = {
'errors': {
'all__': f'ошибка в запросе = {str(e)}'
}
}
return JsonResponse(errors_Dict, status=400)

11
ServicesApp/urls.py Normal file
View File

@@ -0,0 +1,11 @@
from django.contrib import admin
from django.urls import path, include
from django.conf.urls.static import static
from django.conf import settings
from .views import *
urlpatterns = [
# path('', MainPage, name='main'),
# path('page/<str:url>/', StaticPageView, name='static_page'),
# path('test_code', test_code, name='test_code'),
]