<commit_before># coding=utf-8
"""Docstring for this file."""
__author__ = 'ismailsunni'
__project_name = 'watchkeeper'
__filename = 'event'
__date__ = '4/10/15'
__copyright__ = '<EMAIL>'
__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):
        if self.perpetrator:
            return '%s of %s by %s' % (
                self.get_category_display(),
                self.type.name,
                self.perpetrator.name
            )
        else:
            return '%s of %s' % (
                self.get_category_display(),
                self.type.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())<commit_msg>Fix AttributeError.<commit_after># coding=utf-8
"""Docstring for this file."""
__author__ = 'ismailsunni'
__project_name = 'watchkeeper'
__filename = 'event'
__date__ = '4/10/15'
__copyright__ = '<EMAIL>'
__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):
        try:
            return '%s of %s by %s' % (
                self.get_category_display(),
                self.type.name,
                self.perpetrator.name
            )
        except AttributeError:
            return '%s of %s' % (
                self.get_category_display(),
                self.type.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())
{'fraction_non_alphanumeric': 0.09784135904968706, 'fraction_numerical': 0.004598288414867799, 'mean_word_length': 2.1700404858299596, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5145893', 'n_tokens_mistral': 2325, 'n_tokens_neox': 2191, 'n_words': 564}