-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create signals from borrowings to bot for notifications about new bor…
…rowing
- Loading branch information
1 parent
dfe4615
commit 010852a
Showing
4 changed files
with
54 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
from django.db.models.signals import post_save | ||
from django.dispatch import receiver | ||
from notifications_service.management.commands.run_telegram_bot import ( | ||
send_notification | ||
) | ||
from borrowing_service.models import Borrowing | ||
from notifications_service.models import TelegramUser | ||
|
||
|
||
@receiver(post_save, sender=Borrowing) | ||
def notify_new_borrowing(sender, instance, created, **kwargs): | ||
if created: | ||
borrowing_info = ( | ||
"New borrowing created:\n\n" | ||
f"-Book: {instance.book}\n" | ||
f"--Borrow date: {instance.borrow_date}\n" | ||
f"--Expected return date: {instance.expected_return_date}\n" | ||
) | ||
send_notification( | ||
TelegramUser.objects.get(user_id=instance.user_id).chat_id, | ||
borrowing_info | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters