Skip to content

Commit

Permalink
Merge pull request #35 from galv-team/upload-release
Browse files Browse the repository at this point in the history
feat: allow user upload
  • Loading branch information
mjaquiery authored Sep 6, 2024
2 parents e4626c8 + 3d0dab3 commit d467f44
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 6 deletions.
2 changes: 1 addition & 1 deletion backend_django/config/settings_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
# Build paths inside the project like this: BASE_DIR / 'subdir'.
import os

API_VERSION = "2.3.1"
API_VERSION = "2.4.0"

try:
USER_ACTIVATION_TOKEN_EXPIRY_S = int(os.environ.get("DJANGO_USER_ACTIVATION_TOKEN_EXPIRY_S"))
Expand Down
20 changes: 19 additions & 1 deletion backend_django/galv/serializers/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -1761,7 +1761,22 @@ class Meta:
'upload_errors': {'help_text': "Errors associated with this File"}
})


class ObservedFileCreateSerializer(ObservedFileSerializer, WithTeamMixin):
"""
The ObservedFileCreateSerializer is used to create ObservedFiles from uploaded files.
This can be done in a one- or two-step process.
In the one-step process, a file is supplied along with a `mapping` that is applicable to that file.
An ObservedFile is created with the supplied mapping applied to the file.
Its data and preview image are extracted and stored in Storage.
In the two-stage process, a file is supplied without a `mapping`.
The `summary` of the file is extracted and stored in a new ObservedFile.
The user can then apply a mapping to that file in the usual manner.
Once a mapping has been applied, the file can be re-uploaded citing its `id` to complete the process.
The data and preview image will be extracted and stored in Storage.
"""
file = serializers.FileField(write_only=True, help_text="File to upload")
target_file_id = TruncatedHyperlinkedRelatedIdField(
'ObservedFileSerializer',
Expand Down Expand Up @@ -1824,7 +1839,8 @@ def validate(self, attrs):
if 'file' not in attrs:
raise ValidationError("You must provide a file to upload")
if 'id' in attrs and 'mapping' not in attrs:
raise ValidationError("You must specify the mapping when updating an existing file")
if self.instance is None or self.instance.mapping is None:
raise ValidationError("You must specify the mapping when updating an existing file")
return super().validate(attrs)

def to_representation(self, instance):
Expand Down Expand Up @@ -1860,6 +1876,8 @@ def create(self, validated_data):
observed_file = target_file
if observed_file.summary != json.loads(summary.to_json()): # apply the same processing to summary
raise ValidationError("Summary does not match existing file")
if mapping is None:
mapping = observed_file.mapping
else:
observed_file = ObservedFile.objects.create(
**validated_data,
Expand Down
11 changes: 9 additions & 2 deletions backend_django/galv/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -1215,8 +1215,15 @@ class MonitoredPathViewSet(DescribeSelfMixin, viewsets.ModelViewSet):
summary="Upload a new File",
description="""
Files can be uploaded to the server.
Files will be kept temporarily while processed, and then deleted once the import process is complete
or after a certain period of time.
If you know the `mapping` of a file, the file can be uploaded in a single step.
If you do not know the `mapping` of a file, upload the file without a Mapping and then assign it a `mapping` using the
mapping interface.
You may create a Mapping using the mapping interface and the `summary` data extracted from the file if necessary.
Once a `mapping` has been selected for the file, upload the file again, specifying the `id` of the partially-uploaded
file as `target_file_id`.
The file will then be uploaded in full.
"""
),
retrieve=extend_schema(
Expand Down
2 changes: 1 addition & 1 deletion docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
project = 'Galv'
copyright = '2023, Oxford RSE'
author = 'Oxford RSE'
release = '2.3.1'
release = '2.4.0'

# -- General configuration ---------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration
Expand Down
2 changes: 1 addition & 1 deletion docs/tags.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
["v2.2.0", "v2.3.1", "main"]
["v2.2.0", "v2.3.1", "v2.4.0", "main"]

0 comments on commit d467f44

Please sign in to comment.