Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 7 additions & 8 deletions backend/api/migrations/0001_v3_0.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
# Generated by Django 3.2.25 on 2026-02-02 15:11

from datetime import datetime

import django.contrib.postgres.fields
import django.core.validators
import django.utils.timezone
import tinymce.models
from django.conf import settings
from django.db import migrations, models

Expand Down Expand Up @@ -1224,7 +1221,7 @@ class Migration(migrations.Migration):
migrations.AddConstraint(
model_name="spectrogramanalysis",
constraint=models.CheckConstraint(
check=models.Q(
condition=models.Q(
("legacy", True),
models.Q(("data_duration__isnull", False), ("legacy", False)),
_connector="OR",
Expand All @@ -1235,14 +1232,16 @@ class Migration(migrations.Migration):
migrations.AddConstraint(
model_name="spectrogram",
constraint=models.CheckConstraint(
check=models.Q(("start__lt", django.db.models.expressions.F("end"))),
condition=models.Q(
("start__lt", django.db.models.expressions.F("end"))
),
name="start is lower than end",
),
),
migrations.AddConstraint(
model_name="legacyspectrogramconfiguration",
constraint=models.CheckConstraint(
check=models.Q(
condition=models.Q(
models.Q(
("linear_frequency_scale__isnull", True),
("multi_linear_frequency_scale__isnull", False),
Expand Down Expand Up @@ -1302,7 +1301,7 @@ class Migration(migrations.Migration):
migrations.AddConstraint(
model_name="annotation",
constraint=models.CheckConstraint(
check=models.Q(
condition=models.Q(
models.Q(
("annotator__isnull", True),
("detector_configuration__isnull", False),
Expand All @@ -1319,7 +1318,7 @@ class Migration(migrations.Migration):
migrations.AddConstraint(
model_name="annotation",
constraint=models.CheckConstraint(
check=models.Q(
condition=models.Q(
models.Q(
("end_frequency__isnull", True),
("end_time__isnull", True),
Expand Down
6 changes: 3 additions & 3 deletions backend/api/migrations/0012_archive_constraints.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class Migration(migrations.Migration):
migrations.AddConstraint(
model_name="annotationcampaign",
constraint=models.CheckConstraint(
check=models.Q(
condition=models.Q(
models.Q(
("archived", True),
("archived_at__isnull", False),
Expand All @@ -32,7 +32,7 @@ class Migration(migrations.Migration):
migrations.AddConstraint(
model_name="annotationphase",
constraint=models.CheckConstraint(
check=models.Q(
condition=models.Q(
models.Q(
("archived", True),
("archived_at__isnull", False),
Expand All @@ -51,7 +51,7 @@ class Migration(migrations.Migration):
migrations.AddConstraint(
model_name="dataset",
constraint=models.CheckConstraint(
check=models.Q(
condition=models.Q(
models.Q(
("archived", True),
("archived_at__isnull", False),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class Migration(migrations.Migration):
migrations.AddConstraint(
model_name="annotation",
constraint=models.CheckConstraint(
check=models.Q(
condition=models.Q(
models.Q(
("end_time__isnull", True),
("max_frequency__isnull", True),
Expand Down
4 changes: 2 additions & 2 deletions backend/api/models/annotation/annotation.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ class Meta:
constraints = [
models.CheckConstraint(
name="require_user_or_detector",
check=(
condition=(
models.Q(
annotator__isnull=True, detector_configuration__isnull=False
)
Expand All @@ -112,7 +112,7 @@ class Meta:
),
models.CheckConstraint(
name="Annotation type",
check=(
condition=(
models.Q(
type="W",
start_time__isnull=True,
Expand Down
2 changes: 1 addition & 1 deletion backend/api/models/annotation/annotation_campaign.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class Meta:
constraints = [
CheckConstraint(
name="campaign_archive_info",
check=Q(
condition=Q(
archived=True, archived_at__isnull=False, archived_by__isnull=False
)
| Q(archived=False, archived_at__isnull=True, archived_by__isnull=True),
Expand Down
2 changes: 1 addition & 1 deletion backend/api/models/annotation/annotation_phase.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class Meta:
constraints = [
CheckConstraint(
name="phase_archive_info",
check=Q(
condition=Q(
archived=True, archived_at__isnull=False, archived_by__isnull=False
)
| Q(archived=False, archived_at__isnull=True, archived_by__isnull=True),
Expand Down
2 changes: 1 addition & 1 deletion backend/api/models/data/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class Meta:
constraints = [
CheckConstraint(
name="dataset_archive_info",
check=Q(
condition=Q(
archived=True, archived_at__isnull=False, archived_by__isnull=False
)
| Q(archived=False, archived_at__isnull=True, archived_by__isnull=True),
Expand Down
2 changes: 1 addition & 1 deletion backend/api/models/data/spectrogram.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class Meta:
ordering = ("start", "id")
constraints = [
models.CheckConstraint(
name="start is lower than end", check=Q(start__lt=F("end"))
name="start is lower than end", condition=Q(start__lt=F("end"))
)
]

Expand Down
2 changes: 1 addition & 1 deletion backend/api/models/data/spectrogram_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class Meta:
constraints = [
CheckConstraint(
name="spectrogram_analysis_legacy",
check=Q(legacy=True) | Q(legacy=False, data_duration__isnull=False),
condition=Q(legacy=True) | Q(legacy=False, data_duration__isnull=False),
)
]
ordering = ("-created_at",)
Expand Down
5 changes: 5 additions & 0 deletions backend/api/schema/nodes/annotation_campaign.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ def resolve_labels_with_acoustic_features(self: AnnotationCampaign, info):
def resolve_spectrograms_count(self: AnnotationCampaign, info):
return (
Spectrogram.objects.filter(analysis__annotation_campaigns=self)
.order_by()
.distinct()
.count()
)
Expand All @@ -108,6 +109,7 @@ def resolve_queryset(cls, queryset: QuerySet, info: GraphQLResolveInfo):
AnnotationFileRange.objects.filter(
annotation_phase__annotation_campaign_id=OuterRef("pk"),
)
.order_by()
.annotate(sum=Func(F("files_count"), function="Sum"))
.values("sum")
),
Expand All @@ -119,6 +121,7 @@ def resolve_queryset(cls, queryset: QuerySet, info: GraphQLResolveInfo):
annotation_phase__annotation_campaign_id=OuterRef("pk"),
annotator_id=info.context.user.id,
)
.order_by()
.annotate(sum=Func(F("files_count"), function="Sum"))
.values("sum")
),
Expand All @@ -129,6 +132,7 @@ def resolve_queryset(cls, queryset: QuerySet, info: GraphQLResolveInfo):
annotation_phase__annotation_campaign_id=OuterRef("pk"),
status=AnnotationTask.Status.FINISHED,
)
.order_by()
.annotate(count=Func(F("id"), function="count"))
.values("count")
),
Expand All @@ -138,6 +142,7 @@ def resolve_queryset(cls, queryset: QuerySet, info: GraphQLResolveInfo):
status=AnnotationTask.Status.FINISHED,
annotator_id=info.context.user.id,
)
.order_by()
.annotate(count=Func(F("id"), function="count"))
.values("count")
),
Expand Down
8 changes: 8 additions & 0 deletions backend/api/tests/schema/annotation/update_annotations.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@
field
}
}

_debug {
exceptions {
excType
message
stack
}
}
}
"""
BASE_VARIABLES = {
Expand Down
11 changes: 7 additions & 4 deletions backend/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,6 @@

USE_I18N = True

USE_L10N = True

USE_TZ = True


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/3.2/howto/static-files/
Expand Down Expand Up @@ -194,3 +190,10 @@
"MIDDLEWARE": ["graphene_django.debug.middleware.DjangoDebugMiddleware"],
"TESTING_ENDPOINT": "/api/graphql/public",
}

STORAGES = {
"default": {"BACKEND": "django.core.files.storage.FileSystemStorage"},
"staticfiles": {
"BACKEND": "whitenoise.storage.CompressedManifestStaticFilesStorage"
},
}
4 changes: 4 additions & 0 deletions backend/settings/development.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
DEBUG = True

ALLOWED_HOSTS = []
CSRF_TRUSTED_ORIGINS = [
"http://localhost:8000",
"http://localhost:5173",
]

# Database
# https://docs.djangoproject.com/en/3.1/ref/settings/#databases
Expand Down
1 change: 1 addition & 0 deletions backend/settings/production.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
# Prod settings
SECRET_KEY = os.environ["SECRET_KEY"]
ALLOWED_HOSTS = [os.environ["OSMOSE_HOST"]]
CSRF_TRUSTED_ORIGINS = [os.environ["OSMOSE_HOST"]]

# Database
# https://docs.djangoproject.com/en/3.1/ref/settings/#databases
Expand Down
19 changes: 14 additions & 5 deletions backend/storage/resolvers/_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,22 +27,31 @@ def _get_all_analysis_for_dataset(
) -> list[SpectrogramAnalysis | FailedItem]:
analysis = []

for a in dataset.spectrogram_analysis.all():
if exists(join(dataset.path, a.path)):
analysis.append(a)
if dataset.pk:
# Not initialized datasets has neither pk nor spectrogram_analysis relations
for a in dataset.spectrogram_analysis.all():
if exists(join(dataset.path, a.path)):
analysis.append(a)

for a in super()._get_all_analysis_for_dataset(
dataset=dataset, detailed=detailed
):
if not dataset.spectrogram_analysis.filter(path=a.path).exists():
if (
not dataset.pk
or not dataset.spectrogram_analysis.filter(path=a.path).exists()
):
# Not initialized datasets has neither pk nor spectrogram_analysis relations
analysis.append(a)

return analysis

def _get_analysis(
self, dataset: Dataset, relative_path: str, detailed: bool = False
) -> SpectrogramAnalysis | FailedItem:
if dataset.spectrogram_analysis.filter(path=relative_path).exists():
if (
dataset.pk
and dataset.spectrogram_analysis.filter(path=relative_path).exists()
):
return dataset.spectrogram_analysis.get(path=relative_path)
return super()._get_analysis(
dataset=dataset, relative_path=relative_path, detailed=detailed
Expand Down
14 changes: 8 additions & 6 deletions backend/storage/schema/queries/spectrogram_paths.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import graphene
from django.shortcuts import get_object_or_404
from django_extension.schema.errors import NotFoundError
from django_extension.schema.permissions import GraphQLResolve, GraphQLPermissions

from backend.api.models import (
Expand All @@ -22,11 +22,13 @@ def __init__(self, audio_path, spectrogram_path):

@GraphQLResolve(permission=GraphQLPermissions.AUTHENTICATED)
def resolve_paths(root, info, spectrogram_id: int, analysis_id: int):
relation: SpectrogramAnalysisRelation = get_object_or_404(
SpectrogramAnalysisRelation,
spectrogram_id=spectrogram_id,
analysis_id=analysis_id,
)
try:
relation: SpectrogramAnalysisRelation = SpectrogramAnalysisRelation.objects.get(
spectrogram_id=spectrogram_id,
analysis_id=analysis_id,
)
except SpectrogramAnalysisRelation.DoesNotExist as e:
raise NotFoundError from e

resolver = Resolver(join(relation.analysis.dataset.path, relation.analysis.path))
paths = resolver.get_spectrogram_paths(relation=relation)
Expand Down
1 change: 1 addition & 0 deletions backend/storage/tests/schema/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from .browse import BrowseTestCase
from .search import SearchTestCase
from .import_dataset import ImportDatasetTestCase
from .spectrogram_paths import SpectrogramPathsTestCase
6 changes: 2 additions & 4 deletions backend/storage/tests/schema/spectrogram_paths.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from django.test import override_settings
from django_extension.tests import ExtendedTestCase

from backend.api.models import Spectrogram, SpectrogramAnalysis
from backend.api.models import SpectrogramAnalysis
from backend.aplose.models import User
from .import_dataset import (
QUERY as IMPORT_QUERY,
Expand Down Expand Up @@ -50,9 +50,7 @@ def test_connected_empty_user(self):
)
self.assertResponseHasErrors(response)
content = json.loads(response.content)
self.assertEqual(
content["errors"][0]["message"], "No Spectrogram matches the given query."
)
self.assertEqual(content["errors"][0]["message"], "Not found")

@override_settings(DATASET_EXPORT_PATH=GOOD, VOLUMES_ROOT=VOLUMES_ROOT)
def test(self):
Expand Down
Loading
Loading