0.0.2 init, blocks prepare

This commit is contained in:
SDE
2023-11-26 14:31:30 +03:00
parent 74f7bbb24b
commit 53687e240d
20 changed files with 475 additions and 33 deletions

View File

@@ -95,8 +95,8 @@ class BaseModelViewPage(BaseModel):
help_text=u'')
# icon = FileBrowseField("Image", max_length=200, directory="files/", extensions=[".jpg"], blank=True, null=True)
visible = models.BooleanField(verbose_name=_('Отображать'), default=True)
background_image_left = models.ImageField(verbose_name=_('Левая подложка'), blank=True, null=True)
background_image_right = models.ImageField(verbose_name=_('Правая подложка'), blank=True, null=True)
# background_image_left = models.ImageField(verbose_name=_('Левая подложка'), blank=True, null=True)
# background_image_right = models.ImageField(verbose_name=_('Правая подложка'), blank=True, null=True)
seo_title = models.CharField(max_length=250, verbose_name=_('Title (80 знаков)'), null=True, blank=True)

View File

@@ -1,8 +1,75 @@
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
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_Inline_WidgetForBlock(SuperInlineModelAdmin, Admin_Trans_BaseIconStackedInline):
# class Admin_Inline_WidgetForBlock(Admin_Trans_BaseIconTabularInline, SuperInlineModelAdmin):
def formfield_for_dbfield(self, db_field, request, **kwargs):
field = super(Admin_Inline_WidgetForBlock, self).formfield_for_dbfield(db_field, request, **kwargs)
return sets_for_formfield_for_dbfield(field, db_field)
# return field
model = WidgetForBlock
extra = 0
# fields = ['title', 'description', 'picture', 'bg_color', 'but_title', 'but_color', 'url']
fieldsets = [
(None, {
'classes': [],
'fields': [
('title', 'description', 'picture'),
('bg_color', ),
('but_title', 'but_color'),
('url',),
]
})
]
class Admin_StackedInline_Block(Admin_Trans_GenericBaseIconStackedInline, SuperInlineModelAdmin):
# class Admin_StackedInline_Block(Admin_Trans_GenericBaseIconStackedInline):
def formfield_for_dbfield(self, db_field, request, **kwargs):
field = super(Admin_StackedInline_Block, self).formfield_for_dbfield(db_field, request, **kwargs)
return sets_for_formfield_for_dbfield(field, db_field)
model = Block
extra = 0
fieldsets = [
(None, {
'classes': [],
'fields': [
('block_type', 'title', 'description', 'picture'),
('bg_color', ),
('but_title', 'but_color'),
('url',),
('child_in_row_count',),
]
})
]
inlines = [Admin_Inline_WidgetForBlock]
# class Admin_StaticPage(NestedModelAdmin, Admin_Trans_BaseModelViewPage):
class Admin_StaticPage(SuperModelAdmin, Admin_Trans_BaseModelViewPage):
class Admin_StaticPage(Admin_Trans_BaseModelViewPage):
fieldsets = [
(None, {
@@ -36,6 +103,8 @@ class Admin_StaticPage(Admin_Trans_BaseModelViewPage):
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
@@ -45,23 +114,11 @@ class Admin_StaticPage(Admin_Trans_BaseModelViewPage):
admin.site.register(StaticPage,Admin_StaticPage)
class Admin_Block(Admin_BaseBlock):
class Admin_Block(Admin_Trans_BaseModelViewPage):
def get_fieldsets(self, request, obj=None):
fieldsets = super(type(self), self).get_fieldsets(request, obj)
if not request.user.is_superuser and obj.name and obj.name in ('About US', 'machines', 'works'):
fieldsets[0][1]['fields'].pop(0)
fieldsets.insert(
1, ('Контент', {
'classes': ['wide'],
'fields': (
'title', 'description', 'text',
'picture',
)
})
)
return fieldsets
inlines = [Admin_StackedInline_Block]
def has_delete_permission(self, request, obj=None):
if request.user.is_superuser:

View File

@@ -0,0 +1,68 @@
# Generated by Django 4.2.7 on 2023-11-21 16:49
import colorfield.fields
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('contenttypes', '0002_remove_content_type_name'),
('GeneralApp', '0001_initial'),
]
operations = [
migrations.RemoveField(
model_name='block',
name='background_image_left',
),
migrations.RemoveField(
model_name='block',
name='background_image_right',
),
migrations.RemoveField(
model_name='staticpage',
name='background_image_left',
),
migrations.RemoveField(
model_name='staticpage',
name='background_image_right',
),
migrations.AddField(
model_name='block',
name='bg_color',
field=colorfield.fields.ColorField(default='#FFFFFF', image_field=None, max_length=25, samples=None, verbose_name='Цвет фона'),
),
migrations.AddField(
model_name='block',
name='block_type',
field=models.CharField(default='photo_n_text', max_length=100, verbose_name='Тип блока'),
),
migrations.AddField(
model_name='block',
name='but_color',
field=colorfield.fields.ColorField(default='#000000', image_field=None, max_length=25, samples=None, verbose_name='Цвет кнопки'),
),
migrations.AddField(
model_name='block',
name='but_title',
field=models.CharField(blank=True, max_length=100, null=True, verbose_name='Текст на кнопке'),
),
migrations.AddField(
model_name='block',
name='child_in_row_count',
field=models.PositiveSmallIntegerField(default=3, verbose_name='Количество дочерних элементов в строке'),
),
migrations.AddField(
model_name='block',
name='content_type',
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, to='contenttypes.contenttype'),
),
migrations.AddField(
model_name='block',
name='object_id',
field=models.PositiveIntegerField(default=0),
preserve_default=False,
),
]

View File

@@ -0,0 +1,18 @@
# Generated by Django 4.2.7 on 2023-11-21 16:51
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('GeneralApp', '0002_remove_block_background_image_left_and_more'),
]
operations = [
migrations.AlterField(
model_name='block',
name='url',
field=models.TextField(blank=True, null=True, verbose_name='URL привязанной страницы'),
),
]

View File

@@ -0,0 +1,22 @@
# Generated by Django 4.2.7 on 2023-11-22 16:15
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('GeneralApp', '0003_alter_block_url'),
]
operations = [
migrations.AlterModelOptions(
name='block',
options={'verbose_name': 'Блок на странице', 'verbose_name_plural': 'Блоки на странице'},
),
migrations.AlterField(
model_name='block',
name='block_type',
field=models.CharField(choices=[('photo_n_text', 'Фото + текст')], default='photo_n_text', max_length=100, verbose_name='Тип блока'),
),
]

View File

@@ -0,0 +1,41 @@
# Generated by Django 4.2.7 on 2023-11-24 14:36
import ckeditor_uploader.fields
import colorfield.fields
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('GeneralApp', '0004_alter_block_options_alter_block_block_type'),
]
operations = [
migrations.CreateModel(
name='WidgetForBlock',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.TextField(blank=True, help_text='Название', null=True, verbose_name='Название')),
('name_plural', models.TextField(blank=True, null=True, verbose_name='Название (множественное число)')),
('order', models.IntegerField(blank=True, null=True, verbose_name='Очередность отображения')),
('createDT', models.DateTimeField(auto_now_add=True, verbose_name='Дата и время создания')),
('modifiedDT', models.DateTimeField(blank=True, null=True, verbose_name='Дата и время последнего изменения')),
('enable', models.BooleanField(db_index=True, default=True, verbose_name='Включено')),
('json_data', models.JSONField(blank=True, default=dict, verbose_name='Дополнительные данные')),
('title', models.TextField(blank=True, null=True, verbose_name='Заголовок')),
('description', ckeditor_uploader.fields.RichTextUploadingField(blank=True, null=True, verbose_name='Краткое описание')),
('picture', models.ImageField(blank=True, null=True, upload_to='uploads/', verbose_name='Картинка')),
('url', models.TextField(blank=True, null=True, verbose_name='URL привязанной страницы')),
('bg_color', colorfield.fields.ColorField(default='#FFFFFF', image_field=None, max_length=25, samples=None, verbose_name='Цвет фона')),
('but_title', models.CharField(blank=True, max_length=100, null=True, verbose_name='Текст на кнопке')),
('but_color', colorfield.fields.ColorField(default='#000000', image_field=None, max_length=25, samples=None, verbose_name='Цвет кнопки')),
('block', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='rel_widgets_for_block', to='GeneralApp.block', verbose_name='Родительский блок')),
],
options={
'verbose_name': 'Виджет в блоке',
'verbose_name_plural': 'Виджеты в блоках',
},
),
]

View File

@@ -0,0 +1,74 @@
# Generated by Django 4.2.7 on 2023-11-24 14:47
import ckeditor_uploader.fields
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('GeneralApp', '0005_widgetforblock'),
]
operations = [
migrations.AddField(
model_name='block',
name='block_type_en',
field=models.CharField(choices=[('photo_n_text', 'Фото + текст')], default='photo_n_text', max_length=100, null=True, verbose_name='Тип блока'),
),
migrations.AddField(
model_name='block',
name='block_type_ru',
field=models.CharField(choices=[('photo_n_text', 'Фото + текст')], default='photo_n_text', max_length=100, null=True, verbose_name='Тип блока'),
),
migrations.AddField(
model_name='block',
name='but_title_en',
field=models.CharField(blank=True, max_length=100, null=True, verbose_name='Текст на кнопке'),
),
migrations.AddField(
model_name='block',
name='but_title_ru',
field=models.CharField(blank=True, max_length=100, null=True, verbose_name='Текст на кнопке'),
),
migrations.AddField(
model_name='widgetforblock',
name='but_title_en',
field=models.CharField(blank=True, max_length=100, null=True, verbose_name='Текст на кнопке'),
),
migrations.AddField(
model_name='widgetforblock',
name='but_title_ru',
field=models.CharField(blank=True, max_length=100, null=True, verbose_name='Текст на кнопке'),
),
migrations.AddField(
model_name='widgetforblock',
name='description_en',
field=ckeditor_uploader.fields.RichTextUploadingField(blank=True, null=True, verbose_name='Краткое описание'),
),
migrations.AddField(
model_name='widgetforblock',
name='description_ru',
field=ckeditor_uploader.fields.RichTextUploadingField(blank=True, null=True, verbose_name='Краткое описание'),
),
migrations.AddField(
model_name='widgetforblock',
name='name_en',
field=models.TextField(blank=True, help_text='Название', null=True, verbose_name='Название'),
),
migrations.AddField(
model_name='widgetforblock',
name='name_ru',
field=models.TextField(blank=True, help_text='Название', null=True, verbose_name='Название'),
),
migrations.AddField(
model_name='widgetforblock',
name='title_en',
field=models.TextField(blank=True, null=True, verbose_name='Заголовок'),
),
migrations.AddField(
model_name='widgetforblock',
name='title_ru',
field=models.TextField(blank=True, null=True, verbose_name='Заголовок'),
),
]

View File

@@ -3,6 +3,11 @@ from BaseModels.base_models import BaseModelViewPage, BaseModel
from django.utils.translation import gettext_lazy as _
# from ckeditor.fields import RichTextField
from ckeditor_uploader.fields import RichTextUploadingField
# from colorfield.fields import ColorField
from django.contrib.contenttypes.models import ContentType
from django.contrib.contenttypes.fields import GenericForeignKey
from django.contrib.contenttypes.fields import GenericRelation
from colorfield.fields import ColorField
class StaticPage(BaseModelViewPage):
promo_header = models.BooleanField(verbose_name='Промо-хэдер', default=False)
@@ -11,15 +16,69 @@ class StaticPage(BaseModelViewPage):
verbose_name = _('Статическая страница')
verbose_name_plural = _('Статические страницы')
block_type_choices = (
('photo_n_text', _('Фото + текст')),
('photo150_n_title', _('Фото 150x150 + заголовок')),
('slider', _('Галерея слайдов')),
)
class Block(BaseModelViewPage):
content_type = models.ForeignKey(ContentType, on_delete=models.SET_NULL, null=True)
object_id = models.PositiveIntegerField()
content_object = GenericForeignKey('content_type', 'object_id')
block_type = models.CharField(max_length=100, choices=block_type_choices, verbose_name=_('Тип блока'), default='photo_n_text')
url = models.TextField(verbose_name=_('URL привязанной страницы'), null=True, blank=True)
bg_color = ColorField(verbose_name=_('Цвет фона'), default='#FFFFFF')
but_title = models.CharField(max_length=100, verbose_name=_('Текст на кнопке'), null=True, blank=True)
but_color = ColorField(verbose_name=_('Цвет кнопки'), default='#000000')
child_in_row_count = models.PositiveSmallIntegerField(
verbose_name=_('Количество дочерних элементов в строке'), default=3)
class Meta:
verbose_name = _('Блок на странице')
verbose_name_plural = _('Блоки на страницах')
verbose_name_plural = _('Блоки на странице')
class WidgetForBlock(BaseModel):
block = models.ForeignKey(
Block, verbose_name=_('Родительский блок'), on_delete=models.CASCADE,
related_name='rel_widgets_for_block'
)
title = models.TextField(verbose_name=_('Заголовок'), null=True, blank=True)
description = RichTextUploadingField(verbose_name=_('Краткое описание'), null=True, blank=True)
picture = models.ImageField(upload_to='uploads/', verbose_name=_('Картинка'), null=True, blank=True)
# block_type = models.CharField(max_length=100, choices=block_type_choices, verbose_name=_('Тип блока'), default='photo_n_text')
url = models.TextField(verbose_name=_('URL привязанной страницы'), null=True, blank=True)
bg_color = ColorField(verbose_name=_('Цвет фона'), default='#FFFFFF')
but_title = models.CharField(max_length=100, verbose_name=_('Текст на кнопке'), null=True, blank=True)
but_color = ColorField(verbose_name=_('Цвет кнопки'), default='#000000')
class Meta:
verbose_name = _('Виджет в блоке')
verbose_name_plural = _('Виджеты в блоке')
class Option(BaseModel):
opt_type = models.CharField(max_length=250, verbose_name='Тип', blank=True, null=True)
prefix = models.CharField(max_length=250, verbose_name='Префикс', blank=True, null=True)
value = models.CharField(max_length=250, verbose_name='Значение')
opt_type = models.CharField(max_length=250, verbose_name=_('Тип'), blank=True, null=True)
prefix = models.CharField(max_length=250, verbose_name=_('Префикс'), blank=True, null=True)
value = models.CharField(max_length=250, verbose_name=_('Значение'))
picture = models.ImageField(upload_to='uploads/', verbose_name=_('Миниатюра'), null=True, blank=True,
help_text=u'')
@@ -29,15 +88,12 @@ class Option(BaseModel):
class FAQitem(BaseModel):
from django.contrib.contenttypes.models import ContentType
from django.contrib.contenttypes.fields import GenericForeignKey
content_type = models.ForeignKey(ContentType, on_delete=models.SET_NULL, null=True)
object_id = models.PositiveIntegerField()
content_object = GenericForeignKey('content_type', 'object_id')
question = models.TextField(verbose_name='Вопрос')
answer = RichTextUploadingField(verbose_name='Ответ')
question = models.TextField(verbose_name=_('Вопрос'))
answer = RichTextUploadingField(verbose_name=_('Ответ'))
def __str__(self):
if self.question:

View File

@@ -10,11 +10,19 @@ translator.register(StaticPage, StaticPage_TranslationOptions)
class Block_TranslationOptions(TranslationOptions):
fields = (
'name', 'description', 'text', 'title', 'FAQ_title'
'name', 'description', 'text', 'title', 'FAQ_title', 'but_title'
)
translator.register(Block, Block_TranslationOptions)
class WidgetForBlock_TranslationOptions(TranslationOptions):
fields = (
'name', 'description', 'title', 'but_title'
)
translator.register(WidgetForBlock, WidgetForBlock_TranslationOptions)
class FAQitem_TranslationOptions(TranslationOptions):
fields = (
'name', 'question', 'answer'

0
ServicesApp/__init__.py Normal file
View File

3
ServicesApp/admin.py Normal file
View File

@@ -0,0 +1,3 @@
from django.contrib import admin
# Register your models here.

6
ServicesApp/apps.py Normal file
View File

@@ -0,0 +1,6 @@
from django.apps import AppConfig
class ServicesappConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'ServicesApp'

View File

24
ServicesApp/models.py Normal file
View File

@@ -0,0 +1,24 @@
from django.db import models
from BaseModels.base_models import *
from django.utils.translation import gettext_lazy as _
class Section(BaseModelViewPage):
class Meta:
verbose_name = _('Раздел сайта')
verbose_name_plural = _('Разделы сайта')
class Service(BaseModelViewPage):
section = models.ForeignKey(
Section, verbose_name=_('Раздел'),
on_delete=models.SET_NULL, related_name='rel_services_for_section',
null=True, blank=True
)
parent_service = models.ForeignKey(
'Service', verbose_name=_('Родитель'),
on_delete=models.SET_NULL, related_name='rel_children_for_service',
null=True, blank=True
)
class Meta:
verbose_name = _('Услуга')
verbose_name_plural = _('Услуги')

3
ServicesApp/tests.py Normal file
View File

@@ -0,0 +1,3 @@
from django.test import TestCase
# Create your tests here.

3
ServicesApp/views.py Normal file
View File

@@ -0,0 +1,3 @@
from django.shortcuts import render
# Create your views here.

Binary file not shown.

View File

@@ -31,7 +31,11 @@ ALLOWED_HOSTS = []
# Application definition
INSTALLED_APPS = [
'colorfield',
'modeltranslation',
"admin_interface",
'super_inlines',
'django.contrib.admin',
'django.contrib.auth',
@@ -41,7 +45,7 @@ INSTALLED_APPS = [
'django.contrib.staticfiles',
'django.contrib.humanize',
'colorfield',
# 'nested_admin',
'ckeditor',
'ckeditor_uploader',

View File

@@ -8,16 +8,16 @@ urlpatterns = [
# path('admin/', admin.site.urls),
path('ckeditor/', include('ckeditor_uploader.urls')),
path('i18n/', include('django.conf.urls.i18n')),
# path('_nested_admin/', include('nested_admin.urls')),
]
from django.conf.urls.i18n import i18n_patterns
urlpatterns += i18n_patterns(
path('admin/', admin.site.urls),
path('', include('GeneralApp.urls')),
)
urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT) + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

View File

@@ -1,4 +1,9 @@
from BaseModels.admin_utils import Admin_GenericBaseIconStackedInline, Admin_BaseIconModel
from modeltranslation.admin import (TranslationAdmin,
TranslationGenericStackedInline,
TranslationGenericTabularInline,
TranslationTabularInline,
TranslationStackedInline)
from copy import deepcopy
class AdminStacked_FAQitem(Admin_GenericBaseIconStackedInline):
@@ -98,7 +103,7 @@ class Admin_BaseModelViewPage(Admin_BaseIconModel):
from modeltranslation.admin import TranslationAdmin
class AdminTranslationBase(TranslationAdmin):
# def formfield_for_dbfield(self, db_field, **kwargs):
@@ -127,3 +132,53 @@ class Admin_Trans_BaseModel(Admin_BaseModel, AdminTranslationBase):
class Admin_Trans_BaseModelViewPage(Admin_BaseModelViewPage, AdminTranslationBase):
pass
class Admin_Trans_GenericBaseIconStackedInline(TranslationGenericStackedInline):
class Media:
js = (
'modeltranslation/js/force_jquery.js',
'http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js',
'http://ajax.googleapis.com/ajax/libs/jqueryui/1.10.2/jquery-ui.min.js',
'modeltranslation/js/tabbed_translation_fields.js',
)
css = {
'screen': ('modeltranslation/css/tabbed_translation_fields.css',),
}
class Admin_Trans_GenericBaseIconTabularInline(TranslationGenericTabularInline):
class Media:
js = (
'modeltranslation/js/force_jquery.js',
'http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js',
'http://ajax.googleapis.com/ajax/libs/jqueryui/1.10.2/jquery-ui.min.js',
'modeltranslation/js/tabbed_translation_fields.js',
)
css = {
'screen': ('modeltranslation/css/tabbed_translation_fields.css',),
}
class Admin_Trans_BaseIconTabularInline(TranslationTabularInline):
class Media:
js = (
'modeltranslation/js/force_jquery.js',
'http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js',
'http://ajax.googleapis.com/ajax/libs/jqueryui/1.10.2/jquery-ui.min.js',
'modeltranslation/js/tabbed_translation_fields.js',
)
css = {
'screen': ('modeltranslation/css/tabbed_translation_fields.css',),
}
class Admin_Trans_BaseIconStackedInline(TranslationStackedInline):
class Media:
js = (
'modeltranslation/js/force_jquery.js',
'http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js',
'http://ajax.googleapis.com/ajax/libs/jqueryui/1.10.2/jquery-ui.min.js',
'modeltranslation/js/tabbed_translation_fields.js',
)
css = {
'screen': ('modeltranslation/css/tabbed_translation_fields.css',),
}