Exemple #1
0
    def get_schema(self):
        schema_base = DataSchemas("COPO").get_ui_template().get("copo")
        x = data_utils.json_to_object(schema_base.get(self.component, dict()))

        return dict(schema_dict=schema_base.get(self.component, dict()).get("fields", list()),
                    schema=x.fields
                    )
Exemple #2
0
    def is_description_mismatch(self, auto_fields):
        """
        function verifies if description targets have any mismatch with submitted stage description
        :param auto_fields: form entries
        :return: boolean; True if there is a mismatch
        """
        # get target stage reference
        current_stage = auto_fields["current_stage"]

        # get target stage dictionary
        stage = self.get_batch_stage(current_stage)

        # build data dictionary
        data = DecoupleFormSubmission(auto_fields, d_utils.json_to_object(stage).items).get_schema_fields_updated()

        description_mismatch = False
        for target in self.description_targets:
            self.set_datafile_id(target["recordID"])
            target_description = self.get_datafile_description()['attributes']
            if current_stage in target_description:
                if data != target_description[current_stage]:
                    description_mismatch = True
                    break

        return description_mismatch
Exemple #3
0
    def get_schema(self):
        schema_base = DataSchemas("COPO").get_ui_template().get("copo")
        x = data_utils.json_to_object(schema_base.get(self.component, dict()))

        return dict(schema_dict=schema_base.get(self.component,
                                                dict()).get("fields", list()),
                    schema=x.fields)
Exemple #4
0
 def get_ui_template_as_obj(self):
     """obj_type specifies how the document should be returned: as 'dict' - python dictionary or
      'obj' - an object-typed notation"""
     doc = self.get_ui_template()
     if doc:
         return d_utils.json_to_object(doc)
     return doc
Exemple #5
0
    def save_stage_data(self, auto_fields):
        """
        function saves stage data
        auto_fields: data to be applied to description targets
        :return:
        """

        # get target stage reference
        current_stage = auto_fields.get("current_stage", str())

        # get target stage dictionary
        stage = self.get_batch_stage(current_stage)

        aggregate_data = list()

        # extract and save values for items in the description target

        # build data dictionary and apply to all targets
        data = DecoupleFormSubmission(auto_fields, d_utils.json_to_object(stage).items).get_schema_fields_updated()

        # aggregate target's data to aggregate
        aggregate_data.append(data)

        for target in self.description_targets:
            # 'focus' on target
            self.set_datafile_id(target["recordID"])

            # use batch stages to update targets
            self.update_datafile_stage(self.get_batch_stages())

            # retrieve previously saved data for the stage
            old_stage_data = self.get_stage_data(stage['ref']) or dict()

            # call to handle triggers defined on items
            self.handle_save_triggers(old_stage_data, data, stage)

            # update attribute, given data
            self.update_datafile_attributes({'ref': stage["ref"], 'data': data})

        # get batch attributes
        batch_attributes = self.get_batch_attributes()
        if not stage["ref"] in batch_attributes:
            batch_attributes[stage["ref"]] = list()

        # append targets' data to the batch aggregate
        batch_attributes[stage['ref']].append(data)

        # update batch description
        self.set_batch_attributes(batch_attributes)

        # update description targets
        self.update_targets_datafiles()

        return True