コード例 #1
0
ファイル: rf_utils_db.py プロジェクト: diegorufe/rfpyweb
    def fetch_value_query(vo_class_instance, ar_data):
        """
        Mehtod for fetch data in vo
        :param vo_class_instance: class for vo
        :param ar_data: to fetch
        :return: ar data for fetches values
        """
        ar_response = []
        if ar_data is not None:

            for data in ar_data:

                vo_instance = vo_class_instance()

                for key in data:
                    old_instance = vo_instance
                    ar_key_split = RFUtilsStr.split(key, FIELD_TABLE_SEPARATOR)

                    if RFUtilsArray.is_not_empty(ar_key_split):

                        for field in ar_key_split:
                            # Not use default alias
                            if field == DEFAULT_ALIAS:
                                continue
                            if RFUtilsBuilt.has_attr(old_instance, field):
                                old_tpm_instance = RFUtilsBuilt.get_attr(
                                    old_instance, field)

                                if old_tpm_instance is None:
                                    rf_column = RFContext.get_column_table(
                                        old_instance.__class__.__name__, field)
                                    if rf_column is not None and RFUtilsStr.is_not_emtpy(
                                            rf_column.join_vo_class_name
                                    ) is True:
                                        old_tpm_instance = RFContext.instance_vo(
                                            vo_class_name=rf_column.
                                            join_vo_class_name)
                                        RFUtilsBuilt.set_attr(
                                            old_instance, field,
                                            old_tpm_instance)
                                        old_instance = old_tpm_instance
                                    else:
                                        RFUtilsBuilt.set_attr(
                                            old_instance, field, data[key])
                                else:
                                    old_instance = old_tpm_instance

                            else:
                                break

                ar_response.append(vo_instance)

        return ar_response
コード例 #2
0
    def json_data_to_vo(self, vo_class_name, data):
        """
        Mehtod for fetch data in vo
        :param vo_class_name: class name for vo
        :param ar_data: to fetch
        :return: ar data for fetches values
        """

        vo_instance = RFContext.instance_vo(vo_class_name)

        if data is not None:
            for key, data_vo in data.items():
                rf_column = RFContext.get_column_table(vo_class_name, key)

                if data_vo is not None and rf_column is not None:
                    if isinstance(data_vo, Mapping):
                        RFUtilsBuilt.set_attr(vo_instance, key,
                                              self.json_data_to_vo(rf_column.join_vo_class_name, data_vo))
                    elif isinstance(data_vo, float):
                        RFUtilsBuilt.set_attr(vo_instance, key, Decimal(data_vo))
                    else:
                        RFUtilsBuilt.set_attr(vo_instance, key, data_vo)

        return vo_instance