@@ -1,6 +1,6 @@
|
||||
from django.contrib import admin
|
||||
|
||||
from common.models import ItemData
|
||||
from common.models import ItemData, ContextButtonType
|
||||
from common.signals import add_signals
|
||||
|
||||
|
||||
@@ -8,10 +8,19 @@ from common.signals import add_signals
|
||||
class ItemDataAdmin(admin.ModelAdmin):
|
||||
list_display = ('title', "author", 'status', 'created_at', 'updated_at')
|
||||
search_fields = ('title', 'author')
|
||||
list_filter = ('collection', 'status', 'author')
|
||||
list_filter = ('collection', 'status')
|
||||
ordering = ('-created_at', '-updated_at', 'id')
|
||||
|
||||
|
||||
admin.site.register(ItemData, ItemDataAdmin)
|
||||
|
||||
|
||||
class ContextButtonTypeAdmin(admin.ModelAdmin):
|
||||
list_display = ('verbose', 'name')
|
||||
search_fields = ('verbose', 'name')
|
||||
ordering = ('verbose',)
|
||||
|
||||
|
||||
admin.site.register(ContextButtonType, ContextButtonTypeAdmin)
|
||||
|
||||
add_signals()
|
||||
|
||||
25
common/migrations/0005_contextbuttontype.py
Normal file
25
common/migrations/0005_contextbuttontype.py
Normal file
@@ -0,0 +1,25 @@
|
||||
# Generated by Django 4.2.16 on 2024-10-01 14:39
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('common', '0004_alter_itemdatacollection_name_and_more'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='ContextButtonType',
|
||||
fields=[
|
||||
('name', models.CharField(max_length=20, primary_key=True, serialize=False)),
|
||||
('verbose', models.CharField(max_length=20)),
|
||||
],
|
||||
options={
|
||||
'verbose_name': 'Тип контекстной кнопки',
|
||||
'verbose_name_plural': 'Типы контекстных кнопок',
|
||||
'ordering': ('verbose',),
|
||||
},
|
||||
),
|
||||
]
|
||||
@@ -109,3 +109,15 @@ class ItemData(models.Model):
|
||||
|
||||
return card
|
||||
|
||||
|
||||
class ContextButtonType(models.Model):
|
||||
name = models.CharField(max_length=20, primary_key=True)
|
||||
verbose = models.CharField(max_length=20)
|
||||
|
||||
def __str__(self):
|
||||
return self.verbose
|
||||
|
||||
class Meta:
|
||||
ordering = ('verbose',)
|
||||
verbose_name = 'Тип контекстной кнопки'
|
||||
verbose_name_plural = 'Типы контекстных кнопок'
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
from django.db.models.signals import post_migrate, post_delete
|
||||
from django.dispatch import receiver
|
||||
|
||||
from common.models import ItemDataCollection, ItemDataStatus
|
||||
from common.models import ItemDataCollection, ItemDataStatus, ContextButtonType
|
||||
|
||||
|
||||
@receiver(post_migrate)
|
||||
@@ -39,6 +39,24 @@ def create_status_types(sender, **kwargs):
|
||||
except Exception as e:
|
||||
print(f"[-] {repr(e)} - {collection_name} {collection_verbose}")
|
||||
|
||||
@receiver(post_migrate)
|
||||
def create_context_button_types(sender, **kwargs):
|
||||
default_context_button_types = (
|
||||
("telegram", "Телеграм"),
|
||||
("vk", "Вконтакте"),
|
||||
("email", "E-MAIL"),
|
||||
("steam", "Страница в стиме"),
|
||||
("itchio", "Страница в itch.io"),
|
||||
)
|
||||
|
||||
for name, verbose in default_context_button_types:
|
||||
try:
|
||||
ContextButtonType.objects.get_or_create(name=name, verbose=verbose)
|
||||
except Exception as e:
|
||||
print(f"[-] {repr(e)} - {name} {verbose}")
|
||||
|
||||
|
||||
|
||||
|
||||
def add_signals():
|
||||
print("[+] Store signals added")
|
||||
print("[+] Common signals added")
|
||||
|
||||
Submodule frontend/NovelPlus-frontend updated: 98596203bf...356a49e52d
File diff suppressed because one or more lines are too long
@@ -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.26bf2160.js' %}"></script>
|
||||
<script defer="defer" src="{% static 'frontend/js/main.b0f7af15.js' %}"></script>
|
||||
<link rel="stylesheet" href="{% static 'frontend/css/main.bc62eaf9.css' %}">
|
||||
</head>
|
||||
<body>
|
||||
|
||||
@@ -2,7 +2,14 @@ from django.contrib import admin
|
||||
from django.contrib.auth.admin import UserAdmin
|
||||
|
||||
from users.admin_forms import UserCreationForm, UserChangeForm
|
||||
from users.models import User
|
||||
from users.models import User, UserContextButton
|
||||
|
||||
|
||||
class UserContextButtonsInline(admin.TabularInline):
|
||||
model = UserContextButton
|
||||
verbose_name = 'Контекстная кнопка пользователя'
|
||||
verbose_name_plural = 'Контекстные кнопки пользователя'
|
||||
extra = 1
|
||||
|
||||
|
||||
class CustomUserAdmin(UserAdmin):
|
||||
@@ -23,6 +30,7 @@ class CustomUserAdmin(UserAdmin):
|
||||
)}
|
||||
),
|
||||
)
|
||||
inlines = [UserContextButtonsInline]
|
||||
search_fields = ("email", "username", "email")
|
||||
ordering = ("id",)
|
||||
|
||||
|
||||
30
users/migrations/0006_usercontextbutton.py
Normal file
30
users/migrations/0006_usercontextbutton.py
Normal file
@@ -0,0 +1,30 @@
|
||||
# Generated by Django 4.2.16 on 2024-10-01 14:39
|
||||
|
||||
from django.conf import settings
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('common', '0005_contextbuttontype'),
|
||||
('users', '0005_alter_user_description'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='UserContextButton',
|
||||
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='user_buttons', to='common.contextbuttontype', verbose_name='Тип кнопки')),
|
||||
('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='context_buttons', to=settings.AUTH_USER_MODEL, verbose_name='Пользователь')),
|
||||
],
|
||||
options={
|
||||
'verbose_name': 'Контекстная кнопка пользователей',
|
||||
'verbose_name_plural': 'Контекстные кнопки пользователей',
|
||||
'unique_together': {('user', 'button_type')},
|
||||
},
|
||||
),
|
||||
]
|
||||
@@ -30,6 +30,9 @@ class User(AbstractUser):
|
||||
}
|
||||
|
||||
def get_user_page_info_dict(self, current_user_id: typing.Union[int, None]) -> dict:
|
||||
|
||||
context_buttons = [{"name": cb.button_type.verbose, "url": cb.url} for cb in self.context_buttons.all()]
|
||||
|
||||
return {
|
||||
'username': self.username,
|
||||
'firstName': self.first_name,
|
||||
@@ -39,5 +42,29 @@ class User(AbstractUser):
|
||||
'description': self.description,
|
||||
'isOwner': self.id == current_user_id,
|
||||
'dateJoined': self.date_joined.timestamp(),
|
||||
'id': self.id
|
||||
'id': self.id,
|
||||
'contextButtons': context_buttons
|
||||
}
|
||||
|
||||
|
||||
class UserContextButton(models.Model):
|
||||
user = models.ForeignKey(User,
|
||||
on_delete=models.CASCADE,
|
||||
related_name='context_buttons',
|
||||
verbose_name='Пользователь'
|
||||
)
|
||||
button_type = models.ForeignKey(
|
||||
'common.ContextButtonType',
|
||||
on_delete=models.CASCADE,
|
||||
related_name='user_buttons',
|
||||
verbose_name='Тип кнопки'
|
||||
)
|
||||
url = models.URLField(max_length=255, verbose_name='Ссылка')
|
||||
|
||||
class Meta:
|
||||
verbose_name = 'Контекстная кнопка пользователей'
|
||||
verbose_name_plural = 'Контекстные кнопки пользователей'
|
||||
unique_together = ('user', 'button_type')
|
||||
|
||||
def __str__(self):
|
||||
return f'{self.button_type.verbose} = {self.url}'
|
||||
|
||||
Reference in New Issue
Block a user