# Path: letsmeet/events/models.py
# class Event(TimeStampedModel):
#     community = models.ForeignKey('communities.Community', on_delete=models.CASCADE, related_name='events')
#     name = models.CharField(max_length=64)
#     description = models.TextField(null=True, blank=True, help_text="You can write markdown here!")
#     slug = models.SlugField(max_length=64, help_text="Note: changing the slug will change the URL of the event")
#     begin = models.DateTimeField()
#     end = models.DateTimeField()
#     twitter_hashtag = models.CharField(
#         max_length=140, null=True, blank=True, help_text='Twitter hashtag of this event (without leading #)')
#     max_attendees = models.PositiveIntegerField(
#         blank=True, null=True,
#         help_text='Optional maximum number of attendees for this event. Leave blank for no limit.')
#     location = models.ForeignKey('locations.Location', on_delete=models.SET_NULL, related_name='events', null=True, blank=True)
#     publish = models.BooleanField(default=True, help_text='Should this event be published elsewhere?')  # for shackspace blog posts
# 
#     objects = EventManager()
# 
#     def __str__(self):
#         return self.name
# 
#     def is_upcoming(self):
#         return self.end >= timezone.now()
# 
#     def is_past(self):
#         return self.end < timezone.now()
# 
#     def is_full(self):
#         if not self.max_attendees:
#             return False
# 
#         return self.rsvp_yes().count() >= self.max_attendees
# 
#     def rsvp_yes(self):
#         return self.rsvps.filter(coming=True)
# 
#     def rsvp_no(self):
#         return self.rsvps.filter(coming=False)
# 
#     def save(self, *args, **kwargs):
#         create = False
#         if not self.id:
#             create = True
#             # slugify the name
#             slug = "{}-{}".format(slugify(self.name), str(self.begin.date()))
#             if Event.objects.filter(slug=slug, community=self.community):
#                 # use datetime, because date was not unique
#                 slug = "{}-{}".format(slugify(self.name), slugify(self.begin))
#             self.slug = slug
# 
#         super().save(*args, **kwargs)
# 
#         if create:
#             recipients = self.community.subscribers.filter(
#                 userprofile__notify_on_new_event=True,
#             )
#             # send notification mail to all subscribers
#             if recipients:
#                 from main.utils import send_notification
#                 send_notification(
#                     recipients=recipients,
#                     subject='New event in community {}'.format(self.name),
#                     template='events/mails/new_event.txt',
#                     context={'event': self},
#                 )
# 
#     def get_absolute_url(self):
#         return reverse('event_detail', kwargs={'slug': self.slug,
#                                                'community_slug': self.community.slug})
# 
#     def get_update_url(self):
#         return reverse('event_update', kwargs={'slug': self.slug,
#                                                'community_slug': self.community.slug})
# 
#     def get_comment_create_url(self):
#         return reverse('eventcomment_create', kwargs={
#             'slug': self.slug, 'community_slug': self.community.slug})
# 
#     def get_rsvp_yes_url(self):
#         return reverse('event_rsvp', kwargs={'slug': self.slug,
#                                              'community_slug': self.community.slug,
#                                              'answer': 'yes'})
# 
#     def get_rsvp_no_url(self):
#         return reverse('event_rsvp', kwargs={'slug': self.slug,
#                                              'community_slug': self.community.slug,
#                                              'answer': 'no'})
# 
#     def get_rsvp_reset_url(self):
#         return reverse('event_rsvp', kwargs={'slug': self.slug,
#                                              'community_slug': self.community.slug,
#                                              'answer': 'reset'})
# 
#     class Meta:
#         ordering = ['begin', 'name']
#         unique_together = ('community', 'slug')


import json
from django.contrib.auth import get_user_model
from django.contrib.syndication.views import Feed
from django.core.serializers.json import DjangoJSONEncoder
from django.http import HttpResponse
from django.shortcuts import get_object_or_404
from django.utils.feedgenerator import SyndicationFeed
from django_ical.views import ICalFeed
from .models import Event
        from communities.models import Community
        from communities.models import Community
        return Event.objects.filter(community=obj).order_by('-created')

    def item_title(self, item):
        return item.name

    def item_description(self, item):
        return item.description

    def item_pubdate(self, item):
        return item.created


class ICalCommunityEventsFeed(ICalFeed):
    description = "letsmeet.click community events feed"
    product_id = '-//letsmeet.click//Event//DE'
    timezone = 'UTC'

    def title(self, obj):
        return "{} calendar".format(obj.name)

    def file_name(self, obj):
        return "feed_{}.ics".format(obj.slug)

    def get_object(self, request, community_slug):
        try:
            return Community.objects.get(slug=community_slug)
        except Community.DoesNotExist:
            return []

    def items(self, obj):

# Path: letsmeet/events/models.py
# class Event(TimeStampedModel):
#     community = models.ForeignKey('communities.Community', on_delete=models.CASCADE, related_name='events')
#     name = models.CharField(max_length=64)
#     description = models.TextField(null=True, blank=True, help_text="You can write markdown here!")
#     slug = models.SlugField(max_length=64, help_text="Note: changing the slug will change the URL of the event")
#     begin = models.DateTimeField()
#     end = models.DateTimeField()
#     twitter_hashtag = models.CharField(
#         max_length=140, null=True, blank=True, help_text='Twitter hashtag of this event (without leading #)')
#     max_attendees = models.PositiveIntegerField(
#         blank=True, null=True,
#         help_text='Optional maximum number of attendees for this event. Leave blank for no limit.')
#     location = models.ForeignKey('locations.Location', on_delete=models.SET_NULL, related_name='events', null=True, blank=True)
#     publish = models.BooleanField(default=True, help_text='Should this event be published elsewhere?')  # for shackspace blog posts
# 
#     objects = EventManager()
# 
#     def __str__(self):
#         return self.name
# 
#     def is_upcoming(self):
#         return self.end >= timezone.now()
# 
#     def is_past(self):
#         return self.end < timezone.now()
# 
#     def is_full(self):
#         if not self.max_attendees:
#             return False
# 
#         return self.rsvp_yes().count() >= self.max_attendees
# 
#     def rsvp_yes(self):
#         return self.rsvps.filter(coming=True)
# 
#     def rsvp_no(self):
#         return self.rsvps.filter(coming=False)
# 
#     def save(self, *args, **kwargs):
#         create = False
#         if not self.id:
#             create = True
#             # slugify the name
#             slug = "{}-{}".format(slugify(self.name), str(self.begin.date()))
#             if Event.objects.filter(slug=slug, community=self.community):
#                 # use datetime, because date was not unique
#                 slug = "{}-{}".format(slugify(self.name), slugify(self.begin))
#             self.slug = slug
# 
#         super().save(*args, **kwargs)
# 
#         if create:
#             recipients = self.community.subscribers.filter(
#                 userprofile__notify_on_new_event=True,
#             )
#             # send notification mail to all subscribers
#             if recipients:
#                 from main.utils import send_notification
#                 send_notification(
#                     recipients=recipients,
#                     subject='New event in community {}'.format(self.name),
#                     template='events/mails/new_event.txt',
#                     context={'event': self},
#                 )
# 
#     def get_absolute_url(self):
#         return reverse('event_detail', kwargs={'slug': self.slug,
#                                                'community_slug': self.community.slug})
# 
#     def get_update_url(self):
#         return reverse('event_update', kwargs={'slug': self.slug,
#                                                'community_slug': self.community.slug})
# 
#     def get_comment_create_url(self):
#         return reverse('eventcomment_create', kwargs={
#             'slug': self.slug, 'community_slug': self.community.slug})
# 
#     def get_rsvp_yes_url(self):
#         return reverse('event_rsvp', kwargs={'slug': self.slug,
#                                              'community_slug': self.community.slug,
#                                              'answer': 'yes'})
# 
#     def get_rsvp_no_url(self):
#         return reverse('event_rsvp', kwargs={'slug': self.slug,
#                                              'community_slug': self.community.slug,
#                                              'answer': 'no'})
# 
#     def get_rsvp_reset_url(self):
#         return reverse('event_rsvp', kwargs={'slug': self.slug,
#                                              'community_slug': self.community.slug,
#                                              'answer': 'reset'})
# 
#     class Meta:
#         ordering = ['begin', 'name']
#         unique_together = ('community', 'slug')


# Path: letsmeet/events/feeds.py
import json
from django.contrib.auth import get_user_model
from django.contrib.syndication.views import Feed
from django.core.serializers.json import DjangoJSONEncoder
from django.http import HttpResponse
from django.shortcuts import get_object_or_404
from django.utils.feedgenerator import SyndicationFeed
from django_ical.views import ICalFeed
from .models import Event
        from communities.models import Community
        from communities.models import Community

        return Event.objects.filter(community=obj).order_by('-created')

    def item_title(self, item):
        return item.name

    def item_description(self, item):
        return item.description

    def item_pubdate(self, item):
        return item.created


class ICalCommunityEventsFeed(ICalFeed):
    description = "letsmeet.click community events feed"
    product_id = '-//letsmeet.click//Event//DE'
    timezone = 'UTC'

    def title(self, obj):
        return "{} calendar".format(obj.name)

    def file_name(self, obj):
        return "feed_{}.ics".format(obj.slug)

    def get_object(self, request, community_slug):
        try:
            return Community.objects.get(slug=community_slug)
        except Community.DoesNotExist:
            return []

    def items(self, obj):

        return Event.objects.filter(community=obj).order_by('-created')