# Path: brasilcomvc/common/email.py
# def send_template_email(subject, to, template_name, context=None):
#     '''
#     Render a template into an email body and send it through Django's send_mail
# 
#     - The `to` parameter must be a single email address.
#     - This function omits `from_email` because it expects it to exist from an
#     environment variable.
#     - Other parameters are omitted as well because there are no
#     use for them in the current use case.
#     '''
#     body = render_to_string(template_name, context or {}, Context({
#         'mailing_address': settings.MAILING_ADDRESS,
#         'site_url': settings.BASE_URL,
#         'sns_facebook': settings.SNS_FACEBOOK,
#         'sns_googleplus': settings.SNS_GOOGLEPLUS,
#         'sns_twitter': settings.SNS_TWITTER,
#         'subject': subject,
#     }))
#     plain_body = strip_tags(body)
# 
#     email = EmailMultiAlternatives(
#         subject=subject,
#         body=plain_body,
#         to=(to,))
#     email.attach_alternative(body, 'text/html')
#     email.send()


from django.conf import settings
from django.contrib.gis.db import models
from django.contrib.gis.geos import Point
from django.core.exceptions import ValidationError
from django.core.urlresolvers import reverse
from django.utils.encoding import smart_text, python_2_unicode_compatible
from django.utils.text import slugify
from imagekit.models import ImageSpecField, ProcessedImageField
from imagekit.processors import ResizeToFill
from pygeocoder import Geocoder, GeocoderError
from brasilcomvc.common.email import send_template_email

    def __str__(self):
        return self.name

    def get_absolute_url(self):
        return reverse('projects:project_details', kwargs={'slug': self.slug})

    def clean(self):
        # Use Google Maps API to geocode `address` into `latlng`
        try:
            addr = Geocoder.geocode(' '.join(self.address.splitlines()))[0]
            self.latlng = Point(y=addr.latitude, x=addr.longitude, srid=4326)

        except GeocoderError as err:
            if err.status != GeocoderError.G_GEO_ZERO_RESULTS:
                raise
            raise ValidationError('Endereço não reconhecido no Google Maps.')

    def save(self, **kwargs):
        if self.pk is None:
            self.slug = slugify(smart_text(self.name))
        super(Project, self).save(**kwargs)


@python_2_unicode_compatible
class Tag(models.Model):

    name = models.CharField(max_length=24)

    def __str__(self):

# Path: brasilcomvc/common/email.py
# def send_template_email(subject, to, template_name, context=None):
#     '''
#     Render a template into an email body and send it through Django's send_mail
# 
#     - The `to` parameter must be a single email address.
#     - This function omits `from_email` because it expects it to exist from an
#     environment variable.
#     - Other parameters are omitted as well because there are no
#     use for them in the current use case.
#     '''
#     body = render_to_string(template_name, context or {}, Context({
#         'mailing_address': settings.MAILING_ADDRESS,
#         'site_url': settings.BASE_URL,
#         'sns_facebook': settings.SNS_FACEBOOK,
#         'sns_googleplus': settings.SNS_GOOGLEPLUS,
#         'sns_twitter': settings.SNS_TWITTER,
#         'subject': subject,
#     }))
#     plain_body = strip_tags(body)
# 
#     email = EmailMultiAlternatives(
#         subject=subject,
#         body=plain_body,
#         to=(to,))
#     email.attach_alternative(body, 'text/html')
#     email.send()


# Path: brasilcomvc/projects/models.py
from django.conf import settings
from django.contrib.gis.db import models
from django.contrib.gis.geos import Point
from django.core.exceptions import ValidationError
from django.core.urlresolvers import reverse
from django.utils.encoding import smart_text, python_2_unicode_compatible
from django.utils.text import slugify
from imagekit.models import ImageSpecField, ProcessedImageField
from imagekit.processors import ResizeToFill
from pygeocoder import Geocoder, GeocoderError
from brasilcomvc.common.email import send_template_email


    def __str__(self):
        return self.name

    def get_absolute_url(self):
        return reverse('projects:project_details', kwargs={'slug': self.slug})

    def clean(self):
        # Use Google Maps API to geocode `address` into `latlng`
        try:
            addr = Geocoder.geocode(' '.join(self.address.splitlines()))[0]
            self.latlng = Point(y=addr.latitude, x=addr.longitude, srid=4326)

        except GeocoderError as err:
            if err.status != GeocoderError.G_GEO_ZERO_RESULTS:
                raise
            raise ValidationError('Endereço não reconhecido no Google Maps.')

    def save(self, **kwargs):
        if self.pk is None:
            self.slug = slugify(smart_text(self.name))
        super(Project, self).save(**kwargs)


@python_2_unicode_compatible
class Tag(models.Model):

    name = models.CharField(max_length=24)

    def __str__(self):

        return self.name