def save_stage_data(auto_fields): d = DataFile() datafile_id = auto_fields["datafile"] current_stage = auto_fields["current_stage"] description_stages = d.GET(datafile_id)["description"]["stages"] stage = [elem for elem in description_stages if elem["ref"] == current_stage] # get schema for resolving ontology terms onto_schema = d_utils.json_to_pytype(lkup.DB_TEMPLATES["ONTOLOGY_ANNOTATION"]) if stage: data = {} stage_items = stage[0]["items"] if stage_items: for sti in stage_items: # handle ontology term if sti["control"].lower() == "ontology term": a = {} for k in onto_schema["properties"]: if sti["id"] + "." + k in auto_fields.keys(): a[k] = auto_fields[sti["id"] + "." + k] data[sti["id"]] = a else: data[sti["id"]] = auto_fields[sti["id"]] d.save_description_stage(datafile_id, {"ref": current_stage, "data": data})
def data_wiz(request): context = {} step = int(request.POST['step']) datafile = request.POST['datafile'] d = DataFile() dispatch_description = { 'ena': wizh.ena_description, 'figshare': wizh.figshare_description, 'default': wizh.default_description } if step == 1: # first stage in the process where the wizard has only just been initiated # infer the deposition context (target repository) based on the file # if we can infer the context, switch immediately to that, else request destination from user description_attributes = d.GET(datafile)['description']['attributes'] try: deposition_context = description_attributes['deposition_context']['deposition_context'] except: deposition_context = None if not deposition_context: # try to resolve, and save deposition context as an implicit stage deposition_context = wizh.get_deposition_context(datafile) if deposition_context: d.save_description_stage(datafile, {'ref': 'deposition_context', 'data': {'deposition_context': deposition_context}}) if deposition_context: # as there might be previous description data, # we want to be able to load this, else follow the step-wise wizard path if len(description_attributes) > 1: context['stages'] = wizh.get_stages_display(datafile) else: # follow the step-wise wizard path auto_fields = {"current_stage": "deposition_context", "datafile": datafile} context['stage'] = dispatch_description[deposition_context](auto_fields) else: # if we couldn't infer deposition context, ask user's intervention df_wizard_dict = copy.deepcopy(lkup.DF_WIZARD) context['stage'] = { "title": "Verify Destination", "content": wtags.get_deposition_html(deposition_context) } elif step >= 2: auto_fields = ast.literal_eval(request.POST['auto_fields']) deposition_context = auto_fields["deposition_context"] if deposition_context == "": deposition_context = "default" auto_fields["datafile"] = datafile context['stage'] = dispatch_description[deposition_context](auto_fields) elif step == -1: # save all stages auto_fields = ast.literal_eval(request.POST['auto_fields']) # get the deposition context from the first element for a_f in auto_fields: auto_field = ast.literal_eval(a_f) auto_field["datafile"] = datafile wizh.save_stage_data(auto_field) out = jsonpickle.encode(context) return HttpResponse(out, content_type='json')