def render_base_config(self): if isinstance(self.value, datetime) or isinstance(self.value, date): value = date2str(self.value) else: value = self.value super(ExtDateField, self).render_base_config() self._put_config_value('format', self.format) self._put_config_value('value', value) self._put_config_value( 'enableKeyEvents', self.enable_key_events, self.enable_key_events) self._put_config_value('startDay', self.start_day) self._put_config_value('maxValue', self.max_value) self._put_config_value('minValue', self.min_value) self._put_config_value('editable', self.editable)
def render_base_config(self): if isinstance(self.value, datetime) or isinstance(self.value, date): value = date2str(self.value) else: value = self.value super(ExtDateField, self).render_base_config() self._put_config_value('format', self.format) self._put_config_value('value', value) self._put_config_value('enableKeyEvents', self.enable_key_events, self.enable_key_events) self._put_config_value('startDay', self.start_day) self._put_config_value('maxValue', self.max_value) self._put_config_value('minValue', self.min_value) self._put_config_value('editable', self.editable)
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
def _date2str(*args): # lazy import from m3 import date2str return date2str(*args)
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