示例#1
0
 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.create_empty() 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=Entity.items_of_remap_keys(),
       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 ["owners", "assignee", "creator", "verifier"] 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 [
       Entity.update_objs_attrs_values_by_entered_data(
           obj_or_objs=factory_obj, is_allow_none_values=False, **scope) for
       scope, factory_obj in zip(list_scopes_to_convert, list_factory_objs)]
示例#2
0
 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.create_empty() for _ in xrange(len(list_scopes))
     ]
     list_scopes_with_upper_keys = [
         string_utils.dict_keys_to_upper_case(scope)
         for scope in list_scopes
     ]
     list_scopes_to_convert = string_utils.exchange_dicts_items(
         transform_dict=Entity.items_of_remap_keys(),
         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
         string_utils.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] = string_utils.get_bool_value_from_arg(val)
                 # convert datetime attributes' directly
                 if key in ["updated_at", "created_at"]:
                     scope[key] = string_utils.convert_str_to_datetime(val)
                 # convert datetime attributes' in 'comments'
                 if (key == "comments" and isinstance(val, list) and all(
                         isinstance(comment, dict) for comment in val)):
                     # u'(Creator) 07/06/2017 05:47:14 AM UTC'
                     # to u'07/06/2017 05:47:14 AM UTC'
                     scope[key] = [{
                         k: (string_utils.convert_str_to_datetime(
                             re.sub(regex.TEXT_WITHIN_PARENTHESES, "", v))
                             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 ["owners", "assessor", "creator", "verifier"]:
                     # convert CSV like u'*****@*****.**' to u'Example User'
                     val = val if val != url.DEFAULT_USER_EMAIL else roles.DEFAULT_USER
                     # split multiple values if need 'Ex1, Ex2 F' to ['Ex1', 'Ex2 F']
                     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 "*" in val):
                     scope[key] = val.replace("*", "")
     return [
         Entity.update_objs_attrs_values_by_entered_data(
             obj_or_objs=factory_obj, is_allow_none_values=False, **scope)
         for scope, factory_obj in zip(list_scopes_to_convert,
                                       list_factory_objs)
     ]
示例#3
0
 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.create_empty() for _ in xrange(len(list_scopes))]
   list_scopes_with_upper_keys = [
       string_utils.dict_keys_to_upper_case(scope) for scope in list_scopes]
   list_scopes_to_convert = string_utils.exchange_dicts_items(
       transform_dict=Entity.items_of_remap_keys(),
       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
     string_utils.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] = string_utils.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_WITHIN_PARENTHESES,
                                        string_utils.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 ["owners", "assessor", "creator", "verifier"]:
           # split multiple values if need 'Ex1, Ex2 F' to ['Ex1', 'Ex2 F']
           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
                 string_utils.STAR in val):
           scope[key] = val.replace(string_utils.STAR, string_utils.BLANK)
   return [
       Entity.update_objs_attrs_values_by_entered_data(
           obj_or_objs=factory_obj, is_allow_none_values=False, **scope) for
       scope, factory_obj in zip(list_scopes_to_convert, list_factory_objs)]
示例#4
0
 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.create_empty() for _ in xrange(len(list_scopes))
     ]
     list_scopes_with_upper_keys = [
         string_utils.dict_keys_to_upper_case(scope)
         for scope in list_scopes
     ]
     list_scopes_remapped = string_utils.remap_keys_for_list_dicts(
         dict_of_transform_keys=Entity.items_of_remap_keys(),
         list_dicts=list_scopes_with_upper_keys)
     # add extra 'owners' attribute name and value if 'creator' in scopes
     list_extra_scopes = [
         dict(scope_remapped.items() +
              [("owners", scope_remapped.get("creator"))])
         if "creator" in scope_remapped.keys() else scope_remapped
         for scope_remapped in list_scopes_remapped
     ]
     # convert and represent values in scopes
     for scope in list_extra_scopes:
         for key, val in scope.iteritems():
             # convert u'false' and u'true' to boolean
             scope[key] = string_utils.get_bool_from_string(val)
             # convert multiple values to list of strings
             if key in ["owners", "assessor", "creator"]:
                 # convert CSV like u'*****@*****.**' to u'Example User'
                 val = val if val != url.DEFAULT_USER_EMAIL else roles.DEFAULT_USER
                 scope[key] = string_utils.convert_to_list(val)
             # convert 'slug' from CSV for snapshoted objects u'*23eb72ac-4d9d'
             if (key == "slug"
                     and self.obj_name in objects.ALL_SNAPSHOTABLE_OBJS
                     and "*" in val):
                 scope[key] = val.replace("*", "")
     return [
         EntitiesFactory.update_objs_attrs_values_by_entered_data(
             objs=factory_obj, is_allow_none_values=False, **scope)
         for scope, factory_obj in zip(list_extra_scopes, list_factory_objs)
     ]
示例#5
0
 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.create_empty() for _ in xrange(len(list_scopes))]
   list_scopes_with_upper_keys = [
       string_utils.dict_keys_to_upper_case(scope) for scope in list_scopes]
   list_scopes_remapped = string_utils.remap_keys_for_list_dicts(
       dict_of_transform_keys=Entity.items_of_remap_keys(),
       list_dicts=list_scopes_with_upper_keys)
   # add extra 'owners' attribute name and value if 'creator' in scopes
   list_extra_scopes = [
       dict(scope_remapped.items() +
            [("owners", scope_remapped.get("creator"))]) if
       "creator" in scope_remapped.keys() else scope_remapped for
       scope_remapped in list_scopes_remapped]
   # convert and represent values in scopes
   for scope in list_extra_scopes:
     for key, val in scope.iteritems():
       # convert u'false' and u'true' to boolean
       scope[key] = string_utils.get_bool_from_string(val)
       # convert multiple values to list of strings
       if key in ["owners", "assessor", "creator"]:
         # convert CSV like u'*****@*****.**' to u'Example User'
         val = val if val != url.DEFAULT_USER_EMAIL else roles.DEFAULT_USER
         scope[key] = string_utils.convert_to_list(val)
       # convert 'slug' from CSV for snapshoted objects u'*23eb72ac-4d9d'
       if (key == "slug" and
               self.obj_name in objects.ALL_SNAPSHOTABLE_OBJS and "*" in val):
         scope[key] = val.replace("*", "")
   return [
       EntitiesFactory.update_objs_attrs_values_by_entered_data(
           objs=factory_obj, is_allow_none_values=False, **scope) for
       scope, factory_obj in zip(list_extra_scopes, list_factory_objs)]