def publish_model(cursor, model, publisher, message):
publishers = publisher<EOL>if isinstance(publishers, list) and len(publishers) > <NUM_LIT:1>:<EOL><INDENT>raise ValueError("<STR_LIT>"<EOL>"<STR_LIT>"<EOL>.format(len(publishers), publishers))<EOL><DEDENT>module_ident, ident_hash = _insert_metadata(cursor, model,<EOL>publisher, message)<EOL>for resource in getattr(model, '<STR_LIT>', []):<EOL><INDENT>_insert_resource_file(cursor, module_ident, resource)<EOL><DEDENT>if isinstance(model, Document):<EOL><INDENT>html = bytes(cnxepub.DocumentContentFormatter(model))<EOL>sha1 = hashlib.new('<STR_LIT>', html).hexdigest()<EOL>cursor.execute("<STR_LIT>", (sha1,))<EOL>try:<EOL><INDENT>fileid = cursor.fetchone()[<NUM_LIT:0>]<EOL><DEDENT>except TypeError:<EOL><INDENT>file_args = {<EOL>'<STR_LIT>': '<STR_LIT>',<EOL>'<STR_LIT:data>': psycopg2.Binary(html),<EOL>}<EOL>cursor.execute("""<STR_LIT>""", file_args)<EOL>fileid = cursor.fetchone()[<NUM_LIT:0>]<EOL><DEDENT>args = {<EOL>'<STR_LIT>': module_ident,<EOL>'<STR_LIT:filename>': '<STR_LIT>',<EOL>'<STR_LIT>': fileid,<EOL>}<EOL>cursor.execute("""<STR_LIT>""", args)<EOL><DEDENT>elif isinstance(model, Binder):<EOL><INDENT>tree = cnxepub.model_to_tree(model)<EOL>tree = _insert_tree(cursor, tree)<EOL><DEDENT>return ident_hash<EOL>
Publishes the ``model`` and return its ident_hash.