Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/sckan 259 #228

Merged
merged 10 commits into from
Feb 15, 2024
8 changes: 4 additions & 4 deletions backend/composer/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
from rest_framework.serializers import ValidationError

from composer.services.state_services import (
ConnectivityStatementService,
SentenceService,
ConnectivityStatementStateService,
SentenceStateService,
)
from .filtersets import (
SentenceFilter,
Expand Down Expand Up @@ -307,7 +307,7 @@ class ConnectivityStatementViewSet(
permissions.IsAuthenticatedOrReadOnly,
]
filterset_class = ConnectivityStatementFilter
service = ConnectivityStatementService
service = ConnectivityStatementStateService


def get_serializer_class(self):
Expand Down Expand Up @@ -370,7 +370,7 @@ class SentenceViewSet(
permissions.IsAuthenticatedOrReadOnly,
]
filterset_class = SentenceFilter
service = SentenceService
service = SentenceStateService


class SpecieViewSet(viewsets.ReadOnlyModelViewSet):
Expand Down
12 changes: 6 additions & 6 deletions backend/composer/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,22 +40,22 @@ class DestinationType(models.TextChoices):

class SentenceState(models.TextChoices):
OPEN = "open"
TO_BE_REVIEWED = "to_be_reviewed"
NEEDS_FURTHER_REVIEW = "needs_further_review"
COMPOSE_LATER = "compose_later"
READY_TO_COMPOSE = "ready_to_compose"
COMPOSE_NOW = "compose_now"
COMPLETED = "completed"
EXCLUDED = "excluded"
DUPLICATE = "duplicate"


class CSState(models.TextChoices):
# Connectivity Statement States
DRAFT = "draft"
COMPOSE_NOW = "compose_now"
CURATED = "curated"
EXCLUDED = "excluded"
REJECTED = "rejected"
IN_PROGRESS = "in_progress"
TO_BE_REVIEWED = "to_be_reviewed"
CONNECTION_MISSING = "connection_missing"
REVISE = "revise"
REJECTED = "rejected"
NPO_APPROVED = "npo_approved"
EXPORTED = "exported"
INVALID = "invalid"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Generated by Django 4.1.4 on 2024-02-13 13:01

from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
("composer", "0038_alter_connectivitystatement_circuit_type_and_more"),
]

operations = [
migrations.RemoveConstraint(
model_name="connectivitystatement",
name="state_valid",
),
migrations.RemoveConstraint(
model_name="sentence",
name="sentence_state_valid",
),
migrations.AlterField(
model_name="exportmetrics",
name="state",
field=models.CharField(max_length=20),
),
]
69 changes: 69 additions & 0 deletions backend/composer/migrations/0040_auto_20240213_1301.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# Generated by Django 4.1.4 on 2024-02-13 13:01

from django.db import migrations, models


def migrate_deprecated_states(apps, schema_editor):
Sentence = apps.get_model('composer', 'Sentence')
ConnectivityStatement = apps.get_model('composer', 'ConnectivityStatement')

Sentence.objects.filter(state='duplicate').update(state='excluded')

Sentence.objects.filter(state='to_be_reviewed').update(state='needs_further_review')

ConnectivityStatement.objects.filter(state='curated').update(state='in_progress')

ConnectivityStatement.objects.filter(state__in=['excluded', 'connection_missing']).update(state='rejected')


class Migration(migrations.Migration):
dependencies = [
("composer", "0039_remove_connectivitystatement_state_valid_and_more"),
]

operations = [
migrations.RunPython(migrate_deprecated_states),

migrations.AddConstraint(
model_name="connectivitystatement",
constraint=models.CheckConstraint(
check=models.Q(
(
"state__in",
[
"draft",
"compose_now",
"in_progress",
"to_be_reviewed",
"revise",
"rejected",
"npo_approved",
"exported",
"invalid",
],
)
),
name="state_valid",
),
),
migrations.AddConstraint(
model_name="sentence",
constraint=models.CheckConstraint(
check=models.Q(
(
"state__in",
[
"open",
"needs_further_review",
"compose_later",
"ready_to_compose",
"compose_now",
"completed",
"excluded",
],
)
),
name="sentence_state_valid",
),
),
]
Loading