# Path: app/rules_engine/models.py
# class ElementSuppressor(models.Model):
#     """
#     Suppress an element
#     """
#     element = models.CharField(db_index=True, max_length=255)
#     suppressed_by = models.ForeignKey(User)
#     date_added = models.DateTimeField(auto_now_add=True)
#     start_time = models.DateTimeField(null=True, blank=True)
#     end_time = models.DateTimeField(null=True, blank=True)
# 
#     def __unicode__(self):
#         return unicode('%s|%s' % (self.element, self.suppressed_by))
# 
# class EventSuppressor(models.Model):
#     """
#     Suppress an event
#     """
#     event = models.ForeignKey(Event, db_index=True)
#     suppressed_by = models.ForeignKey(User)
#     date_added = models.DateTimeField(auto_now_add=True)
#     start_time = models.DateTimeField(null=True, blank=True)
#     end_time = models.DateTimeField(null=True, blank=True)
# 
#     def __unicode__(self):
#         return unicode('%s|%s' % (self.event, self.suppressed_by))
# 
# class EventAndElementSuppressor(models.Model):
#     """
#     Suppresses an Event + Element combination
#     """
#     event = models.ForeignKey(Event, db_index=True)
#     element = models.CharField(db_index=True, max_length=255)
#     suppressed_by = models.ForeignKey(User)
#     date_added = models.DateTimeField(auto_now_add=True)
#     start_time = models.DateTimeField(null=True, blank=True)
#     end_time = models.DateTimeField(null=True, blank=True)
# 
#     def __unicode__(self):
#         return unicode('%s|%s|%s' % (self.element, self.event, self.suppressed_by))


from django import forms
from cito_engine.models import Event
from .models import ElementSuppressor, EventSuppressor, EventAndElementSuppressor
            self._errors['eventid'] = self.error_class([msg])
            self._errors['element'] = self.error_class([msg])
            return cleaned_data

        if suppression_type == '1':
            if not self.is_event_valid(eventid):
                self._errors['eventid'] = self.error_class([u'EventID does not exist'])

            elif EventSuppressor.objects.filter(event__pk=eventid).exists():
                self._errors['eventid'] = self.error_class([u'This EventID is already suppressed.'])

        if suppression_type == '2':
            if ElementSuppressor.objects.filter(element=element).exists():
                self._errors['element'] = self.error_class([u'This Element is already suppressed.'])

        if suppression_type == '3':
            if not self.is_event_valid(eventid):
                self._errors['eventid'] = self.error_class([u'EventID does not exist'])
                return cleaned_data
            elif EventAndElementSuppressor.objects.filter(event__pk=eventid, element=element).exists():
                msg = u'This EventID and Element combination are already suppressed.'
                self._errors['eventid'] = self.error_class([msg])
                self._errors['element'] = self.error_class([msg])

        return cleaned_data

    def save(self, user):
        cleaned_data = self.clean()
        # Add Event Suppression
        if cleaned_data.get('suppression_type') == '1':

# Path: app/rules_engine/models.py
# class ElementSuppressor(models.Model):
#     """
#     Suppress an element
#     """
#     element = models.CharField(db_index=True, max_length=255)
#     suppressed_by = models.ForeignKey(User)
#     date_added = models.DateTimeField(auto_now_add=True)
#     start_time = models.DateTimeField(null=True, blank=True)
#     end_time = models.DateTimeField(null=True, blank=True)
# 
#     def __unicode__(self):
#         return unicode('%s|%s' % (self.element, self.suppressed_by))
# 
# class EventSuppressor(models.Model):
#     """
#     Suppress an event
#     """
#     event = models.ForeignKey(Event, db_index=True)
#     suppressed_by = models.ForeignKey(User)
#     date_added = models.DateTimeField(auto_now_add=True)
#     start_time = models.DateTimeField(null=True, blank=True)
#     end_time = models.DateTimeField(null=True, blank=True)
# 
#     def __unicode__(self):
#         return unicode('%s|%s' % (self.event, self.suppressed_by))
# 
# class EventAndElementSuppressor(models.Model):
#     """
#     Suppresses an Event + Element combination
#     """
#     event = models.ForeignKey(Event, db_index=True)
#     element = models.CharField(db_index=True, max_length=255)
#     suppressed_by = models.ForeignKey(User)
#     date_added = models.DateTimeField(auto_now_add=True)
#     start_time = models.DateTimeField(null=True, blank=True)
#     end_time = models.DateTimeField(null=True, blank=True)
# 
#     def __unicode__(self):
#         return unicode('%s|%s|%s' % (self.element, self.event, self.suppressed_by))


# Path: app/rules_engine/forms.py
from django import forms
from cito_engine.models import Event
from .models import ElementSuppressor, EventSuppressor, EventAndElementSuppressor

            self._errors['eventid'] = self.error_class([msg])
            self._errors['element'] = self.error_class([msg])
            return cleaned_data

        if suppression_type == '1':
            if not self.is_event_valid(eventid):
                self._errors['eventid'] = self.error_class([u'EventID does not exist'])

            elif EventSuppressor.objects.filter(event__pk=eventid).exists():
                self._errors['eventid'] = self.error_class([u'This EventID is already suppressed.'])

        if suppression_type == '2':
            if ElementSuppressor.objects.filter(element=element).exists():
                self._errors['element'] = self.error_class([u'This Element is already suppressed.'])

        if suppression_type == '3':
            if not self.is_event_valid(eventid):
                self._errors['eventid'] = self.error_class([u'EventID does not exist'])
                return cleaned_data
            elif EventAndElementSuppressor.objects.filter(event__pk=eventid, element=element).exists():
                msg = u'This EventID and Element combination are already suppressed.'
                self._errors['eventid'] = self.error_class([msg])
                self._errors['element'] = self.error_class([msg])

        return cleaned_data

    def save(self, user):
        cleaned_data = self.clean()
        # Add Event Suppression
        if cleaned_data.get('suppression_type') == '1':

            EventSuppressor.objects.create(event=self.event,