Add a notify_books attribute of GrumpySettings. If set to "True", the code should send an email to the admin whenever a new book is created (and deleted?) (but not updated). Obviously, the title of the book should not be included in the email.
The code could work a bit like this:
grumpy/books/views.py:
from django.conf import settings
from django.contrib.sites.shortcuts import get_current_site
from django.core.mail import mail_managers
....
class BookCreateView(LoginRequiredMixin, UserPassesTestMixin, CreateView):
....
def form_valid(self, form):
....
book = self.object
....
if settings.NOTIFY_BOOKS:
subject = super().format_email_subject(f"new book added for {book.owner}")
message = f"User {current_user.email} added a new book [{book.id}] at at {get_current_site(request)}."
mail_managers(subject, message, fail_silently=True)
....
Add a
notify_booksattribute ofGrumpySettings. If set to "True", the code should send an email to the admin whenever a new book is created (and deleted?) (but not updated). Obviously, the title of the book should not be included in the email.The code could work a bit like this:
grumpy/books/views.py: