Merge pull request #3 from Mikan-DS/feature/NP-2

Feature/np 2
This commit is contained in:
Mikan
2024-10-02 21:53:19 +03:00
committed by GitHub
7 changed files with 74 additions and 10 deletions

View File

@@ -10,6 +10,8 @@ For the full list of settings and their values, see
https://docs.djangoproject.com/en/4.2/ref/settings/
"""
import os
from pathlib import Path
from bd_config import default_database
@@ -25,7 +27,7 @@ BASE_DIR = Path(__file__).resolve().parent.parent
SECRET_KEY = 'django-insecure-+l_9olvm8c90$1y39)ukodf4_zdt^4vhdf+n+b=^i9tyl$wki%'
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = False
DEBUG = bool(os.environ.get('LOCALDEV', False))
ALLOWED_HOSTS = [
"vnovelplus.temp.swtest.ru",

View File

@@ -1,16 +1,24 @@
from django.contrib import admin
from common.models import ItemData, ContextButtonType
from common.models import ItemData, ContextButtonType, ItemDataContextButton
from common.signals import add_signals
# Register your models here.
class ItemDataButtonsInline(admin.TabularInline):
model = ItemDataContextButton
verbose_name = 'Контекстная кнопка информационного объекта'
verbose_name_plural = 'Контекстные кнопки информационных объектов'
extra = 1
class ItemDataAdmin(admin.ModelAdmin):
list_display = ('title', "author", 'status', 'created_at', 'updated_at')
search_fields = ('title', 'author')
list_filter = ('collection', 'status')
ordering = ('-created_at', '-updated_at', 'id')
inlines = [ItemDataButtonsInline]
admin.site.register(ItemData, ItemDataAdmin)

View File

@@ -0,0 +1,28 @@
# Generated by Django 4.2.16 on 2024-10-02 17:58
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('common', '0005_contextbuttontype'),
]
operations = [
migrations.CreateModel(
name='ItemDataContextButton',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('url', models.URLField(max_length=255, verbose_name='Ссылка')),
('button_type', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='item_data_buttons', to='common.contextbuttontype', verbose_name='Тип кнопки')),
('item_data', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='context_buttons', to='common.itemdata', verbose_name='Информационный объект')),
],
options={
'verbose_name': 'Контекстная кнопка информационного объекта',
'verbose_name_plural': 'Контекстные кнопки информационных объектов',
'unique_together': {('item_data', 'button_type')},
},
),
]

View File

@@ -82,14 +82,17 @@ class ItemData(models.Model):
@property
def item_dict(self) -> typing.Dict[str, typing.Union[str, int, float, None]]:
context_buttons = [{"name": cb.button_type.verbose, "url": cb.url} for cb in self.context_buttons.all()]
return {
"image": self.image.url,
"title": self.title,
"shortDescription": self.short_description,
"description": self.description,
"contextButtons": context_buttons
}
@property
def card_dict(self) -> typing.Dict[str, typing.Union[str, int, float, None]]:
return {
@@ -103,7 +106,7 @@ class ItemData(models.Model):
card = self.card_dict
card.update({
"status": self.status.verbose,
"updatedAt": self.updated_at.timestamp()//.001,
"updatedAt": self.updated_at.timestamp() // .001,
"shortDescription": self.short_description
})
@@ -121,3 +124,26 @@ class ContextButtonType(models.Model):
ordering = ('verbose',)
verbose_name = 'Тип контекстной кнопки'
verbose_name_plural = 'Типы контекстных кнопок'
class ItemDataContextButton(models.Model):
item_data = models.ForeignKey(ItemData,
on_delete=models.CASCADE,
related_name='context_buttons',
verbose_name='Информационный объект'
)
button_type = models.ForeignKey(
'common.ContextButtonType',
on_delete=models.CASCADE,
related_name='item_data_buttons',
verbose_name='Тип кнопки'
)
url = models.URLField(max_length=255, verbose_name='Ссылка')
class Meta:
verbose_name = 'Контекстная кнопка информационного объекта'
verbose_name_plural = 'Контекстные кнопки информационных объектов'
unique_together = ('item_data', 'button_type')
def __str__(self):
return f'{self.button_type.verbose} = {self.url}'

View File

@@ -11,7 +11,7 @@
<meta name="yandex-verification" content="e38d4768470c4ba2" />
<link rel="icon" href="{% static '/misc/icon.ico' %}">
<meta name="viewport" content="width=device-width, initial-scale=1">
<script defer="defer" src="{% static 'frontend/js/main.b0f7af15.js' %}"></script>
<script defer="defer" src="{% static 'frontend/js/main.a4f12760.js' %}"></script>
<link rel="stylesheet" href="{% static 'frontend/css/main.bc62eaf9.css' %}">
</head>
<body>