コード例 #1
0
    def get_object_by_key(self, key="slug"):
        """ Get object if the slug is in the system or return a new object """
        value = self.get_value(key)
        self.is_new = False

        if value:
            obj = self.find_by_key(key, value)

        if not value or not obj:
            # We assume that 'get_importables()' returned value contains
            # names of the objects that cannot be created via import but
            # can be updated.
            if self.block_converter.class_name.lower() not in get_importables(
            ):
                self.add_error(errors.CREATE_INSTANCE_ERROR)
            obj = self.object_class()
            self.is_new = True
        elif not permissions.is_allowed_update_for(obj):
            self.ignore = True
            self.add_error(errors.PERMISSION_ERROR)
        elif self._has_readonly_access(obj):
            self._is_obj_readonly = True

        self.initial_state = dump_attrs(obj)
        return obj
コード例 #2
0
ファイル: base_row.py プロジェクト: google/ggrc-core
  def get_object_by_key(self, key="slug"):
    """ Get object if the slug is in the system or return a new object """
    value = self.get_value(key)
    self.is_new = False

    if value:
      obj = self.find_by_key(key, value)

    if not value or not obj:
      # We assume that 'get_importables()' returned value contains
      # names of the objects that cannot be created via import but
      # can be updated.
      if self.block_converter.class_name.lower() not in get_importables() and \
              not self._check_object_is_external():
        self.add_error(errors.CREATE_INSTANCE_ERROR)
      obj = self.object_class()
      self.is_new = True
    elif not permissions.is_allowed_update_for(obj):
      self.ignore = True
      self.add_error(errors.PERMISSION_ERROR)
    elif self._has_readonly_access(obj):
      self._is_obj_readonly = True

    self.initial_state = dump_attrs(obj)
    return obj