Skip to content

Commit

Permalink
feat: ExperimentUpload objects output, better format and filters
Browse files Browse the repository at this point in the history
  • Loading branch information
kaliif committed Jan 16, 2025
1 parent d9157e4 commit 0a5ac8b
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 3 deletions.
7 changes: 7 additions & 0 deletions viewer/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
CanonSiteConf,
Compound,
Experiment,
ExperimentUpload,
Pose,
QuatAssembly,
SiteObservation,
Expand Down Expand Up @@ -125,3 +126,9 @@ class AssemblyFilter(TargetFilterMixin):
class Meta:
model = QuatAssembly
fields = ("target",)


class ExperimentUploadFilter(filters.FilterSet):
class Meta:
model = ExperimentUpload
fields = ("target", "project", "data_version_major", "data_version_minor")
18 changes: 17 additions & 1 deletion viewer/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -895,9 +895,25 @@ class Meta:


class TargetExperimentReadSerializer(ValidateProjectMixin, serializers.ModelSerializer):
tarball = serializers.CharField()

class Meta:
model = models.ExperimentUpload
fields = '__all__'
fields = (
'target',
'project',
'tarball',
'commit_datetime',
'committer',
'task_id',
'neighbourhood_transforms',
'conformer_site_transforms',
'reference_structure_transforms',
'upload_data_dir',
'upload_version',
'data_version_major',
'data_version_minor',
)


class TargetExperimentWriteSerializer(serializers.ModelSerializer):
Expand Down
20 changes: 18 additions & 2 deletions viewer/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
from dateutil.parser import parse
from django.conf import settings
from django.contrib.auth import get_user_model
from django.db.models import F, Value
from django.db.models.fields import CharField
from django.db.models.functions import Concat
from django.http import FileResponse, HttpResponse, JsonResponse
from django.shortcuts import get_object_or_404, redirect, render
from django.urls import reverse
Expand Down Expand Up @@ -1834,10 +1837,23 @@ def create(self, request, *args, **kwargs):


class ExperimentUploadView(ISPyBSafeQuerySet):
queryset = models.ExperimentUpload.objects.all()
queryset = models.ExperimentUpload.objects.annotate(
tarball=Concat(
Value(settings.TARGET_LOADER_MEDIA_DIRECTORY),
Value('/'),
F('target__zip_archive'),
Value('/'),
F('file'),
output_field=CharField(),
),
).order_by(
'project',
'target__title',
'upload_version',
)
serializer_class = serializers.TargetExperimentReadSerializer
permission_class = [permissions.IsAuthenticated]
filterset_fields = ("target", "project")
filterset_class = filters.ExperimentUploadFilter
filter_permissions = "target__project"
http_method_names = ('get',)

Expand Down

0 comments on commit 0a5ac8b

Please sign in to comment.