def get_type_entities(self, type_id, user_permissions, scope):
        """
        Iterate over entities from collection matching the supplied type.

        'scope' is used to determine the extend of data top be included in the listing:
        a value of 'all' means that site-wide entyioties are icnluded in the listing.
        Otherwise only collection entities are included.        
        """
        entitytypeinfo = EntityTypeInfo(self._site, self._coll, type_id)
        include_sitedata = (scope == "all")
        for e in entitytypeinfo.enum_entities(user_permissions,
                                              usealtparent=include_sitedata):
            yield e
        return
Exemple #2
0
    def check_delete_type_values(self,
                                 listinfo,
                                 entity_id,
                                 entity_type,
                                 msg,
                                 continuation_url=None):
        """
        Checks for attempt to delete type with existing values

        Returns redirect URI to display error, or None if no error
        """
        if entity_type == "_type":
            typeinfo = EntityTypeInfo(listinfo.site, listinfo.collection,
                                      entity_id)
            if next(typeinfo.enum_entities(), None) is not None:
                return (
                    # Type has valu7es: redisplay form with error message
                    uri_with_params(listinfo.view.get_request_path(),
                                    listinfo.view.error_params(msg),
                                    continuation_url))
        return None
Exemple #3
0
    def rename_entity_type(self, viewinfo, old_typeinfo, old_type_id,
                           new_typeinfo, new_type_id, type_data):
        """
        Save a renamed type entity.

        This involves renaming all of the instances of the type to
        the new type (with new type id and in new location).

        Returns None if the operation succeeds, or error message
        details to be displayed as a pair of values for the message 
        heading and the message body.
        """
        # NOTE: old RecordData instance is not removed.

        # Don't allow type-rename to or from a type value
        if old_typeinfo.type_id != new_typeinfo.type_id:
            log.warning(
                "EntityEdit.rename_entity_type: attempt to change type of type record"
            )
            return (message.INVALID_OPERATION_ATTEMPTED,
                    message.INVALID_TYPE_CHANGE)
        # Don't allow renaming built-in type
        builtin_types = get_built_in_type_ids()
        if (new_type_id in builtin_types) or (old_type_id in builtin_types):
            log.warning(
                "EntityEdit.rename_entity_type: attempt to rename or define a built-in type"
            )
            return (message.INVALID_OPERATION_ATTEMPTED,
                    message.INVALID_TYPE_RENAME)

        # Create new type record
        new_typeinfo.create_entity(new_type_id, type_data)

        # Update instances of type
        src_typeinfo = EntityTypeInfo(viewinfo.site, viewinfo.collection,
                                      old_type_id)
        dst_typeinfo = EntityTypeInfo(viewinfo.site,
                                      viewinfo.collection,
                                      new_type_id,
                                      create_typedata=True)
        if new_typeinfo.entity_exists(new_type_id):
            # Enumerate type instance records and move to new type
            remove_OK = True
            for d in src_typeinfo.enum_entities():
                data_id = d.get_id()
                data_vals = d.get_values()
                data_vals[ANNAL.CURIE.type_id] = new_type_id
                data_vals[
                    ANNAL.CURIE.type] = dst_typeinfo.entityclass._entitytype
                if self.rename_entity(src_typeinfo, data_id, dst_typeinfo,
                                      data_id, data_vals):
                    remove_OK = False
            # Finally, remove old type record:
            if remove_OK:  # Precautionary
                new_typeinfo.remove_entity(old_type_id)
                RecordTypeData.remove(new_typeinfo.entitycoll, old_type_id)
        else:
            log.warning("Failed to rename type %s to type %s" %
                        (old_type_id, new_type_id))
            return (message.SYSTEM_ERROR,
                    message.RENAME_TYPE_FAILED % (old_type_id, new_type_id))
        return None