当前位置: 首页>>代码示例>>Python>>正文


Python StringMethods.dict_keys_to_upper_case方法代码示例

本文整理汇总了Python中lib.utils.string_utils.StringMethods.dict_keys_to_upper_case方法的典型用法代码示例。如果您正苦于以下问题:Python StringMethods.dict_keys_to_upper_case方法的具体用法?Python StringMethods.dict_keys_to_upper_case怎么用?Python StringMethods.dict_keys_to_upper_case使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在lib.utils.string_utils.StringMethods的用法示例。


在下文中一共展示了StringMethods.dict_keys_to_upper_case方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: remap_collection

# 需要导入模块: from lib.utils.string_utils import StringMethods [as 别名]
# 或者: from lib.utils.string_utils.StringMethods import dict_keys_to_upper_case [as 别名]
 def remap_collection():
   """Get transformation dictionary {'OLD KEY': 'NEW KEY'}, where
   'OLD KEY' - UI elements and CSV fields correspond to
   'NEW KEY' - objects attributes.
   """
   from lib.constants import element, files
   els = element.TransformationElements
   csv = files.TransformationCSVFields
   # common for UI and CSV
   result_remap_items = {
       els.TITLE: "title", els.ADMIN: "admins",
       els.CODE: "slug", els.REVIEW_STATE: "os_state",
       els.OBJECT_REVIEW: "os_state",
       els.STATE: "status"
   }
   ui_remap_items = {
       els.MANAGER: "managers", els.VERIFIED: "verified",
       els.STATUS: "status", els.LAST_UPDATED: "updated_at",
       els.AUDIT_CAPTAINS: "audit_captains", els.CAS: "custom_attributes",
       els.MAPPED_OBJECTS: "mapped_objects", els.ASSIGNEES: "assignees",
       els.CREATORS: "creators", els.VERIFIERS: "verifiers",
       els.COMMENTS_HEADER: "comments", els.CREATED_AT: "created_at",
       els.MODIFIED_BY: "modified_by", els.LAST_UPDATED_BY: "modified_by",
       els.UPDATED_AT: "updated_at", els.ASMT_TYPE: "assessment_type"
   }
   csv_remap_items = {
       csv.REVISION_DATE: "updated_at"
   }
   result_remap_items.update(ui_remap_items)
   result_remap_items.update(csv_remap_items)
   return StringMethods.dict_keys_to_upper_case(result_remap_items)
开发者ID:,项目名称:,代码行数:33,代码来源:

示例2: _create_list_objs

# 需要导入模块: from lib.utils.string_utils import StringMethods [as 别名]
# 或者: from lib.utils.string_utils.StringMethods import dict_keys_to_upper_case [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)]
开发者ID:egorhm,项目名称:ggrc-core,代码行数:59,代码来源:webui_service.py


注:本文中的lib.utils.string_utils.StringMethods.dict_keys_to_upper_case方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。