Пример #1
0
 def create_objs(self, factory, list_of_scopes):
     """Create business objects used entities factories and Web UI
 (list of text scopes (list of dicts) got from Web UI).
 Return list of objects.
 """
     objs = [factory.create() for _ in xrange(len(list_of_scopes))]
     list_of_scopes_remaped = self.remap_keys_for_list_dicts(
         transform_dict=self.ui_elements_to_obj_attrs(),
         list_old_dicts=list_of_scopes)
     return [
         EntitiesFactory.update_obj_attrs_values(obj=obj, **scope_remaped)
         for scope_remaped, obj in zip(list_of_scopes_remaped, 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 [
       EntitiesFactory.update_objs_attrs_values_by_entered_data(
           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, 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 = [factory.create() for _ in xrange(len(list_scopes))]
   list_scopes_remapped = string_utils.remap_keys_for_list_dicts(
       dict_transformation_keys=self.ui_elements_to_obj_attrs(),
       list_dicts=list_scopes)
   return [
       EntitiesFactory.update_obj_attrs_values(
           obj=factory_obj, **scope_remapped) for
       scope_remapped, factory_obj in zip(list_scopes_remapped,
                                          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_remapped = string_utils.remap_keys_for_list_dicts(
       dict_transformation_keys=self.ui_elements_to_obj_attrs(),
       list_dicts=list_scopes)
   return [
       EntitiesFactory.update_obj_attrs_values(
           obj=factory_obj, **scope_remapped) for
       scope_remapped, factory_obj in zip(list_scopes_remapped,
                                          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)
     ]
Пример #6
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)]