Newer
Older
Branson Stephens
committed
from django.db import models, IntegrityError

Tanner Prestegard
committed
from django.core.exceptions import ValidationError
from django.utils import six
from django.utils.encoding import python_2_unicode_compatible

Tanner Prestegard
committed
from django.utils.translation import ugettext_lazy as _
from model_utils.managers import InheritanceManager

Tanner Prestegard
committed
from django.contrib.auth import get_user_model

Branson Craig Stephens
committed
from django.contrib.contenttypes.models import ContentType

Tanner Prestegard
committed
from guardian.models import GroupObjectPermission
import logging; log = logging.getLogger(__name__)
import glue
import glue.ligolw
import glue.ligolw.utils
import glue.ligolw.table
import glue.ligolw.lsctables
from glue.ligolw.ligolw import LIGOLWContentHandler

Tanner Prestegard
committed
import json, re

Branson Craig Stephens
committed

Tanner Prestegard
committed
from core.models import AutoIncrementModel, CleanSaveModel
from core.models import LogBase, m2mThroughBase
from django.conf import settings
import pytz
import calendar
try:
from StringIO import StringIO
except ImportError: # python >= 3
from io import StringIO
from hashlib import sha1

Tanner Prestegard
committed
import shutil
from .managers import ProductionPipelineManager, ExternalPipelineManager

Tanner Prestegard
committed
UserModel = get_user_model()
SERVER_TZ = pytz.timezone(settings.TIME_ZONE)
# Let's say we start here on schema versions
#
# 1.0 -> 1.1 changed EventLog.comment from CharField(length=200) -> TextField
#
schema_version = "1.1"
@python_2_unicode_compatible
class Group(models.Model):
name = models.CharField(max_length=20)
def __str__(self):
return six.text_type(self.name)
@python_2_unicode_compatible
class Pipeline(models.Model):
PIPELINE_TYPE_EXTERNAL = 'E'
PIPELINE_TYPE_OTHER = 'O'
PIPELINE_TYPE_SEARCH_OTHER = 'SO'
PIPELINE_TYPE_SEARCH_PRODUCTION = 'SP'
PIPELINE_TYPE_CHOICES = (
(PIPELINE_TYPE_EXTERNAL, 'external'),
(PIPELINE_TYPE_OTHER, 'other'),
(PIPELINE_TYPE_SEARCH_OTHER, 'non-production search'),
(PIPELINE_TYPE_SEARCH_PRODUCTION, 'production search'),
)
name = models.CharField(max_length=100)
# Are submissions allowed for this pipeline?
enabled = models.BooleanField(default=True)
# Pipeline type
pipeline_type = models.CharField(max_length=2,
choices=PIPELINE_TYPE_CHOICES)
# Add custom managers; must manually define 'objects' as well
objects = models.Manager()
production_objects = ProductionPipelineManager()
external_objects = ExternalPipelineManager()
class Meta:
permissions = (
('manage_pipeline', 'Can enable or disable pipeline'),
)
def __str__(self):
return six.text_type(self.name)
class PipelineLog(models.Model):
PIPELINE_LOG_ACTION_DISABLE = 'D'
PIPELINE_LOG_ACTION_ENABLE = 'E'
PIPELINE_LOG_ACTION_CHOICES = (
(PIPELINE_LOG_ACTION_DISABLE, 'disable'),
(PIPELINE_LOG_ACTION_ENABLE, 'enable'),
)
creator = models.ForeignKey(UserModel)
pipeline = models.ForeignKey(Pipeline)
created = models.DateTimeField(auto_now_add=True)
action = models.CharField(max_length=10,
choices=PIPELINE_LOG_ACTION_CHOICES)
@python_2_unicode_compatible
class Search(models.Model):
name = models.CharField(max_length=100)
description = models.TextField(blank=True)
# XXX Need any additional fields? Like a PI email? Or perhaps even fk?
def __str__(self):
return six.text_type(self.name)
# Label color will be used in CSS, see
# https://www.w3schools.com/colors/colors_names.asp for
# allowed color choices
@python_2_unicode_compatible
name = models.CharField(max_length=20, unique=True)
# XXX really, does this belong here? probably not.

Tanner Prestegard
committed
defaultColor = models.CharField(max_length=20, unique=False,
default="black")
description = models.TextField(blank=False)
# protected = True means that the Label should not be "writeable": i.e.,
# users should not be able to directly apply or remove it. This is useful
# for labels that are added and removed as part of a process, like
# signoffs, for examples.
protected = models.BooleanField(default=False)

Tanner Prestegard
committed
def __str__(self):
return six.text_type(self.name)
class ProtectedLabelError(Exception):
# To be raised when an attempt is made to apply or remove a
# protected label to/from an event or superevent
pass
class RelatedSignoffExistsError(Exception):
# To be raised when an attempt is made to apply a "signoff request"
# label (like ADVREQ, H1OPS, etc.) when a signoff of that type already
# exists (example: an advocate signoff exists and ADVOK or ADVNO is
# applied, but a user tries to apply 'ADVREQ')
pass
@python_2_unicode_compatible
objects = InheritanceManager() # Queries can return subclasses, if available.
# ANALYSIS_TYPE_CHOICES = (
# ("LM", "LowMass"),
# ("HM", "HighMass"),
# ("GRB", "GRB"),
# ("RD", "Ringdown"),
# ("OM", "Omega"),
# ("Q", "Q"),
# ("X", "X"),
# ("CWB", "CWB"),
# ("MBTA", "MBTAOnline"),
# ("HWINJ", "HardwareInjection"),
# )
DEFAULT_EVENT_NEIGHBORHOOD = (-5,5)

Tanner Prestegard
committed
submitter = models.ForeignKey(UserModel)
created = models.DateTimeField(auto_now_add=True)
group = models.ForeignKey(Group)
#uid = models.CharField(max_length=20, default="") # XXX deprecated. should be removed.
#analysisType = models.CharField(max_length=20, choices=ANALYSIS_TYPE_CHOICES)

Tanner Prestegard
committed
# Events aren't required to be part of a superevent. If the superevent is
# deleted, don't delete the event; just set this FK to null.
superevent = models.ForeignKey('superevents.Superevent', null=True,
related_name='events', on_delete=models.SET_NULL)

Tanner Prestegard
committed
# Note: a default value is needed only during the schema migration
# that creates this column. After that, we can safely remove it.
# The presence or absence of the default value has no effect on the DB
# tables, so removing it does not necessitate a migration.
pipeline = models.ForeignKey(Pipeline)
search = models.ForeignKey(Search, null=True)
instruments = models.CharField(max_length=20, default="")
nevents = models.PositiveIntegerField(null=True)
likelihood = models.FloatField(null=True)
# NOT from coinc_event, but so, so common.
Loading
Loading full blame...