Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

change admin bot settings #239

Merged
merged 4 commits into from
Aug 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 4 additions & 13 deletions src/bot_settings/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@
class BotSettingsAdmin(admin.ModelAdmin):
"""Base admin configuration for BotSettings model."""

list_display = ("get_title", "get_type", "get_value", "get_key")
list_display = ("get_title", "type", "get_value")
list_filter = ("title", "type", "value")
search_fields = ("title", "type", "value", "key")
readonly_fields = ("key", "type")
search_fields = ("title", "type", "value")
readonly_fields = ("type",)
exclude = ("key",)

def has_delete_permission(self, request, obj=None):
"""Disable delete permission for BotSettings model."""
Expand All @@ -21,17 +22,7 @@ def get_title(self, obj):
"""Display title of settings in admin panel."""
return obj.title[:100]

@admin.display(description="Тип значения")
def get_type(self, obj):
"""Display type of settings in admin panel."""
return obj.type[:100]

@admin.display(description="Значение настройки")
def get_value(self, obj):
"""Display value of settings in admin panel."""
return obj.value[:100]

@admin.display(description="Ключ настройки")
def get_key(self, obj):
"""Display key of settings in admin panel."""
return obj.key[:100]
115 changes: 112 additions & 3 deletions src/bot_settings/migrations/0002_add_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,9 @@ def create_assistance_message_setting(apps, schema_editor):
BotSettings = apps.get_model("bot_settings", "BotSettings")
BotSettings.objects.create(
key="assistance_message",
title="Сообщение при нажатии на кнопку Assistance",
title="Сообщение при нажатии на кнопку 'Получить помощь'",
type=BotSettingsModel.TEXT,
value='Сообщение после нажатия на кнопку "Получить помощь"'
"(Выбор региона)",
value="Выберите нужный регион",
)


Expand All @@ -77,6 +76,96 @@ def remove_assistance_message_setting(apps, schema_editor):
setting.delete()


def create_select_type_of_help_setting(apps, schema_editor):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Нужно еще это сообщение добавить в настройку

[Заглушка]Сообщение в момент выбора юр., соц., психол., помощи и т.д.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

или она не подтянулась, проверишь?

"""Create select_type_of_help setting instance."""
BotSettings = apps.get_model("bot_settings", "BotSettings")
BotSettings.objects.create(
key="select_type_of_help",
title="Сообщение при нажатии на кнопку нужного региона",
type=BotSettingsModel.TEXT,
value="[Заглушка]Сообщение в момент выбора юр., соц., психол., помощи и т.д.",
)


def remove_select_type_of_help_setting(apps, schema_editor):
"""Remove select_type_of_help setting instance."""
BotSettings = apps.get_model("bot_settings", "BotSettings")
setting = BotSettings.objects.get(key="select_type_of_help")
setting.delete()


def create_selected_type_assistance_setting(apps, schema_editor):
"""Create selected_type_assistance setting instance."""
BotSettings = apps.get_model("bot_settings", "BotSettings")
BotSettings.objects.create(
key="selected_type_assistance",
title="Сообщение при нажатии на кнопку нужного типа помощи",
type=BotSettingsModel.TEXT,
value="Выбор вопроса из списка",
)


def remove_selected_type_assistance_setting(apps, schema_editor):
"""Remove selected_type_assistance setting instance."""
BotSettings = apps.get_model("bot_settings", "BotSettings")
setting = BotSettings.objects.get(key="selected_type_assistance")
setting.delete()


def create_ask_question_setting(apps, schema_editor):
"""Create ask_question setting instance."""
BotSettings = apps.get_model("bot_settings", "BotSettings")
BotSettings.objects.create(
key="ask_question",
title="Сообщение при нажатии на кнопку 'Задать свой вопрос'",
type=BotSettingsModel.TEXT,
value="Задайте Ваш вопрос",
)


def remove_ask_question_setting(apps, schema_editor):
"""Remove ask_question setting instance."""
BotSettings = apps.get_model("bot_settings", "BotSettings")
setting = BotSettings.objects.get(key="ask_question")
setting.delete()


def create_fund_programs_setting(apps, schema_editor):
"""Create fund_programs setting instance."""
BotSettings = apps.get_model("bot_settings", "BotSettings")
BotSettings.objects.create(
key="fund_programs",
title="Сообщение при нажатии на кнопку 'Наши программы'",
type=BotSettingsModel.TEXT,
value="Выбор программы из списка",
)


def remove_fund_programs_setting(apps, schema_editor):
"""Remove fund_programs setting instance."""
BotSettings = apps.get_model("bot_settings", "BotSettings")
setting = BotSettings.objects.get(key="fund_programs")
setting.delete()


def create_contact_with_us_setting(apps, schema_editor):
"""Create contact_with_us setting instance."""
BotSettings = apps.get_model("bot_settings", "BotSettings")
BotSettings.objects.create(
key="contact_with_us",
title="Сообщение при нажатии на кнопку 'Связаться с нами'",
type=BotSettingsModel.TEXT,
value="Выберите способ связи",
)


def remove_contact_with_us_setting(apps, schema_editor):
"""Remove contact_with_us setting instance."""
BotSettings = apps.get_model("bot_settings", "BotSettings")
setting = BotSettings.objects.get(key="contact_with_us")
setting.delete()


class Migration(migrations.Migration):
"""Initial migration for bot_settings app."""

Expand All @@ -101,4 +190,24 @@ class Migration(migrations.Migration):
create_assistance_message_setting,
reverse_code=remove_assistance_message_setting,
),
migrations.RunPython(
create_select_type_of_help_setting,
reverse_code=remove_select_type_of_help_setting,
),
migrations.RunPython(
create_selected_type_assistance_setting,
reverse_code=remove_selected_type_assistance_setting,
),
migrations.RunPython(
create_ask_question_setting,
reverse_code=remove_ask_question_setting,
),
migrations.RunPython(
create_fund_programs_setting,
reverse_code=remove_fund_programs_setting,
),
migrations.RunPython(
create_contact_with_us_setting,
reverse_code=remove_contact_with_us_setting,
),
]
24 changes: 24 additions & 0 deletions src/bot_settings/migrations/0004_alter_botsettings_type.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Generated by Django 4.2.4 on 2023-08-30 17:04

from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
(
"bot_settings",
"0003_alter_botsettings_title_alter_botsettings_value",
),
]

operations = [
migrations.AlterField(
model_name="botsettings",
name="type",
field=models.CharField(
choices=[("url", "Ссылка"), ("text", "Текст")],
max_length=100,
verbose_name="Тип значения",
),
),
]
4 changes: 2 additions & 2 deletions src/bot_settings/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ class BotSettings(BaseModel):
URL = "url"
TEXT = "text"
__VALUE_TYPES = (
(URL, "URL"),
(TEXT, "TEXT"),
(URL, "Ссылка"),
(TEXT, "Текст"),
)
key = models.CharField(
max_length=100,
Expand Down