'Pre-process a CRUD request to create a new node
@param r: the request
@param table: the hierarchical table
@param parent_id: the parent ID'

def preprocess_create_node(self, r, parent_id):

    table = current.s3db.table(self.tablename)
    query = (table[self.pkey.name] == parent_id)
    DELETED = current.xml.DELETED
    if (DELETED in table.fields):
        query &= (table[DELETED] != True)
    parent = current.db(query).select(table._id).first()
    if (not parent):
        raise KeyError('Parent    record    not    found')
    link = self.link
    fkey = self.fkey
    if (self.link is None):
        fkey.default = fkey.update = parent_id
        fkey.comment = None
        if (r.http == 'POST'):
            r.post_vars[fkey.name] = parent_id
        fkey.readable = fkey.writable = False
        link = None
    else:
        link = {'linktable': self.link, 'rkey': fkey.name, 'lkey': self.lkey, 'parent_id': parent_id}
    return link
