# Path: fossevents/base/mail.py
# def send_email(subject, email_template_name, to_emails,
#                extra_context=None, html_email_template_name=None):
#     ctx_dict = {}
#     current_site = Site.objects.get_current()
# 
#     if extra_context:
#         ctx_dict.update(extra_context)
# 
#     ctx_dict.update({
#         'site': current_site,
#         'scheme': settings.SITE_SCHEME
#     })
# 
#     from_email = getattr(settings, 'DEFAULT_FROM_EMAIL')
#     message_txt = render_to_string(email_template_name,
#                                    ctx_dict)
# 
#     email_message = EmailMultiAlternatives(subject, message_txt,
#                                            from_email, to_emails)
# 
#     if html_email_template_name:
#         try:
#             message_html = render_to_string(
#                 html_email_template_name, ctx_dict)
#             email_message.attach_alternative(message_html, 'text/html')
#         except TemplateDoesNotExist:
#             pass
# 
#     email_message.send()


from django.conf import settings
from django.utils import timezone
from django.contrib.auth import get_user_model
from django.contrib.sites.models import Site
from django.core.urlresolvers import reverse
from fossevents.base.mail import send_email
from . import models

def send_event_create_mail(event, users_emails):

    current_site = Site.objects.get_current()
    extra_context = {'event': event, 'review_url': get_event_review_url(event),
                     'site_url': '{}://{}'.format(settings.SITE_SCHEME, current_site.domain)}

    # Send mail to moderators
    send_email('FOSSEvents | ' + event.name[:15] + ' published!',
               'email/event_create_moderators_email.txt', users_emails,
               extra_context, 'email/event_create_moderators_email.html')

    # Send mail to creator
    send_email('FOSSEvents | ' + event.name[:15] + ' published!',
               'email/event_create_creator_email.txt', [event.owner_email],
               extra_context, 'email/event_create_creator_email.html')


def send_event_update_mail(event, users_emails):

    current_site = Site.objects.get_current()
    extra_context = {'event': event, 'review_url': get_event_review_url(event),
                     'site_url': '{}://{}'.format(settings.SITE_SCHEME, current_site.domain)}

    # Send mail to moderators
    send_email('FOSSEvents | ' + event.name[:15] + ' updated!',
               'email/event_update_moderators_email.txt', users_emails,
               extra_context, 'email/event_update_moderators_email.html')

    # Send mail to creator

# Path: fossevents/base/mail.py
# def send_email(subject, email_template_name, to_emails,
#                extra_context=None, html_email_template_name=None):
#     ctx_dict = {}
#     current_site = Site.objects.get_current()
# 
#     if extra_context:
#         ctx_dict.update(extra_context)
# 
#     ctx_dict.update({
#         'site': current_site,
#         'scheme': settings.SITE_SCHEME
#     })
# 
#     from_email = getattr(settings, 'DEFAULT_FROM_EMAIL')
#     message_txt = render_to_string(email_template_name,
#                                    ctx_dict)
# 
#     email_message = EmailMultiAlternatives(subject, message_txt,
#                                            from_email, to_emails)
# 
#     if html_email_template_name:
#         try:
#             message_html = render_to_string(
#                 html_email_template_name, ctx_dict)
#             email_message.attach_alternative(message_html, 'text/html')
#         except TemplateDoesNotExist:
#             pass
# 
#     email_message.send()


# Path: fossevents/events/services.py
from django.conf import settings
from django.utils import timezone
from django.contrib.auth import get_user_model
from django.contrib.sites.models import Site
from django.core.urlresolvers import reverse
from fossevents.base.mail import send_email
from . import models


def send_event_create_mail(event, users_emails):

    current_site = Site.objects.get_current()
    extra_context = {'event': event, 'review_url': get_event_review_url(event),
                     'site_url': '{}://{}'.format(settings.SITE_SCHEME, current_site.domain)}

    # Send mail to moderators
    send_email('FOSSEvents | ' + event.name[:15] + ' published!',
               'email/event_create_moderators_email.txt', users_emails,
               extra_context, 'email/event_create_moderators_email.html')

    # Send mail to creator
    send_email('FOSSEvents | ' + event.name[:15] + ' published!',
               'email/event_create_creator_email.txt', [event.owner_email],
               extra_context, 'email/event_create_creator_email.html')


def send_event_update_mail(event, users_emails):

    current_site = Site.objects.get_current()
    extra_context = {'event': event, 'review_url': get_event_review_url(event),
                     'site_url': '{}://{}'.format(settings.SITE_SCHEME, current_site.domain)}

    # Send mail to moderators
    send_email('FOSSEvents | ' + event.name[:15] + ' updated!',
               'email/event_update_moderators_email.txt', users_emails,
               extra_context, 'email/event_update_moderators_email.html')

    # Send mail to creator

    send_email('FOSSEvents | ' + event.name[:15] + ' updated!',