11import string
22
33from flask import request
4- from marshmallow import EXCLUDE
54from webargs .flaskparser import parser
65from webargs import fields
76import sqlalchemy .sql .expression as sae
@@ -207,14 +206,12 @@ def load_from_neurostore(cls, source_id):
207206 parent_source = parent .source
208207 parent_source_id = parent .source_id
209208
210- schema = cls ._schema (copy = True )
209+ context = {
210+ "clone" : True ,
211+ "nested" : True ,
212+ }
213+ schema = cls ._schema (context = context )
211214 tmp_data = schema .dump (annotation )
212- for note in tmp_data ["notes" ]:
213- note .pop ("analysis_name" )
214- note .pop ("study_name" )
215- note .pop ("study_year" )
216- note .pop ("publication" )
217- note .pop ("authors" )
218215 data = schema .load (tmp_data )
219216 data ["source" ] = "neurostore"
220217 data ["source_id" ] = source_id
@@ -266,12 +263,6 @@ def view_search(self, q, args):
266263
267264 return q
268265
269- def serialize_records (self , records , args , exclude = tuple ()):
270- if args .get ("flat" ):
271- exclude = ("versions" ,)
272-
273- return super ().serialize_records (records , args , exclude )
274-
275266 def join_tables (self , q ):
276267 "join relevant tables to speed up query"
277268 q = q .options (joinedload ("versions" ))
@@ -382,8 +373,6 @@ class StudiesView(ObjectView, ListView):
382373 "pmid" ,
383374 )
384375
385- # _default_exclude = ("has_coordinates", "has_images", "studysets")
386-
387376 def view_search (self , q , args ):
388377 # search studies for data_type
389378 if args .get ("data_type" ):
@@ -426,10 +415,6 @@ def serialize_records(self, records, args, exclude=tuple()):
426415 study .studysets = study .studysets .filter (
427416 Studyset .user_id == args .get ("studyset_owner" )
428417 ).all ()
429- if args .get ("flat" ):
430- exclude += ("analyses" ,)
431-
432- exclude += ("studysets" , "has_coordinates" , "has_images" )
433418 return super ().serialize_records (records , args , exclude )
434419
435420 @classmethod
@@ -452,8 +437,10 @@ def load_from_neurostore(cls, source_id):
452437 parent_source = parent .source
453438 parent_source_id = parent .source_id
454439
455- schema = cls ._schema (copy = True )
456- data = schema .load (schema .dump (study ), unknown = EXCLUDE )
440+ context = {"clone" : True , "nested" : True }
441+ schema = cls ._schema (context = context )
442+ dump_study = schema .dump (study )
443+ data = schema .load (dump_study )
457444 data ["source" ] = "neurostore"
458445 data ["source_id" ] = source_id
459446 data ["source_updated_at" ] = study .updated_at or study .created_at
0 commit comments