# Path: happenings/signals.py
# def update_time(sender, **kwargs):
#     """
#     When a Comment is added, updates the Update to set "last_updated" time
#     """
#     comment = kwargs['instance']
#     if comment.content_type.app_label == "happenings" and comment.content_type.name == "Update":
#         from .models import Update
#         item = Update.objects.get(id=comment.object_pk)
#         item.save()


import datetime
import os
import zipfile
from io import BytesIO
from itertools import chain
from PIL import Image as PIL_Image
from django.conf import settings
from django.contrib.contenttypes.models import ContentType
from django.core.files.uploadedfile import SimpleUploadedFile
from django.db import models
from django.db.models import signals, Q
from django.urls import reverse
from django.utils.functional import cached_property
from tango_shared.models import ContentImage, BaseUserContentModel, BaseSidebarContentModel
from tango_shared.utils.maptools import get_geocode
from tango_shared.utils.sanetize import sanetize_text
from .signals import update_time
    from tango_comments.models import Comment
                try:
                    img_file = SimpleUploadedFile(clean_filename, temp_handle.read(), 'image/jpeg',)
                except Exception:
                    img_file = None
                if img_file is not None:
                    try:
                        Image.objects.get(image=dirstring + clean_filename)
                    except Image.DoesNotExist:
                        new_img = Image(
                            event=self.event,
                            image=img_file,
                        )
                        new_img.save()
        return  # note that we're not actually saving the zip. No good reason to.


if supports_video:

    class EventVideo(models.Model):
        video = models.ForeignKey(
            'video.Video',
            on_delete=models.CASCADE,
            related_name="event_video"
        )
        event = models.ForeignKey(
            Event,
            on_delete=models.CASCADE
        )

if supports_comments:

# Path: happenings/signals.py
# def update_time(sender, **kwargs):
#     """
#     When a Comment is added, updates the Update to set "last_updated" time
#     """
#     comment = kwargs['instance']
#     if comment.content_type.app_label == "happenings" and comment.content_type.name == "Update":
#         from .models import Update
#         item = Update.objects.get(id=comment.object_pk)
#         item.save()


# Path: happenings/models.py
import datetime
import os
import zipfile
from io import BytesIO
from itertools import chain
from PIL import Image as PIL_Image
from django.conf import settings
from django.contrib.contenttypes.models import ContentType
from django.core.files.uploadedfile import SimpleUploadedFile
from django.db import models
from django.db.models import signals, Q
from django.urls import reverse
from django.utils.functional import cached_property
from tango_shared.models import ContentImage, BaseUserContentModel, BaseSidebarContentModel
from tango_shared.utils.maptools import get_geocode
from tango_shared.utils.sanetize import sanetize_text
from .signals import update_time
    from tango_comments.models import Comment

                try:
                    img_file = SimpleUploadedFile(clean_filename, temp_handle.read(), 'image/jpeg',)
                except Exception:
                    img_file = None
                if img_file is not None:
                    try:
                        Image.objects.get(image=dirstring + clean_filename)
                    except Image.DoesNotExist:
                        new_img = Image(
                            event=self.event,
                            image=img_file,
                        )
                        new_img.save()
        return  # note that we're not actually saving the zip. No good reason to.


if supports_video:

    class EventVideo(models.Model):
        video = models.ForeignKey(
            'video.Video',
            on_delete=models.CASCADE,
            related_name="event_video"
        )
        event = models.ForeignKey(
            Event,
            on_delete=models.CASCADE
        )

if supports_comments:

    signals.post_save.connect(update_time, sender=Comment)