Exemple #1
0
    def convert_value(self, value):
        """
        Конвертирует данные в JS строку
        """

        if value is None:
            res_value = '""'
        elif isinstance(value, bool):
            res_value = str(value).lower()
        elif isinstance(value, (int, Decimal, float)):
            res_value = str(value)
        elif isinstance(value, datetime.date):
            res_value = 'new Date("%s")' % value.ctime()
        else:
            res_value = '"%s"' % normalize(value)

        return res_value
Exemple #2
0
    def convert_value(self, value):
        """
        Конвертирует данные в JS строку
        """

        if value is None:
            res_value = '""'
        elif isinstance(value, bool):
            res_value = str(value).lower()
        elif isinstance(value, (int, Decimal, float)):
            res_value = str(value)
        elif isinstance(value, datetime.date):
            res_value = 'new Date("%s")' % value.ctime()
        else:
            res_value = '"%s"' % normalize(value)

        return res_value
Exemple #3
0
    def _put_base_value(
            self, src_list, extjs_name, item, condition=True, depth=0):
        """
        Управляет правильной установкой (в зависимости от типа)
        параметров контрола
        :param src_list: список словарей
        :type src_list: list
        :param extjs_name: Оригинальное название атрибута в ExtJs
        :type: extjs_name: str
        :param item: значение атрибута в М3
        :type item: basestring, bool, int, float, decimal, long, dict
        :param condition: Условие добавления в конфиг.
        :type condition: bool
        :param depth: глубина обхода
        :type depth: int

        :raise: ExtComponentException
        """
        conf_dict = {}
        res = None
        if item is None or not condition:
            return
        elif callable(item):
            res = self.__check_unicode(item())

        elif isinstance(item, basestring):

            # если в строке уже есть апостроф, то будет очень больно.
            # поэтому replace
            res = "'%s'" % normalize(self.__check_unicode(item))

        elif isinstance(item, bool):
            res = str(item).lower()

        elif isinstance(item, (int, float, decimal.Decimal, long)):
            res = item

        elif isinstance(item, datetime.date):
            res = "'%s'" % date2str(item)

        elif isinstance(item, dict):
            # рекурсивный обход вложенных свойств
            d_tmp = {}
            for k, v in item.items():
                prop = self._put_base_value(
                    src_list=src_list,
                    extjs_name=k,
                    item=v,
                    depth=depth + 1
                )
                if prop:
                    d_tmp[k] = prop[k]
            res = d_tmp

        elif hasattr(item, '__unicode__'):
            return self._put_base_value(
                src_list, extjs_name, unicode(item), condition, depth)
        else:
            # Эээээ... Выводится для себя
            raise ExtComponentException(
                u'Тип переданного параметра не '
                u'поддерживается: "%s":"%s"' % (extjs_name, item))

        if res is not None:
            conf_dict[extjs_name] = res
            if depth == 0:
                src_list.append(conf_dict)

            return conf_dict
Exemple #4
0
    def _put_base_value(self,
                        src_list,
                        extjs_name,
                        item,
                        condition=True,
                        depth=0):
        """
        Управляет правильной установкой (в зависимости от типа)
        параметров контрола
        :param src_list: список словарей
        :type src_list: list
        :param extjs_name: Оригинальное название атрибута в ExtJs
        :type: extjs_name: str
        :param item: значение атрибута в М3
        :type item: basestring, bool, int, float, decimal, long, dict
        :param condition: Условие добавления в конфиг.
        :type condition: bool
        :param depth: глубина обхода
        :type depth: int

        :raise: ExtComponentException
        """
        conf_dict = {}
        res = None
        if item is None or not condition:
            return
        elif callable(item):
            res = self.__check_unicode(item())

        elif isinstance(item, basestring):

            # если в строке уже есть апостроф, то будет очень больно.
            # поэтому replace
            res = "'%s'" % normalize(self.__check_unicode(item))

        elif isinstance(item, bool):
            res = str(item).lower()

        elif isinstance(item, (int, float, decimal.Decimal, long)):
            res = item

        elif isinstance(item, datetime.date):
            res = "'%s'" % date2str(item)

        elif isinstance(item, dict):
            # рекурсивный обход вложенных свойств
            d_tmp = {}
            for k, v in item.items():
                prop = self._put_base_value(src_list=src_list,
                                            extjs_name=k,
                                            item=v,
                                            depth=depth + 1)
                if prop:
                    d_tmp[k] = prop[k]
            res = d_tmp

        elif hasattr(item, '__unicode__'):
            return self._put_base_value(src_list, extjs_name, unicode(item),
                                        condition, depth)
        else:
            # Эээээ... Выводится для себя
            raise ExtComponentException(u'Тип переданного параметра не '
                                        u'поддерживается: "%s":"%s"' %
                                        (extjs_name, item))

        if res is not None:
            conf_dict[extjs_name] = res
            if depth == 0:
                src_list.append(conf_dict)

            return conf_dict