Skip to content

Commit

Permalink
Merge pull request #34 from Naz-iv/setup-notifications-bot
Browse files Browse the repository at this point in the history
Fixed create borrowings feature
  • Loading branch information
RVChornyy authored Dec 18, 2023
2 parents 809c92a + 454986c commit 6132193
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions borrowing_service/signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,16 @@
@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
)
try:
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
)
except TelegramUser.DoesNotExist:
pass

0 comments on commit 6132193

Please sign in to comment.