Skip to content
Snippets Groups Projects
Commit 223b9084 authored by Jean-Philippe Laverdure's avatar Jean-Philippe Laverdure
Browse files

Implements GraphQL Datafile annotations mutation

parent 36a43b1a
No related branches found
No related tags found
3 merge requests!111Populate /secure/my-sharegroups/ with the same groups that are available to a...,!109Populate /secure/my-sharegroups/ with the same groups that are available to a...,!108Resolve "Datafile annotation return as json in graphql output instead of jsonstring"
......@@ -160,6 +160,14 @@ class InstitutionForm(forms.ModelForm):
fields = ('__all__')
class DataFileGraphQLForm(forms.ModelForm):
"""Only enables modification of annotations, iric_data_id is used as a lookup key
"""
class Meta:
model = DataFile
fields = ('iric_data_id', 'annotations')
class DataFileForm(forms.ModelForm):
class Meta:
model = DataFile
......@@ -229,7 +237,7 @@ class DataFileServletUploadForm(forms.ModelForm):
class DataFileAnnotationForm(forms.Form):
dropzone_files = forms.CharField(required=False, widget=forms.HiddenInput)
annotations = HStoreField(required=False, label=_('Attach these annotations with the uploaded files:'), help_text=_('Pro Tip: You can also drop a tab separated value file onto this field'),
widget=forms.Textarea(attrs={'placeholder':'{"key": "value"}'}))
widget=forms.Textarea(attrs={'placeholder': '{"key": "value"}'}))
lab = forms.ChoiceField(required=False, label=_('Attach uploaded files to this lab:'))
def __init__(self, request, *args, **kwargs):
......@@ -280,7 +288,7 @@ class DataSetForm(forms.ModelForm):
is_valid = super().is_valid()
if not is_valid:
return is_valid
elif self.instance.id and self.request_profile: # Apply only to DS update
elif self.instance.id and self.request_profile: # Apply only to DS update
is_valid = self.instance in DataSet.objects.writable_by_profile(self.request_profile)
return is_valid
......
import os
import json
import graphene
import hashlib
......@@ -9,13 +8,12 @@ from django.utils import timezone
from graphql.error import GraphQLError
from graphene_django.types import DjangoObjectType
from graphene.types.json import JSONString
# from graphene.types.generic import GenericScalar
from graphene_django.views import GraphQLView
from graphene_django.forms.mutation import DjangoModelFormMutation
from portal.models import DataFile, DataSet, Lab, Profile, ProfileToken, ShareGroup
from portal.views import TokenLoginMixin
from portal.forms import DataSetForm
from portal.forms import DataSetForm, DataFileGraphQLForm
# Protect graphql API page
......@@ -242,6 +240,26 @@ class Query(graphene.ObjectType):
return qs.distinct()
class DataFileMutation(DjangoModelFormMutation):
"""Enable the modification of a DataFile
Makes use of the DataFileForm, so all exposed fields from that form are available"""
class Meta:
form_class = DataFileGraphQLForm
model_operations = ['update']
return_field_name = 'datafile'
@classmethod
def get_form_kwargs(cls, root, info, **input) -> dict:
kwargs = super().get_form_kwargs(root, info, **input)
if 'instance' not in kwargs.keys():
iric_data_id = input.pop("iric_data_id", None)
instance = cls._meta.model._default_manager.get(iric_data_id=iric_data_id)
kwargs["instance"] = instance
return kwargs
class DataSetMutation(DjangoModelFormMutation):
"""Enable the creation or modification of a DataSet
Makes use of the DataSetForm, so all exposed fields from that form are available"""
......@@ -314,6 +332,7 @@ class DataFileAttachMutation(graphene.Mutation):
class Mutation(graphene.ObjectType):
datafile = DataFileMutation.Field()
dataset = DataSetMutation.Field()
attach_datafile_by_hash = DataFileAttachMutation.Field()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment