예제 #1
0
def model_notify(model: Model, created=True) -> None:
    """
    Email notification when a new Model created.
    """

    recipients = [
        u.email for u in User.objects.filter(
            groups__name="Style Managers").exclude(email='')
    ]

    if created:
        model_status = "created"
    else:
        model_status = "updated"

    if recipients:
        domain = Site.objects.get_current().domain
        mail_from = settings.DEFAULT_FROM_EMAIL

        send_mail_wrapper(
            _('A new Model has been %s by %s.') %
            (model_status, model.creator),
            _('\r\nModel name is: %s\r\nModel description is: %s\r\n'
              'Link: http://%s%s\r\n') %
            (model.name, model.description, domain, model.get_absolute_url()),
            mail_from,
            recipients,
            fail_silently=True)
        logging.debug('Sending email notification for %s Model, '
                      'recipients:  %s' % (model.name, recipients))
    else:
        logging.warning('No recipients found for %s Model notification' %
                        model.name)
예제 #2
0
def model_update_notify(model: Model, creator: User, staff: User) -> None:
    """
    Email notification system when staff approved or rejected a Model
    """

    recipients = [
        u.email for u in User.objects.filter(
            groups__name="Style Managers").exclude(email='')
    ]

    if creator.email:
        recipients += [creator.email]

    if model.approved:
        approval_state = 'approved'
    else:
        approval_state = 'rejected'

    review = model.modelreview_set.last()
    comment = review.comment

    if recipients:
        domain = Site.objects.get_current().domain
        mail_from = settings.DEFAULT_FROM_EMAIL
        send_mail_wrapper(
            _('Model %s %s notification.') % (model, approval_state),
            _('\r\nModel %s %s by %s.\r\n%s\r\nLink: http://%s%s\r\n') %
            (model.name, approval_state, staff, comment, domain,
             model.get_absolute_url()),
            mail_from,
            recipients,
            fail_silently=True)
        logging.debug('Sending email %s notification for %s Model, '
                      'recipients:  %s' % (approval_state, model, recipients))
    else:
        logging.warning('No recipients found for %s model %s notification' %
                        (model, approval_state))