from django.conf import settings
from django.template import loader
from django.core.mail import send_mail


def route_notifications(*log_entries):
    for entry in log_entries:
        if entry.action in ACTION_MAPPING:
            ACTION_MAPPING[entry.action](entry)



def send_update_avilable_notification(log):
    message = loader.render_to_string('notifications/update_available.mail.txt',
                                      {'log': log})
    subject = '{prefix}New update available for project "{project}"'.format(**{
        'prefix': settings.EMAIL_SUBJECT_PREFIX,
        'project': log.project.name})

    emails = log.project.members.values_list('email', flat=True)

    send_mail(subject, message, settings.DEFAULT_FROM_EMAIL, emails,
              fail_silently=False)



ACTION_MAPPING = {
    'update_available': send_update_avilable_notification
}

from django.conf import settings
from django.template import loader
from django.core.mail import send_mail


def route_notifications(*log_entries):
    for entry in log_entries:
        if entry.action in ACTION_MAPPING:
            ACTION_MAPPING[entry.action](entry)



def send_update_avilable_notification(log):
    message = loader.render_to_string('notifications/update_available.mail.txt',
                                      {'log': log})
    subject = '{prefix}New update available for project "{project}"'.format(**{
        'prefix': settings.EMAIL_SUBJECT_PREFIX,
        'project': log.project.name})

    mails = []
    members = log.project.projectmember_set.all()
    for member in members:
        mails.append(member.mail or member.user.email)

    send_mail(subject, message, settings.DEFAULT_FROM_EMAIL, mails,
              fail_silently=False)



ACTION_MAPPING = {
    'update_available': send_update_avilable_notification
}

Use project member email if given
Use project member email if given

  from django.conf import settings
  from django.template import loader
  from django.core.mail import send_mail
  
  
  def route_notifications(*log_entries):
      for entry in log_entries:
          if entry.action in ACTION_MAPPING:
              ACTION_MAPPING[entry.action](entry)
  
  
  
  def send_update_avilable_notification(log):
      message = loader.render_to_string('notifications/update_available.mail.txt',
                                        {'log': log})
      subject = '{prefix}New update available for project "{project}"'.format(**{
          'prefix': settings.EMAIL_SUBJECT_PREFIX,
          'project': log.project.name})
  
-     emails = log.project.members.values_list('email', flat=True)
+     mails = []
+     members = log.project.projectmember_set.all()
+     for member in members:
+         mails.append(member.mail or member.user.email)
  
-     send_mail(subject, message, settings.DEFAULT_FROM_EMAIL, emails,
+     send_mail(subject, message, settings.DEFAULT_FROM_EMAIL, mails,
                fail_silently=False)
  
  
  
  ACTION_MAPPING = {
      'update_available': send_update_avilable_notification
  }
  
Use project member email if given
## Code Before:
from django.conf import settings
from django.template import loader
from django.core.mail import send_mail


def route_notifications(*log_entries):
    for entry in log_entries:
        if entry.action in ACTION_MAPPING:
            ACTION_MAPPING[entry.action](entry)



def send_update_avilable_notification(log):
    message = loader.render_to_string('notifications/update_available.mail.txt',
                                      {'log': log})
    subject = '{prefix}New update available for project "{project}"'.format(**{
        'prefix': settings.EMAIL_SUBJECT_PREFIX,
        'project': log.project.name})

    emails = log.project.members.values_list('email', flat=True)

    send_mail(subject, message, settings.DEFAULT_FROM_EMAIL, emails,
              fail_silently=False)



ACTION_MAPPING = {
    'update_available': send_update_avilable_notification
}

## Instruction:
Use project member email if given
## Code After:
from django.conf import settings
from django.template import loader
from django.core.mail import send_mail


def route_notifications(*log_entries):
    for entry in log_entries:
        if entry.action in ACTION_MAPPING:
            ACTION_MAPPING[entry.action](entry)



def send_update_avilable_notification(log):
    message = loader.render_to_string('notifications/update_available.mail.txt',
                                      {'log': log})
    subject = '{prefix}New update available for project "{project}"'.format(**{
        'prefix': settings.EMAIL_SUBJECT_PREFIX,
        'project': log.project.name})

    mails = []
    members = log.project.projectmember_set.all()
    for member in members:
        mails.append(member.mail or member.user.email)

    send_mail(subject, message, settings.DEFAULT_FROM_EMAIL, mails,
              fail_silently=False)



ACTION_MAPPING = {
    'update_available': send_update_avilable_notification
}
