本文整理汇总了Python中lib.utils.string_utils.StringMethods.update_dicts_values方法的典型用法代码示例。如果您正苦于以下问题:Python StringMethods.update_dicts_values方法的具体用法?Python StringMethods.update_dicts_values怎么用?Python StringMethods.update_dicts_values使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类lib.utils.string_utils.StringMethods
的用法示例。
在下文中一共展示了StringMethods.update_dicts_values方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _create_list_objs
# 需要导入模块: from lib.utils.string_utils import StringMethods [as 别名]
# 或者: from lib.utils.string_utils.StringMethods import update_dicts_values [as 别名]
def _create_list_objs(self, entity_factory, list_scopes):
"""Create and return list of objects used entity factory and UI data
(list of scopes UI text elements {"header": "item", ...} remapped to
list of dicts {"attr": "value", ...}).
Return list of created objects.
"""
list_factory_objs = [
entity_factory().obj_inst() for _ in xrange(len(list_scopes))]
list_scopes_with_upper_keys = [
StringMethods.dict_keys_to_upper_case(scope) for scope in list_scopes]
list_scopes_to_convert = StringMethods.exchange_dicts_items(
transform_dict=Representation.remap_collection(),
dicts=list_scopes_with_upper_keys, is_keys_not_values=True)
# convert and represent values in scopes
for scope in list_scopes_to_convert:
# convert u'None', u'No person' to None type
StringMethods.update_dicts_values(scope, ["None", "No person"], None)
for key, val in scope.iteritems():
if val:
if key in ["mandatory", "verified"]:
# convert u'false', u'true' like to Boolean
scope[key] = StringMethods.get_bool_value_from_arg(val)
if key in ["updated_at", "created_at"]:
# UI like u'08/20/2017' to date=2017-08-20, timetz=00:00:00
datetime_val = parser.parse(val)
if str(datetime_val.time()) != "00:00:00":
# UI like u'08/20/2017 07:30:45 AM +03:00' to date=2017-08-20,
# timetz=04:30:45+00:00 if 'tzinfo', else:
# CSV like u'08-20-2017 04:30:45' to date=2017-08-20,
# timetz=04:30:45+00:00
datetime_val = (
datetime_val.astimezone(tz=tz.tzutc()) if datetime_val.tzinfo
else datetime_val.replace(tzinfo=tz.tzutc()))
scope[key] = datetime_val
if (key == "comments" and isinstance(val, list) and
all(isinstance(comment, dict) for comment in val)):
# extract datetime from u'(Creator) 08/20/2017 07:30:45 AM +03:00'
scope[key] = [
{k: (parser.parse(re.sub(regex.TEXT_W_PARENTHESES,
Symbols.BLANK, v)
).astimezone(tz=tz.tzutc())
if k == "created_at" else v)
for k, v in comment.iteritems()} for comment in val]
# convert multiple values to list of strings and split if need it
if (key in Representation.people_attrs_names and
not isinstance(val, list)):
# split Tree View values if need 'Ex1, Ex2 F' to ['Ex1', 'Ex2 F']
# Info Widget values will be represent by internal methods
scope[key] = val.split(", ")
# convert 'slug' from CSV for snapshoted objects u'*23eb72ac-4d9d'
if (key == "slug" and
(self.obj_name in objects.ALL_SNAPSHOTABLE_OBJS) and
Symbols.STAR in val):
scope[key] = val.replace(Symbols.STAR, Symbols.BLANK)
return [
factory_obj.update_attrs(is_allow_none=True, **scope) for
scope, factory_obj in zip(list_scopes_to_convert, list_factory_objs)]