# Path: baobab/backoffice/models.py
# class Event(models.Model):
#     objects = EventManager()  # override the default manager
# 
#     # Used for <pubDate> in RSS Feed
#     last_update = models.DateTimeField(default=now)
# 
#     date_start = models.DateTimeField(default=now)
#     date_end = models.DateTimeField(null=True, blank=True, default=None)
#     estimate_date_end = models.DateTimeField()
#     duration = models.PositiveIntegerField(help_text='Duration (in minutes)')
# 
#     # XXX to remove at the next release
#     title = models.CharField(max_length=255,
#                              help_text='A short description of the event')
# 
#     # XXX to remove at the next release
#     summary = models.TextField(null=True, blank=True, default=None)
#     services = models.ManyToManyField('Service', related_name='events',
#                                       blank=True)
#     MAINTENANCE = 0
#     INCIDENT = 1
#     CATEGORY_CHOICES = (
#         (MAINTENANCE, 'Maintenance'),
#         (INCIDENT, 'Incident'),
#     )
#     category = models.PositiveSmallIntegerField(choices=CATEGORY_CHOICES,
#                                                 help_text='Type of the Event')
#     msg = models.CharField('Social Network', max_length=255,
#                            null=True, blank=True, default=None)
# 
#     def __unicode__(self):
#         return self.title
# 
#     def save(self, *args, **kwargs):
#         if not self.id and self.date_end and self.date_end > now():
#             # create an event with a date_end in future: need to be converted
#             # to the estimate_date_end
#             delta = self.date_end - self.date_start
#             self.duration = delta.total_seconds() / 60
#             self.date_end = None
#         if self.date_end:
#             delta = self.date_end - self.date_start
#             self.duration = delta.total_seconds() / 60
#             if not self.estimate_date_end or \
#                self.date_start >= self.estimate_date_end:
#                 self.estimate_date_end = self.date_end
#             if self.date_end <= now():
#                 if self.eventlogs.exists() and \
#                    self.eventlogs.all()[0].date < self.date_end:
#                     self.last_update = self.date_end
#         else:
#             delta = timedelta(minutes=self.duration)
#             self.estimate_date_end = self.date_start + delta
#         super(Event, self).save(*args, **kwargs)
# 
#     class Meta:
#         # XXX avoid the admin to override the right order: see EventQuerySet
#         ordering = ['id', 'pk']
# 
# class EventLog(models.Model):
#     date = models.DateTimeField(default=now)
# 
#     # XXX to remove at the next release
#     comment = models.TextField()
# 
#     event = models.ForeignKey('Event', related_name='eventlogs')
#     user = models.ForeignKey(User, related_name='eventlogs')
#     msg = models.CharField('Social Network', max_length=255,
#                            null=True, blank=True)
# 
#     def save(self, *args, **kwargs):
#         super(EventLog, self).save(*args, **kwargs)
#         self.event.last_update = self.date
#         self.event.save()
# 
#     class Meta:
#         ordering = ['-date', ]
# 
# Path: baobab/socialnetwork/models.py
# class Event(models.Model):
# 
#     event = models.ForeignKey('backoffice.Event')
#     name = models.CharField(max_length=10)
#     sn_id = models.CharField(max_length=30)
# 
#     class Meta:
#         unique_together = ('event', 'name')
# 
# class EventLog(models.Model):
# 
#     eventlog = models.ForeignKey('backoffice.EventLog')
#     name = models.CharField(max_length=10)
#     sn_id = models.CharField(max_length=30)
# 
#     class Meta:
#         unique_together = ('eventlog', 'name')


import logging
from django.conf import settings
from baobab.backoffice.models import (Event as BackOfficeEvent,
                                      EventLog as BackOfficeEventLog)
from baobab.socialnetwork.models import (Event as SnEvent,
                                         EventLog as SnEventLog)

        :rtype: bool
        """

        if isinstance(obj, BackOfficeEvent):
            if SnEvent.objects.filter(event=obj, name=sn_name).exists():
                return True
        else:
            if SnEventLog.objects.filter(eventlog=obj,
                                         name=sn_name).exists():
                return True
        return False

    def _mark_as_publish(self, obj, sn_name, sn_id):
        """
        :param obj: instance of a django's model
        :type obj: BackOfficeEvent or BackOfficeEventLog
        :param sn_name: name of the socialnetwork
        :type sn_name: string
        :param sn_id: socialNetwork id (if any)
        :type sn_id: str
        """

        if isinstance(obj, BackOfficeEvent):
            SnEvent.objects.create(
                event=obj,
                name=sn_name,
                sn_id=sn_id,
            )
        else:

# Path: baobab/backoffice/models.py
# class Event(models.Model):
#     objects = EventManager()  # override the default manager
# 
#     # Used for <pubDate> in RSS Feed
#     last_update = models.DateTimeField(default=now)
# 
#     date_start = models.DateTimeField(default=now)
#     date_end = models.DateTimeField(null=True, blank=True, default=None)
#     estimate_date_end = models.DateTimeField()
#     duration = models.PositiveIntegerField(help_text='Duration (in minutes)')
# 
#     # XXX to remove at the next release
#     title = models.CharField(max_length=255,
#                              help_text='A short description of the event')
# 
#     # XXX to remove at the next release
#     summary = models.TextField(null=True, blank=True, default=None)
#     services = models.ManyToManyField('Service', related_name='events',
#                                       blank=True)
#     MAINTENANCE = 0
#     INCIDENT = 1
#     CATEGORY_CHOICES = (
#         (MAINTENANCE, 'Maintenance'),
#         (INCIDENT, 'Incident'),
#     )
#     category = models.PositiveSmallIntegerField(choices=CATEGORY_CHOICES,
#                                                 help_text='Type of the Event')
#     msg = models.CharField('Social Network', max_length=255,
#                            null=True, blank=True, default=None)
# 
#     def __unicode__(self):
#         return self.title
# 
#     def save(self, *args, **kwargs):
#         if not self.id and self.date_end and self.date_end > now():
#             # create an event with a date_end in future: need to be converted
#             # to the estimate_date_end
#             delta = self.date_end - self.date_start
#             self.duration = delta.total_seconds() / 60
#             self.date_end = None
#         if self.date_end:
#             delta = self.date_end - self.date_start
#             self.duration = delta.total_seconds() / 60
#             if not self.estimate_date_end or \
#                self.date_start >= self.estimate_date_end:
#                 self.estimate_date_end = self.date_end
#             if self.date_end <= now():
#                 if self.eventlogs.exists() and \
#                    self.eventlogs.all()[0].date < self.date_end:
#                     self.last_update = self.date_end
#         else:
#             delta = timedelta(minutes=self.duration)
#             self.estimate_date_end = self.date_start + delta
#         super(Event, self).save(*args, **kwargs)
# 
#     class Meta:
#         # XXX avoid the admin to override the right order: see EventQuerySet
#         ordering = ['id', 'pk']
# 
# class EventLog(models.Model):
#     date = models.DateTimeField(default=now)
# 
#     # XXX to remove at the next release
#     comment = models.TextField()
# 
#     event = models.ForeignKey('Event', related_name='eventlogs')
#     user = models.ForeignKey(User, related_name='eventlogs')
#     msg = models.CharField('Social Network', max_length=255,
#                            null=True, blank=True)
# 
#     def save(self, *args, **kwargs):
#         super(EventLog, self).save(*args, **kwargs)
#         self.event.last_update = self.date
#         self.event.save()
# 
#     class Meta:
#         ordering = ['-date', ]
# 
# Path: baobab/socialnetwork/models.py
# class Event(models.Model):
# 
#     event = models.ForeignKey('backoffice.Event')
#     name = models.CharField(max_length=10)
#     sn_id = models.CharField(max_length=30)
# 
#     class Meta:
#         unique_together = ('event', 'name')
# 
# class EventLog(models.Model):
# 
#     eventlog = models.ForeignKey('backoffice.EventLog')
#     name = models.CharField(max_length=10)
#     sn_id = models.CharField(max_length=30)
# 
#     class Meta:
#         unique_together = ('eventlog', 'name')


# Path: baobab/socialnetwork/base.py
import logging
from django.conf import settings
from baobab.backoffice.models import (Event as BackOfficeEvent,
                                      EventLog as BackOfficeEventLog)
from baobab.socialnetwork.models import (Event as SnEvent,
                                         EventLog as SnEventLog)


        :rtype: bool
        """

        if isinstance(obj, BackOfficeEvent):
            if SnEvent.objects.filter(event=obj, name=sn_name).exists():
                return True
        else:
            if SnEventLog.objects.filter(eventlog=obj,
                                         name=sn_name).exists():
                return True
        return False

    def _mark_as_publish(self, obj, sn_name, sn_id):
        """
        :param obj: instance of a django's model
        :type obj: BackOfficeEvent or BackOfficeEventLog
        :param sn_name: name of the socialnetwork
        :type sn_name: string
        :param sn_id: socialNetwork id (if any)
        :type sn_id: str
        """

        if isinstance(obj, BackOfficeEvent):
            SnEvent.objects.create(
                event=obj,
                name=sn_name,
                sn_id=sn_id,
            )
        else:

            SnEventLog.objects.create(