# Path: woodstock/models/event.py
# class Event(models.Model, TranslatedObjectMixin, JobUnitMixin, ExtendableMixin):
#     active = models.BooleanField(default=False)
#     slug = models.SlugField(unique=True)
#     date_start = models.DateTimeField(null=True)
#     date_end = models.DateTimeField(null=True)
# 
#     objects = manager_instance
#     default_manager = manager_instance
# 
#     class Meta:
#         ordering = ('date_start',)
#         verbose_name = "Event"
#         verbose_name_plural = "Events"
#         app_label = 'woodstock'
# 
#     def __unicode__(self):
#         try:
#             return self.translation.name
#         except exceptions.ObjectDoesNotExist:
#             return 'no name'
# 
#     def update_dates(self):
#         first_part = self.parts.active().order_by('date_start')[0]
#         self.date_start = first_part.date_start
#         last_part = self.parts.active().order_by('-date_start')[0]
#         self.date_end = last_part.date_end
#         self.save()
# 
#     @models.permalink
#     def get_absolute_url(self):
#         return ('event_detail', (), {
#             'slug': self.slug,
#             })
# 
#     @property
#     def participant_count(self):
#         return Participant.objects.filter(attendances__confirmed=True)\
#                                   .filter(attendances__event_part__event=self)\
#                                   .filter(attendances__event_part__active=True)\
#                                   .distinct().count()
# 
#     def get_participant_count(self):
#         return self.participant_count
#     get_participant_count.short_description = "Participants"
# 
#     @property
#     def available_places(self):
#         return self.max_participants - self.participant_count
# 
#     @property
#     def max_participants(self):
#         if self.parts.active().filter(maximum_participants=0).count():
#             return 0
#         else:
#             return self.parts.active().aggregate(models.Sum('maximum_participants'))['maximum_participants__sum']
# 
#     def get_max_participants(self):
#         return self.max_participants or 'Unlimitiert'
#     get_max_participants.short_description = "Maximum Participants"
# 
#     @property
#     def signable(self):
#         return self.is_signable()
# 
#     def is_signable(self):
#         return self.parts.filter(signable=True).filter(date_start__gt=datetime.datetime.now()).count() > 0
# 
#     # newsletter functions
#     def get_newsletter_receiver_collections(self):
#         collections = tuple()
#         for part in self.parts.all():
#             collections += ((part.name, {'event_part': part.id}),)
#         return collections
# 
#     def get_receiver_filtered_queryset(self, collections=None, **kwargs):
#         from woodstock.models import Participant
# 
#         q = models.Q()
#         all_collections = self.get_newsletter_receiver_collections()
#         for collection in collections:
#             event_part_id = all_collections[int(collection)][1]['event_part']
#             q |= models.Q(attendances__event_part__pk=event_part_id)
#         if kwargs['has_attended']:
#             q &= models.Q(attendances__attended=True)
#         if kwargs['has_not_attended']:
#             q &= models.Q(attendances__attended=False)
#         if kwargs['is_confirmed']:
#             q &= models.Q(attendances__confirmed=True)
#         if kwargs['is_not_confirmed']:
#             q &= models.Q(attendances__confirmed=False)
#         return Participant.objects.filter(q).distinct()
# 
#     def send_subscribe_mail(self, participant):
#         if self.translation.subscribe_mail is None:
#             return
#         self.translation.subscribe_mail.send(participant, group=self)
# 
#     def send_unsubscribe_mail(self, participant):
#         if self.translation.unsubscribe_mail is None:
#             return
#         self.translation.unsubscribe_mail.send(participant, group=self)
# 
#     @classmethod
#     def register_extension(cls, register_fn):
#         register_fn(cls, EventAdmin, EventTranslation, EventTranslationInline, EventPart, EventPartInline)


from django.db import models
from django.template.loader import render_to_string
from woodstock.models import Event



class NextEventsContent(models.Model):
    count = models.IntegerField(default=5)

    class Meta:
        abstract = True
        verbose_name = 'Next Events Content'
        verbose_name_plural = 'Next Events Contents'

    def render(self, **kwargs):

# Path: woodstock/models/event.py
# class Event(models.Model, TranslatedObjectMixin, JobUnitMixin, ExtendableMixin):
#     active = models.BooleanField(default=False)
#     slug = models.SlugField(unique=True)
#     date_start = models.DateTimeField(null=True)
#     date_end = models.DateTimeField(null=True)
# 
#     objects = manager_instance
#     default_manager = manager_instance
# 
#     class Meta:
#         ordering = ('date_start',)
#         verbose_name = "Event"
#         verbose_name_plural = "Events"
#         app_label = 'woodstock'
# 
#     def __unicode__(self):
#         try:
#             return self.translation.name
#         except exceptions.ObjectDoesNotExist:
#             return 'no name'
# 
#     def update_dates(self):
#         first_part = self.parts.active().order_by('date_start')[0]
#         self.date_start = first_part.date_start
#         last_part = self.parts.active().order_by('-date_start')[0]
#         self.date_end = last_part.date_end
#         self.save()
# 
#     @models.permalink
#     def get_absolute_url(self):
#         return ('event_detail', (), {
#             'slug': self.slug,
#             })
# 
#     @property
#     def participant_count(self):
#         return Participant.objects.filter(attendances__confirmed=True)\
#                                   .filter(attendances__event_part__event=self)\
#                                   .filter(attendances__event_part__active=True)\
#                                   .distinct().count()
# 
#     def get_participant_count(self):
#         return self.participant_count
#     get_participant_count.short_description = "Participants"
# 
#     @property
#     def available_places(self):
#         return self.max_participants - self.participant_count
# 
#     @property
#     def max_participants(self):
#         if self.parts.active().filter(maximum_participants=0).count():
#             return 0
#         else:
#             return self.parts.active().aggregate(models.Sum('maximum_participants'))['maximum_participants__sum']
# 
#     def get_max_participants(self):
#         return self.max_participants or 'Unlimitiert'
#     get_max_participants.short_description = "Maximum Participants"
# 
#     @property
#     def signable(self):
#         return self.is_signable()
# 
#     def is_signable(self):
#         return self.parts.filter(signable=True).filter(date_start__gt=datetime.datetime.now()).count() > 0
# 
#     # newsletter functions
#     def get_newsletter_receiver_collections(self):
#         collections = tuple()
#         for part in self.parts.all():
#             collections += ((part.name, {'event_part': part.id}),)
#         return collections
# 
#     def get_receiver_filtered_queryset(self, collections=None, **kwargs):
#         from woodstock.models import Participant
# 
#         q = models.Q()
#         all_collections = self.get_newsletter_receiver_collections()
#         for collection in collections:
#             event_part_id = all_collections[int(collection)][1]['event_part']
#             q |= models.Q(attendances__event_part__pk=event_part_id)
#         if kwargs['has_attended']:
#             q &= models.Q(attendances__attended=True)
#         if kwargs['has_not_attended']:
#             q &= models.Q(attendances__attended=False)
#         if kwargs['is_confirmed']:
#             q &= models.Q(attendances__confirmed=True)
#         if kwargs['is_not_confirmed']:
#             q &= models.Q(attendances__confirmed=False)
#         return Participant.objects.filter(q).distinct()
# 
#     def send_subscribe_mail(self, participant):
#         if self.translation.subscribe_mail is None:
#             return
#         self.translation.subscribe_mail.send(participant, group=self)
# 
#     def send_unsubscribe_mail(self, participant):
#         if self.translation.unsubscribe_mail is None:
#             return
#         self.translation.unsubscribe_mail.send(participant, group=self)
# 
#     @classmethod
#     def register_extension(cls, register_fn):
#         register_fn(cls, EventAdmin, EventTranslation, EventTranslationInline, EventPart, EventPartInline)


# Path: woodstock/content/event/models.py
from django.db import models
from django.template.loader import render_to_string
from woodstock.models import Event




class NextEventsContent(models.Model):
    count = models.IntegerField(default=5)

    class Meta:
        abstract = True
        verbose_name = 'Next Events Content'
        verbose_name_plural = 'Next Events Contents'

    def render(self, **kwargs):

        events = Event.objects.pending()[0:self.count]