77
88
99def create_experiments_and_inventories (parsed_experiments , collection ):
10- """Compiles a dictionary of cript Experiment objects. If a parsed experiment is able to be turned
11- into an Experiment object it is added to an experiments dictionary and that dictionary is returned.
10+ """Compiles dictionaries of CRIPT Experiment objects and CRIPT Inventory objects . If a parsed experiment/inventory is able to be turned
11+ into an Experiment/Inventory object it is added to an experiments dictionary and that dictionary is returned.
1212 parsed_...-dict of dicts
1313 group-object
1414 collection-object
@@ -25,13 +25,13 @@ def create_experiments_and_inventories(parsed_experiments, collection):
2525 cell_type = parsed_cell ["type" ]
2626 cell_key = parsed_cell ["key" ]
2727 cell_value = parsed_cell ["value" ]
28- # Only attribute types should be in Experiment
28+ # Only attribute and that specific identifier should be in experiment
2929 if cell_type == "attribute" :
3030 experiment_dict [cell_key ] = cell_value
3131 inventory_dict [cell_key ] = cell_value
32- if cell_type == "identifier" :
32+ elif cell_type == "identifier" :
3333 if cell_key == "Experiment or Inventory" :
34- if cell_value == "I " :
34+ if cell_value . lower () == "i " :
3535 inventory = True
3636 if inventory :
3737 invObj = _create_object (cript .Inventory , inventory_dict , parsed_cell )
@@ -49,8 +49,8 @@ def create_experiments_and_inventories(parsed_experiments, collection):
4949def create_citations (parsed_citations , group ):
5050 """Compiles dictionaries with Data and File cript objects.
5151 parsed_...-dict of dicts
52- group-obj
53- returns-tuple of dicts of objs
52+ group-cript Group node
53+ returns-tuple of dicts of reference nodes and citation nodes
5454 """
5555
5656 references = {}
@@ -176,7 +176,7 @@ def create_materials(parsed_materials, project, data, citations):
176176
177177 elif cell_type == "property" :
178178 if parsed_cell ["key" ] == "use_existing" :
179- use_existing = cellToBool (parsed_cell ["value" ])
179+ use_existing = is_cell_true (parsed_cell ["value" ])
180180 continue
181181 property = _create_property (parsed_cell , data , citations )
182182 material_dict ["properties" ].append (property )
@@ -189,11 +189,11 @@ def create_materials(parsed_materials, project, data, citations):
189189
190190 try :
191191 # try to get the material using its name
192- name_ = parsed_material ["name" ]["value" ]
193- newProject = cript .Project .get (
192+ mat_name = parsed_material ["name" ]["value" ]
193+ new_project = cript .Project .get (
194194 name = parsed_material ["use_existing" ]["value" ]
195195 )
196- material = cript .Material .get (name = name_ , project = newProject .uid )
196+ material = cript .Material .get (name = mat_name , project = new_project .uid )
197197
198198 # If there is a get error add it to the errors sheet
199199 except ValueError as e :
@@ -205,23 +205,11 @@ def create_materials(parsed_materials, project, data, citations):
205205 # If the material had a successful GET request, add properties, identifiers,
206206 # and select attributes as written in the excel
207207 else :
208- if newProject .name != project .name :
209- material .project = project
210- material .url = None
211- material .uid = None
212- if material .group .name != project .group .name :
213- for property in material .properties :
214- property .citations = []
215- material .group = project .group
216-
217- newProperties = []
218- for property in material .properties :
219- if "+" not in property .key :
220- newProperties .append (property )
221- material .properties = newProperties
222208
223- for property in material_dict [ "properties" ]:
209+ material = copyMaterial ( material , new_project , project )
224210
211+ # Add properties,identifiers, and attributes to material
212+ for property in material_dict ["properties" ]:
225213 material .add_property (property )
226214 for identifier in material_dict ["identifiers" ]:
227215 material .add_identifier (identifier )
@@ -236,6 +224,7 @@ def create_materials(parsed_materials, project, data, citations):
236224 material .notes += material_dict ["notes" ]
237225 else :
238226 material .notes = material_dict ["notes" ]
227+
239228 # create new material object otherwise
240229 else :
241230 material = _create_object (cript .Material , material_dict , parsed_cell )
@@ -481,7 +470,7 @@ def _create_property(parsed_property, data, citations):
481470 property_dict ["conditions" ].append (condition )
482471
483472 elif cell_type == "method" :
484- if cellToBool (parsed_cell ["value" ]):
473+ if is_cell_true (parsed_cell ["value" ]):
485474 property_dict ["method" ] = parsed_cell ["key" ]
486475
487476 elif cell_type == "relation" :
@@ -578,6 +567,37 @@ def _get_relation(related_objs, cell_value, parsed_cell):
578567 return None
579568
580569
581- def cellToBool (val ):
570+ def is_cell_true (val ):
582571 """Converts a cell value to a useable boolean"""
583- return True if str (val ).lower () != "false" else False
572+ return str (val ).lower () != "false"
573+
574+
575+ def copyMaterial (material , new_project , project ):
576+ """
577+ Takes a material node and adjusts values to get rid of legacy code and incompatible features
578+ inputs:
579+ material - cript material node
580+ new_project - cript project node
581+ project - cript project node
582+
583+ returns - cript material node
584+ """
585+ if new_project .name != project .name :
586+ # Sets new project and gets rid of url and uid to make new node object
587+ material .project = project
588+ material .url = None
589+ material .uid = None
590+ # Gets rid of citations that would cause permissions errors
591+ if material .group .name != project .group .name :
592+ for property in material .properties :
593+ property .citations = []
594+ material .group = project .group
595+
596+ newProperties = []
597+ # Gets rid of any legacy properties/custom that won't upload
598+ for property in material .properties :
599+ if "+" not in property .key :
600+ newProperties .append (property )
601+ material .properties = newProperties
602+
603+ return material
0 commit comments