Skip to content

Commit

Permalink
fix: constants
Browse files Browse the repository at this point in the history
  • Loading branch information
gromdimon committed Jul 19, 2023
1 parent d632fb7 commit c3e6c62
Show file tree
Hide file tree
Showing 32 changed files with 229 additions and 167 deletions.
3 changes: 2 additions & 1 deletion irodsadmin/management/commands/irodsorphans.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from projectroles.plugins import get_backend_api

# Landingzones dependency
from landingzones.constants import ZONE_STATUS_MOVED, ZONE_STATUS_DELETED
from landingzones.models import LandingZone

# Samplesheets dependency
Expand Down Expand Up @@ -84,7 +85,7 @@ def get_zone_collections(irods_backend):
return [
irods_backend.get_path(lz)
for lz in LandingZone.objects.filter(
~(Q(status='MOVED') & Q(status='DELETED'))
~(Q(status=ZONE_STATUS_MOVED) & Q(status=ZONE_STATUS_DELETED))
)
]

Expand Down
91 changes: 91 additions & 0 deletions landingzones/constants.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
"""Constants for the landingzones app"""

# Status types for landing zones
ZONE_STATUS_OK = 'OK'
ZONE_STATUS_CREATING = 'CREATING'
ZONE_STATUS_NOT_CREATED = 'NOT CREATED'
ZONE_STATUS_ACTIVE = 'ACTIVE'
ZONE_STATUS_PREPARING = 'PREPARING'
ZONE_STATUS_VALIDATING = 'VALIDATING'
ZONE_STATUS_MOVING = 'MOVING'
ZONE_STATUS_MOVED = 'MOVED'
ZONE_STATUS_FAILED = 'FAILED'
ZONE_STATUS_DELETING = 'DELETING'
ZONE_STATUS_DELETED = 'DELETED'

ZONE_STATUS_TYPES = [
ZONE_STATUS_CREATING,
ZONE_STATUS_NOT_CREATED,
ZONE_STATUS_ACTIVE,
ZONE_STATUS_PREPARING,
ZONE_STATUS_VALIDATING,
ZONE_STATUS_MOVING,
ZONE_STATUS_MOVED,
ZONE_STATUS_FAILED,
ZONE_STATUS_DELETING,
ZONE_STATUS_DELETED,
]

DEFAULT_STATUS_INFO = {
ZONE_STATUS_CREATING: 'Creating landing zone in iRODS',
ZONE_STATUS_NOT_CREATED: 'Creating landing zone in iRODS failed (unknown problem)',
ZONE_STATUS_ACTIVE: 'Available with write access for user',
ZONE_STATUS_PREPARING: 'Preparing transaction for validation and moving',
ZONE_STATUS_VALIDATING: 'Validation in progress, write access disabled',
ZONE_STATUS_MOVING: 'Validation OK, moving files into sample data repository',
ZONE_STATUS_MOVED: 'Files moved successfully, landing zone removed',
ZONE_STATUS_FAILED: 'Validation/moving failed (unknown problem)',
ZONE_STATUS_DELETING: 'Deleting landing zone',
ZONE_STATUS_DELETED: 'Landing zone deleted',
}
STATUS_INFO_DELETE_NO_COLL = (
'No iRODS collection for zone found, marked as deleted'
)

STATUS_STYLES = {
ZONE_STATUS_CREATING: 'bg-warning',
ZONE_STATUS_NOT_CREATED: 'bg-danger',
ZONE_STATUS_ACTIVE: 'bg-info',
ZONE_STATUS_PREPARING: 'bg-warning',
ZONE_STATUS_VALIDATING: 'bg-warning',
ZONE_STATUS_MOVING: 'bg-warning',
ZONE_STATUS_MOVED: 'bg-success',
ZONE_STATUS_FAILED: 'bg-danger',
ZONE_STATUS_DELETING: 'bg-warning',
ZONE_STATUS_DELETED: 'bg-secondary',
}

# Status types for which zone validation, moving and deletion are allowed
STATUS_ALLOW_UPDATE = [ZONE_STATUS_ACTIVE, ZONE_STATUS_FAILED]

# Status types for zones for which activities have finished
STATUS_FINISHED = [
ZONE_STATUS_MOVED,
ZONE_STATUS_NOT_CREATED,
ZONE_STATUS_DELETED,
]

# Status types which lock the project in Taskflow
STATUS_LOCKING = [
ZONE_STATUS_PREPARING,
ZONE_STATUS_VALIDATING,
ZONE_STATUS_MOVING,
]

# Status types for busy landing zones
STATUS_BUSY = [
ZONE_STATUS_CREATING,
ZONE_STATUS_PREPARING,
ZONE_STATUS_VALIDATING,
ZONE_STATUS_MOVING,
ZONE_STATUS_DELETING,
]

# Status types during which file lists and stats should be displayed
STATUS_DISPLAY_FILES = [
ZONE_STATUS_ACTIVE,
ZONE_STATUS_PREPARING,
ZONE_STATUS_VALIDATING,
ZONE_STATUS_MOVING,
ZONE_STATUS_FAILED,
]
3 changes: 2 additions & 1 deletion landingzones/management/commands/busyzones.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
# Projectroles dependency
from projectroles.management.logging import ManagementCommandLogger

from landingzones.models import LandingZone, STATUS_BUSY
from landingzones.constants import STATUS_BUSY
from landingzones.models import LandingZone


logger = ManagementCommandLogger(__name__)
Expand Down
3 changes: 2 additions & 1 deletion landingzones/management/commands/inactivezones.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from projectroles.management.logging import ManagementCommandLogger
from projectroles.plugins import get_backend_api

from landingzones.constants import ZONE_STATUS_MOVED, ZONE_STATUS_DELETED
from landingzones.models import LandingZone


Expand All @@ -20,7 +21,7 @@ def get_inactive_zones(weeks=2):
"""Return landing zones last modified over n weeks ago"""
return LandingZone.objects.filter(
date_modified__lte=localtime() - timedelta(weeks=weeks)
).exclude(status__in=('DELETED', 'MOVED'))
).exclude(status__in=(ZONE_STATUS_MOVED, ZONE_STATUS_DELETED))


def get_output(zones, irods_backend, irods):
Expand Down
85 changes: 8 additions & 77 deletions landingzones/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,81 +9,12 @@
# Samplesheets dependency
from samplesheets.models import Assay

import landingzones.constants as lc

# Access Django user model
AUTH_USER_MODEL = getattr(settings, 'AUTH_USER_MODEL', 'auth.User')


# Status types for landing zones
ZONE_STATUS_OK = 'OK'
ZONE_STATUS_CREATING = 'CREATING'
ZONE_STATUS_NOT_CREATED = 'NOT CREATED'
ZONE_STATUS_ACTIVE = 'ACTIVE'
ZONE_STATUS_PREPARING = 'PREPARING'
ZONE_STATUS_VALIDATING = 'VALIDATING'
ZONE_STATUS_MOVING = 'MOVING'
ZONE_STATUS_MOVED = 'MOVED'
ZONE_STATUS_FAILED = 'FAILED'
ZONE_STATUS_DELETING = 'DELETING'
ZONE_STATUS_DELETED = 'DELETED'

ZONE_STATUS_TYPES = [
ZONE_STATUS_CREATING,
ZONE_STATUS_NOT_CREATED,
ZONE_STATUS_ACTIVE,
ZONE_STATUS_PREPARING,
ZONE_STATUS_VALIDATING,
ZONE_STATUS_MOVING,
ZONE_STATUS_MOVED,
ZONE_STATUS_FAILED,
ZONE_STATUS_DELETING,
ZONE_STATUS_DELETED,
]

DEFAULT_STATUS_INFO = {
ZONE_STATUS_CREATING: 'Creating landing zone in iRODS',
ZONE_STATUS_NOT_CREATED: 'Creating landing zone in iRODS failed (unknown problem)',
ZONE_STATUS_ACTIVE: 'Available with write access for user',
ZONE_STATUS_PREPARING: 'Preparing transaction for validation and moving',
ZONE_STATUS_VALIDATING: 'Validation in progress, write access disabled',
ZONE_STATUS_MOVING: 'Validation OK, moving files into sample data repository',
ZONE_STATUS_MOVED: 'Files moved successfully, landing zone removed',
ZONE_STATUS_FAILED: 'Validation/moving failed (unknown problem)',
ZONE_STATUS_DELETING: 'Deleting landing zone',
ZONE_STATUS_DELETED: 'Landing zone deleted',
}
STATUS_INFO_DELETE_NO_COLL = (
'No iRODS collection for zone found, marked as deleted'
)

STATUS_STYLES = {
ZONE_STATUS_CREATING: 'bg-warning',
ZONE_STATUS_NOT_CREATED: 'bg-danger',
ZONE_STATUS_ACTIVE: 'bg-info',
ZONE_STATUS_PREPARING: 'bg-warning',
ZONE_STATUS_VALIDATING: 'bg-warning',
ZONE_STATUS_MOVING: 'bg-warning',
ZONE_STATUS_MOVED: 'bg-success',
ZONE_STATUS_FAILED: 'bg-danger',
ZONE_STATUS_DELETING: 'bg-warning',
ZONE_STATUS_DELETED: 'bg-secondary',
}

# Status types for which zone validation, moving and deletion are allowed
STATUS_ALLOW_UPDATE = ['ACTIVE', 'FAILED']

# Status types for zones for which activities have finished
STATUS_FINISHED = ['MOVED', 'NOT CREATED', 'DELETED']

# Status types which lock the project in Taskflow
STATUS_LOCKING = ['PREPARING', 'VALIDATING', 'MOVING']

# Status types for busy landing zones
STATUS_BUSY = ['CREATING', 'PREPARING', 'VALIDATING', 'MOVING', 'DELETING']

# Status types during which file lists and stats should be displayed
STATUS_DISPLAY_FILES = ['ACTIVE', 'PREPARING', 'VALIDATING', 'MOVING', 'FAILED']


class LandingZone(models.Model):
"""Class representing an user's iRODS landing zone for an assay"""

Expand Down Expand Up @@ -121,7 +52,7 @@ class LandingZone(models.Model):
max_length=64,
null=False,
blank=False,
default='CREATING',
default=lc.ZONE_STATUS_CREATING,
help_text='Status of landing zone',
)

Expand All @@ -130,7 +61,7 @@ class LandingZone(models.Model):
max_length=1024,
null=True,
blank=True,
default=DEFAULT_STATUS_INFO['CREATING'],
default=lc.DEFAULT_STATUS_INFO[lc.ZONE_STATUS_CREATING],
help_text='Additional status information',
)

Expand Down Expand Up @@ -198,24 +129,24 @@ def get_project(self):

def set_status(self, status, status_info=None):
"""Set zone status"""
if status not in ZONE_STATUS_TYPES:
if status not in lc.ZONE_STATUS_TYPES:
raise TypeError('Unknown status "{}"'.format(status))
self.status = status
if status_info:
self.status_info = status_info
else:
self.status_info = DEFAULT_STATUS_INFO[status][:1024]
self.status_info = lc.DEFAULT_STATUS_INFO[status][:1024]
self.save()

def is_locked(self):
"""
Return True/False depending whether write access to zone is currently
locked.
"""
return self.status in STATUS_LOCKING
return self.status in lc.STATUS_LOCKING

def can_display_files(self):
"""
Return True/False depending whether file info should be displayed.
"""
return self.status in STATUS_DISPLAY_FILES
return self.status in lc.STATUS_DISPLAY_FILES
13 changes: 10 additions & 3 deletions landingzones/plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,12 @@
# Samplesheets dependency
from samplesheets.models import Investigation, Assay

from landingzones.models import LandingZone, STATUS_ALLOW_UPDATE
from landingzones.constants import (
STATUS_ALLOW_UPDATE,
ZONE_STATUS_MOVED,
ZONE_STATUS_DELETED,
)
from landingzones.models import LandingZone
from landingzones.urls import urlpatterns
from landingzones.views import ZoneModifyMixin

Expand Down Expand Up @@ -125,7 +130,7 @@ def get_object_link(self, model_str, uuid):
obj = self.get_object(eval(model_str), uuid)
if not obj:
return None
if obj.__class__ == LandingZone and obj.status != 'MOVED':
if obj.__class__ == LandingZone and obj.status != ZONE_STATUS_MOVED:
return {
'url': reverse(
'landingzones:list',
Expand Down Expand Up @@ -166,7 +171,9 @@ def get_project_list_value(self, column_id, project, user):
zones = LandingZone.objects.filter(project=project)
else:
zones = LandingZone.objects.filter(project=project, user=user)
active_count = zones.exclude(status__in=['MOVED', 'DELETED']).count()
active_count = zones.exclude(
status__in=[ZONE_STATUS_MOVED, ZONE_STATUS_DELETED]
).count()

if investigation and investigation.irods_status and active_count > 0:
return (
Expand Down
4 changes: 2 additions & 2 deletions landingzones/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@
# Samplesheets dependency
from samplesheets.models import Assay

from landingzones.models import (
LandingZone,
from landingzones.constants import (
ZONE_STATUS_OK,
ZONE_STATUS_DELETED,
ZONE_STATUS_NOT_CREATED,
)
from landingzones.models import LandingZone
from landingzones.utils import get_zone_title


Expand Down
3 changes: 2 additions & 1 deletion landingzones/tasks_celery.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Celery tasks for the landingzones app"""

import logging

from django.conf import settings
Expand All @@ -10,7 +11,7 @@
from projectroles.models import Project
from projectroles.plugins import get_backend_api

from landingzones.models import STATUS_ALLOW_UPDATE, STATUS_LOCKING
from landingzones.constants import STATUS_ALLOW_UPDATE, STATUS_LOCKING
from landingzones.views import ZoneMoveMixin

logger = logging.getLogger(__name__)
Expand Down
2 changes: 1 addition & 1 deletion landingzones/tasks_taskflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
# Taskflowbackend dependency
from taskflowbackend.tasks.sodar_tasks import SODARBaseTask

from landingzones.models import (
from landingzones.constants import (
STATUS_BUSY,
ZONE_STATUS_FAILED,
ZONE_STATUS_NOT_CREATED,
Expand Down
3 changes: 2 additions & 1 deletion landingzones/templatetags/landingzones_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
# Projectroles dependency
from projectroles.plugins import get_backend_api

from landingzones.models import LandingZone, STATUS_STYLES, STATUS_FINISHED
from landingzones.constants import STATUS_STYLES, STATUS_FINISHED
from landingzones.models import LandingZone
from landingzones.plugins import get_zone_config_plugin


Expand Down
2 changes: 1 addition & 1 deletion landingzones/tests/test_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
get_inactive_zones,
get_output,
)
from landingzones.models import (
from landingzones.constants import (
ZONE_STATUS_MOVED,
ZONE_STATUS_DELETED,
ZONE_STATUS_ACTIVE,
Expand Down
6 changes: 3 additions & 3 deletions landingzones/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@
# Samplesheets dependency
from samplesheets.tests.test_io import SampleSheetIOMixin, SHEET_DIR

from landingzones.models import (
LandingZone,
from landingzones.constants import (
DEFAULT_STATUS_INFO,
ZONE_STATUS_CREATING,
ZONE_STATUS_ACTIVE,
ZONE_STATUS_MOVING,
)
from landingzones.models import LandingZone


# SODAR constants
Expand All @@ -37,7 +37,7 @@
ZONE_TITLE = '20180503_1724_test_zone'
ZONE_DESC = 'description'
ZONE_MSG = 'user message'
ZONE_STATUS_INFO_INIT = DEFAULT_STATUS_INFO['CREATING']
ZONE_STATUS_INFO_INIT = DEFAULT_STATUS_INFO[ZONE_STATUS_CREATING]


class LandingZoneMixin:
Expand Down
2 changes: 1 addition & 1 deletion landingzones/tests/test_permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
# Samplesheets dependency
from samplesheets.tests.test_io import SampleSheetIOMixin, SHEET_DIR

from landingzones.models import ZONE_STATUS_ACTIVE
from landingzones.constants import ZONE_STATUS_ACTIVE
from landingzones.tests.test_models import (
LandingZoneMixin,
ZONE_TITLE,
Expand Down
Loading

0 comments on commit c3e6c62

Please sign in to comment.