# Path: web/processors/media.py
# class UploadImageError(Exception):
# class ImageSizeTooLargeException(Exception):
# def process_image(image_file):
# 
# Path: mailer/event_report_mailer.py
# def send_email_to_country_ambassadors(event):
#     ambassadors = get_ambassadors_for_country(event.country)
#     for user in ambassadors:
#         send_event_report_email(user, event)


import datetime
from django.conf import settings
from django.contrib.gis.geoip import GeoIP
from api.models import Event
from django_countries import countries
from countries_plus.models import Country
from web.processors import media
from mailer.event_report_mailer import send_email_to_country_ambassadors

            # in case we have geoposition data in event_data
            if 'geoposition' in event_data and event_data['geoposition'] != '':
                # updating geoposition field is a bit fuzzy
                event_latitude = event_data['geoposition'][0]
                event_longitude = event_data['geoposition'][1]
                event_data.pop('geoposition')
                # updating all other fields
                event.__dict__.update(event_data)
                # setting new values for geoposition
                event.__dict__['geoposition'].latitude = event_latitude
                event.__dict__['geoposition'].longitude = event_longitude
                event.save()
            else:
                event.__dict__.update(event_data)
                event.save()

            if 'picture' not in event_data:
                event.picture = ''
                event.save()

            # delete old categories and tags and store new ones
            event.audience.clear()
            event.audience.add(*new_audiences)
            event.theme.clear()
            event.theme.add(*new_themes)
            event.tags.set(*event_tags)

    else:
        event = Event.objects.create(**event_data)

# Path: web/processors/media.py
# class UploadImageError(Exception):
# class ImageSizeTooLargeException(Exception):
# def process_image(image_file):
# 
# Path: mailer/event_report_mailer.py
# def send_email_to_country_ambassadors(event):
#     ambassadors = get_ambassadors_for_country(event.country)
#     for user in ambassadors:
#         send_event_report_email(user, event)


# Path: web/processors/event.py
import datetime
from django.conf import settings
from django.contrib.gis.geoip import GeoIP
from api.models import Event
from django_countries import countries
from countries_plus.models import Country
from web.processors import media
from mailer.event_report_mailer import send_email_to_country_ambassadors


            # in case we have geoposition data in event_data
            if 'geoposition' in event_data and event_data['geoposition'] != '':
                # updating geoposition field is a bit fuzzy
                event_latitude = event_data['geoposition'][0]
                event_longitude = event_data['geoposition'][1]
                event_data.pop('geoposition')
                # updating all other fields
                event.__dict__.update(event_data)
                # setting new values for geoposition
                event.__dict__['geoposition'].latitude = event_latitude
                event.__dict__['geoposition'].longitude = event_longitude
                event.save()
            else:
                event.__dict__.update(event_data)
                event.save()

            if 'picture' not in event_data:
                event.picture = ''
                event.save()

            # delete old categories and tags and store new ones
            event.audience.clear()
            event.audience.add(*new_audiences)
            event.theme.clear()
            event.theme.add(*new_themes)
            event.tags.set(*event_tags)

    else:
        event = Event.objects.create(**event_data)

        send_email_to_country_ambassadors(event)