# coding=utf-8
"""Docstring for this file."""
__author__ = 'ismailsunni'
__project_name = 'watchkeeper'
__filename = 'event'
__date__ = '4/10/15'
__copyright__ = 'imajimatika@gmail.com'
__doc__ = ''

from django.contrib.gis.db import models

from event_type import EventType
from perpetrator import Perpetrator
from victim import Victim

from event_mapper.models.user import User


class Event(models.Model):
    """Event model."""

    class Meta:
        """Meta Class"""
        app_label = 'event_mapper'

    INCIDENT_CODE = 1
    ADVISORY_CODE = 2

    CATEGORY_CHOICES = (
        (INCIDENT_CODE, 'Incident'),
        (ADVISORY_CODE, 'Advisory'),
    )

    category = models.IntegerField(
        choices=CATEGORY_CHOICES,
        verbose_name='Category of the event',
        help_text='There are two event categories: Incident and Advisory'
    )

    location = models.PointField(
        verbose_name='Location',
        help_text='The location of the event in point geometry',
        srid=4326,
        null=False,
        blank=False
    )

    place_name = models.CharField(
        verbose_name='Place name',
        help_text='The name of the event location.',
        max_length=100
    )

    date_time = models.DateTimeField(
        verbose_name='Date and time',
        help_text='Date and time when the event happened.'
    )

    type = models.ForeignKey(
        EventType,
        verbose_name='Event type',
        help_text='The type of the event.'
    )

    perpetrator = models.ForeignKey(
        Perpetrator,
        verbose_name='Perpetrator',
        help_text='The perpetrator of the event.',
        blank=True,
        null=True
    )

    victim = models.ForeignKey(
        Victim,
        verbose_name='Victim',
        help_text='The victim of the event.',
        blank=True,
        null=True
    )

    killed = models.IntegerField(
        verbose_name='Killed people',
        help_text='The number of killed people of the incident.',
        default=0,
        blank=True
    )

    injured = models.IntegerField(
        verbose_name='Injured people',
        help_text='The number of injured people of the incident.',
        default=0,
        blank=True
    )

    detained = models.IntegerField(
        verbose_name='Detained people',
        help_text='The number of detained people of the incident.',
        default=0,
        blank=True
    )

    source = models.TextField(
        verbose_name='Source',
        help_text='The source where the event comes from.',
        blank=True,
    )

    notes = models.TextField(
        verbose_name='Notes',
        help_text='Additional notes for the event.',
        blank=True,
        null=True
    )

    reported_by = models.ForeignKey(
        User,
        verbose_name='Event Reporter',
        help_text='The user who reports the event.'
    )

    notified_immediately = models.BooleanField(
        verbose_name='Notify Immediately',
        help_text='If selected, there will be immediate notification.',
        default=False
    )

    notification_sent = models.BooleanField(
        verbose_name='Notification Sent',
        help_text='If selected, a notification has been sent for this event.',
        default=False
    )

    objects = models.GeoManager()

    def __str__(self):
        return '%s of %s by %s' % (
            self.get_category_display(), self.type.name, self.perpetrator.name)

    def save(self, *args, **kwargs):
        super(Event, self).save(*args, **kwargs)

    def long_message(self):
        return '%s was reported at %s %s' % (
            self.__str__(),
            self.place_name,
            self.location.get_coords())
@@ -3289,32 +3289,65 @@
  __str__(self):%0A
+        if self.perpetrator:%0A    
         return '
@@ -3358,32 +3358,36 @@
 f %25s by %25s' %25 (%0A
+    
             self
@@ -3414,46 +3414,229 @@
 y(),
- self.type.name, self.perpetrator.name
+%0A                self.type.name,%0A                self.perpetrator.name%0A            )%0A        else:%0A            return '%25s of %25s' %25 (%0A                self.get_category_display(),%0A                self.type.name%0A            
 )%0A%0A 
@@ -3848,24 +3848,24 @@
 place_name,%0A
-
             
@@ -3891,8 +3891,9 @@
 oords())
+%0A

Fix #83