Skip to content

Commit

Permalink
Merge branch 'develop' into feature/update-password-reset-template
Browse files Browse the repository at this point in the history
  • Loading branch information
MikeWazowskyi authored Sep 3, 2023
2 parents 8419ff8 + aa42cf2 commit 3af8e46
Show file tree
Hide file tree
Showing 100 changed files with 518 additions and 154 deletions.
2 changes: 1 addition & 1 deletion .flake8
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[flake8]
ignore = E501, E265, F811, PT001, DJ05, D100, D105, D104, W504, W292, D106, D107
ignore = E501, E265, F811, PT001, DJ05, D100, D105, D104, W504, W292, D106, D107, W503
max-line-length = 79
exclude =
*/migrations/
16 changes: 15 additions & 1 deletion .github/workflows/deploy-bot-on-prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@ jobs:
name: prod_deploy
if: ${{ github.event.workflow_run.conclusion == 'success' }}
steps:
- name: copy service file
uses: appleboy/scp-action@v0.1.4
with:
host: ${{ secrets.VM_HOST }}
username: ${{ secrets.VM_USER }}
password: ${{ secrets.VM_PASSWORD }}
source: "infra/prod/"
target: /home/deploy/spread_wings_bot/infra/prod/
- name: ssh pull and start
uses: appleboy/ssh-action@master
with:
Expand All @@ -21,7 +29,6 @@ jobs:
password: ${{ secrets.VM_PASSWORD }}
script: |
cd /home/deploy/spread_wings_bot/infra/prod/
git pull
rm .env
touch .env
Expand Down Expand Up @@ -61,6 +68,13 @@ jobs:
# Cleaning unused containers, images, networks
docker system prune --force
# Installing defend service for app
# Шаг с копированием в строках 16-23 можно заменить командой ниже - нужно тестировать
# scp infra/prod/spread_wings_bot.service ${{ secrets.VM_USER }}@${{ secrets.VM_HOST }}:/spread_wings_bot/infra/prod/
sudo cp -f /home/deploy/spread_wings_bot/infra/prod/spread_wings_bot.service /etc/systemd/system/spread_wings_bot.service
sudo systemctl daemon-reload
sudo systemctl restart spread_wings_bot.service
# Installing the app
docker-compose -f docker-compose.stage.yaml stop
docker-compose -f docker-compose.stage.yaml pull
Expand Down
17 changes: 16 additions & 1 deletion .github/workflows/deploy-bot-on-stage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,15 @@ jobs:
name: stage_deploy
if: ${{ github.event.workflow_run.conclusion == 'success' }}
steps:
- name: copy service file
uses: appleboy/scp-action@v0.1.4
with:
host: ${{ secrets.VM_HOST }}
username: ${{ secrets.VM_USER }}
password: ${{ secrets.VM_PASSWORD }}
port: 22
source: "infra/dev/spread_wings_bot.service"
target: /home/deploy/spread_wings_bot/infra/dev/
- name: ssh pull and start
uses: appleboy/ssh-action@master
with:
Expand All @@ -21,7 +30,6 @@ jobs:
password: ${{ secrets.VM_PASSWORD }}
script: |
cd /home/deploy/spread_wings_bot/infra/dev/
git pull
rm .env
touch .env
Expand Down Expand Up @@ -61,6 +69,13 @@ jobs:
# Cleaning unused containers, images, networks
docker system prune --force
# Installing defend service for app
# Шаг с копированием в строках 16-23 можно заменить командой ниже - нужно тестировать
# scp infra/dev/spread_wings_bot.service ${{ secrets.VM_USER }}@${{ secrets.VM_HOST }}:/spread_wings_bot/infra/dev/
sudo cp -f /home/deploy/spread_wings_bot/infra/dev/spread_wings_bot.service /etc/systemd/system/spread_wings_bot.service
sudo systemctl daemon-reload
sudo systemctl restart spread_wings_bot.service
# Installing the app
docker-compose -f docker-compose.stage.yaml stop
docker-compose -f docker-compose.stage.yaml pull
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ coverage.xml
local_settings.py
db.sqlite3
db.sqlite3-journal
static/
staticfiles/
media/
logs/

Expand Down
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ help: # Show help


.PHONY: runbot-init
runbot-init: deletedb rundb migrate filldb create_superuser runbot-db # Build and run Database Docker-image
runbot-init: deletedb rundb migrate filldb collectstatic createsuperuser runbot-db # Build and run Database Docker-image
@echo -e "$(COLOR_YELLOW)Starting initialization...$(COLOR_RESET)"
@source $$(poetry env info -p)/bin/activate

Expand Down Expand Up @@ -90,6 +90,10 @@ migrate: # Commit migrations to Database
@sleep 3;
@echo -e "$(COLOR_GREEN)Migrated$(COLOR_RESET)"

.PHONY: createsuperuser
createsuperuser:
@echo -e "$(COLOR_YELLOW)Creating Django superuser...$(COLOR_RESET)"
@poetry run python src/manage.py createsuperuser

.PHONY: run_tests
run_tests: run_unit_tests # Run all tests
Expand Down
2 changes: 1 addition & 1 deletion infra/dev/docker-compose.stage.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ services:
- redis
- db
volumes:
- ../../static:/app/src/static
- ../../static:/app/src/staticfiles
- ../../media:/app/src/media
- ./logs/bot/:/app/src/logs
restart: always
Expand Down
29 changes: 29 additions & 0 deletions infra/dev/spread_wings_bot.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
[Unit]

Description=spread_wings_bot
Requires=docker.service
After=docker.service

[Service]

Restart=always
RestartSec=5
TimeOutStartSec=1200
User=root

WorkingDirectory=/home/deploy/spread_wings_bot/infra/dev/

ExecStartPre=docker-compose -f docker-compose.stage.yaml --env-file /home/deploy/spread_wings_bot/infra/dev/.env pull bot
ExecStartPre=docker-compose -f docker-compose.stage.yaml --env-file /home/deploy/spread_wings_bot/infra/dev/.env pull db
ExecStartPre=docker-compose -f docker-compose.stage.yaml --env-file /home/deploy/spread_wings_bot/infra/dev/.env pull redis
ExecStartPre=docker-compose -f docker-compose.stage.yaml --env-file /home/deploy/spread_wings_bot/infra/dev/.env pull nginx
ExecStartPre=docker-compose -f docker-compose.stage.yaml --env-file /home/deploy/spread_wings_bot/infra/dev/.env down

# compose up
ExecStart=docker-compose -f docker-compose.stage.yaml --env-file /home/deploy/spread_wings_bot/infra/dev/.env up

# compose down
ExecStop=docker-compose -f docker-compose.stage.yaml --env-file /home/deploy/spread_wings_bot/infra/dev/.env down

[Install]
WantedBy=multi-user.target
4 changes: 0 additions & 4 deletions infra/init.sh

This file was deleted.

2 changes: 1 addition & 1 deletion infra/prod/docker-compose.prod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ services:
- redis
- db
volumes:
- ../../static:/app/src/static
- ../../static:/app/src/staticfiles
- ../../media:/app/src/media
- ./logs/bot/:/app/src/logs
restart: always
Expand Down
29 changes: 29 additions & 0 deletions infra/prod/spread_wings_bot.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
[Unit]

Description=spread_wings_bot
Requires=docker.service
After=docker.service

[Service]

Restart=always
RestartSec=5
TimeOutStartSec=1200
User=root

WorkingDirectory=/home/deploy/spread_wings_bot/infra/prod/

ExecStartPre=docker-compose -f docker-compose.prod.yaml --env-file /home/deploy/spread_wings_bot/infra/prod/.env pull bot
ExecStartPre=docker-compose -f docker-compose.prod.yaml --env-file /home/deploy/spread_wings_bot/infra/prod/.env pull db
ExecStartPre=docker-compose -f docker-compose.prod.yaml --env-file /home/deploy/spread_wings_bot/infra/prod/.env pull redis
ExecStartPre=docker-compose -f docker-compose.prod.yaml --env-file /home/deploy/spread_wings_bot/infra/prod/.env pull nginx
ExecStartPre=docker-compose -f docker-compose.prod.yaml --env-file /home/deploy/spread_wings_bot/infra/prod/.env down

# compose up
ExecStart=docker-compose -f docker-compose.prod.yaml --env-file /home/deploy/spread_wings_bot/infra/prod/.env up

# compose down
ExecStop=docker-compose -f docker-compose.prod.yaml --env-file /home/deploy/spread_wings_bot/infra/prod/.env down

[Install]
WantedBy=multi-user.target
19 changes: 2 additions & 17 deletions src/bot/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ class QuestionAdmin(RegionForAdmin):
form = QuestionAdminForm
list_display = (
"get_question",
"get_short_description",
"get_question_type",
"short_description",
"question_type",
"get_answer",
"get_regions",
)
Expand All @@ -41,16 +41,6 @@ def get_question(self, obj):
"""Display questions in admin panel."""
return obj.question[:100]

@admin.display(description="Короткое описание")
def get_short_description(self, obj):
"""Display short_descriptions in admin panel."""
return obj.short_description[:100]

@admin.display(description="Тип вопроса")
def get_question_type(self, obj):
"""Display question_type in admin panel."""
return obj.question_type[:100]

@admin.display(description="Ответ")
def get_answer(self, obj):
"""Display answer in admin panel."""
Expand Down Expand Up @@ -95,11 +85,6 @@ def get_title(self, obj):
"""Display title in admin panel."""
return obj.title[:100]

@admin.display(description="Короткое описание")
def get_short_description(self, obj):
"""Display short_description in admin panel."""
return obj.short_description[:100]

@admin.display(description="Описание программы")
def get_fund_text(self, obj):
"""Display fund_text in admin panel."""
Expand Down
4 changes: 2 additions & 2 deletions src/bot/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,8 @@ async def build_app() -> Application:
states={
States.GET_ASSISTANCE: [
CallbackQueryHandler(get_assistance, pattern=GET_ASSISTANCE),
],
States.REGION: [
]
+ [
CallbackQueryHandler(
select_type_of_assistance,
pattern=PATTERN.format(state=key),
Expand Down
12 changes: 0 additions & 12 deletions src/bot/constants/messages.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,6 @@
START_MESSAGE = 'Здравствуйте! Это бот фонда "Расправь крылья".'
HELP_MESSAGE = (
"[Заглушка]Здесь выводится краткое описание возможностей бота (/help)"
)
ASSISTANCE_MESSAGE = (
'[Заглушка]Сообщение после нажатия на кнопку "Получить помощь" '
"(Выбор региона)"
)
CHOOSE_REGION_MESSAGE = "Выберите, пожалуйста, регион"
ASSISTANCE_TYPE_MESSAGE = (
"[Заглушка]Сообщение в момент выбора юр., соц., психол., помощи и т.д."
)
HOW_CAN_WE_HELP = "Чем мы можем помочь?"
MENU_MESSAGE = "Команды и меню обновлены"
CONTACT_US_MESSAGE = "[Заглушка] Задать вопрос."

SELECT_FUND_PROGRAM = "Выбор программы из списка"
SELECT_QUESTION = "Выбор вопроса из списка"
Expand Down
4 changes: 3 additions & 1 deletion src/bot/constants/patterns.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@
state="".join(f"{h_type}|" for h_type in HelpTypes.names)
)
HELP_TYPE = rf"({POSSIBLE_TYPE_OF_ASSISTANCE})(?:{PAGE_SEP_SYMBOL}(\d+))?"
GET_ASSISTANCE = PATTERN.format(
state=rf"({States.GET_ASSISTANCE.value})(?:{PAGE_SEP_SYMBOL}(\d+))?"
)
SEND_EMAIL = PATTERN.format(state=States.SEND_EMAIL.value)
GET_USER_QUESTION = PATTERN.format(state=States.GET_USER_QUESTION.value)
GET_ASSISTANCE = PATTERN.format(state=States.GET_ASSISTANCE.value)
FUND_PROGRAMS = PATTERN.format(
state=rf"({States.FUND_PROGRAMS.value})(?:{PAGE_SEP_SYMBOL}(\d+))?"
)
Expand Down
2 changes: 2 additions & 0 deletions src/bot/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class Meta:

model = Question
widgets = {
"question": forms.Textarea(attrs={"rows": 3, "cols": 50}),
"answer": forms.Textarea(attrs={"rows": 10, "cols": 80}),
"regions": forms.CheckboxSelectMultiple,
}
Expand All @@ -25,6 +26,7 @@ class Meta:

models = FundProgram
widgets = {
"title": forms.Textarea(attrs={"rows": 3, "cols": 50}),
"regions": forms.CheckboxSelectMultiple,
}
fields = "__all__"
27 changes: 17 additions & 10 deletions src/bot/handlers/assistance.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
SELECT_FUND_PROGRAM,
SELECT_QUESTION,
)
from bot.constants.patterns import FUND_PROGRAMS, HELP_TYPE
from bot.constants.patterns import FUND_PROGRAMS, GET_ASSISTANCE, HELP_TYPE
from bot.constants.states import States
from bot.handlers.debug_handlers import debug_logger
from bot.keyboards.assistance import (
Expand All @@ -20,27 +20,34 @@
)
from bot.keyboards.assistance_types import assistance_types_keyboard_markup
from bot.keyboards.utils.callback_data_parse import parse_callback_data
from bot.models import HelpTypes
from bot_settings.models import BotSettings

DEFAULT_PAGE = 1


@debug_logger(state=States.REGION, run_functions_debug_loger="get_assistance")
@debug_logger(
state=States.GET_ASSISTANCE, run_functions_debug_loger="get_assistance"
)
async def get_assistance(
update: Update,
context: ContextTypes.DEFAULT_TYPE,
) -> States:
"""Select a region of assistance."""
await update.callback_query.answer()
keyboard = await build_region_keyboard()
query = update.callback_query
callback_data = query.data.replace("back_to_", "")
_, page_number = parse_callback_data(callback_data, GET_ASSISTANCE)
page_number = page_number or DEFAULT_PAGE
await query.answer()
keyboard = await build_region_keyboard(page_number)
assistance_message = await BotSettings.objects.aget(
key="assistance_message"
)
await update.callback_query.edit_message_text(
text=assistance_message.value, reply_markup=keyboard
)
return States.REGION
if query.message.reply_markup.to_json() != keyboard.markup:
await query.edit_message_text(
text=assistance_message.value,
reply_markup=keyboard.markup,
)
return States.GET_ASSISTANCE


@debug_logger(
Expand Down Expand Up @@ -139,7 +146,7 @@ async def contact_with_us(
) -> States:
"""Ask question and show contacts."""
query = update.callback_query
context.user_data[States.QUESTION_TYPE] = HelpTypes.COMMON_QUESTION.value
context.user_data[States.QUESTION_TYPE] = "COMMON_QUESTION"
await query.answer()
await query.edit_message_text(
text=CONTACT_SHOW_MESSAGE,
Expand Down
4 changes: 2 additions & 2 deletions src/bot/handlers/service_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ async def answer_all_messages(


FUNCTIONS: dict[str, Callable[[Any, Any], Awaitable[States]]] = {
States.GET_ASSISTANCE.value: start,
States.START: start,
States.ASSISTANCE_TYPE: select_type_of_assistance,
States.CONTACT_US: contact_with_us,
States.FUND_PROGRAMS: fund_programs,
States.REGION: get_assistance,
States.REGION.value: get_assistance,
States.SHOW_CONTACT: show_contact,
States.GET_USERNAME: get_user_question,
States.USERNAME_AFTER_RETURNING: get_username_after_returning_back,
Expand Down
Loading

0 comments on commit 3af8e46

Please sign in to comment.