def main():

    name = ShowQueue.init_log()
    ryw_view.print_header_logo()
    print '<TITLE>Browsing Saved Selection</TITLE>'

    success,objID,version = ryw.get_obj_str()
    if not success:
        ryw.give_bad_news('DisplaySelection: failed to get objstr.',
                          logging.critical)
        exit_now(1)

    offsetResult = ShowQueue.get_offset()
    success,isAll,offsetNum = offsetResult
    if not success:
        exit_now(1)

    success,searchFile,reverseLists = \
        ReverseLists.open_searchfile_reverselists(
        'DisplaySelection.main:')
    if not success:
        sys.exit(1)

    success = print_title(objID, version, name, searchFile)
    if not success:
        exit_now(1)

    nameTriple = get_file_paths2(objID, version, searchFile = searchFile)
    if not nameTriple:
        exit_now(1)
    rfpath,chapterListPath,chapterFullName = nameTriple
    if not rfpath:
        exit_now(1)

    reqList = ShowQueue.read_list(rfpath)
    if not reqList:
        ryw.give_news('This selection is empty.<BR>', logging.info)
        print '<BR>'
        print_links(objID, version, name)
        exit_now(0)

    #
    # do this before displaying so that the ReverseLists is
    # properly reflected before we hit the display code.
    #
    result = reverseLists.add(objID + '#' + str(version), reqList)

    #
    # process the chapter list. 10/24/08.
    #
    success,chapterList = ChapterList.create_and_initialize(
        objID + '#' + str(version),
        reqList, searchFile, reverseLists,
        chapterFullName)
    if not success:
        ryw.give_bad_news('ChapterList.create_and_initialize failed: ' +
                          objID + '#' + str(version), logging.error)
        exit_now(1)

    scriptName = '/cgi-bin/DisplaySelection.py?objstr=' + \
                 objID + '%23' + str(version)
    
    success = \
            ShowQueue.go_through_list(reqList,
                                      callBackFunc = delOneSelFunc, 
                                      cBackArg = objID + '#' + str(version),
                                      offResult = offsetResult,
                                      cgiScript = scriptName,
                                      scriptConnectChar = '&',
                                      searchFile = searchFile,
                                      reverseLists = reverseLists,
                                      chapterList = chapterList)

    if success:
        print_links(objID, version, name)
        
    ryw_view.print_footer()

    reverseLists.done()
    searchFile.done()
def main():
    """modeled after DisplaySelection.py.
    This is for displaying a form that allows editing the chapter list."""

    name = ShowQueue.init_log()
    ryw_view.print_header_logo()
    print '<TITLE>Edit the Chapter List</TITLE>'

    success,objID,version = ryw.get_obj_str()
    if not success:
        ryw.give_bad_news('ChapterListForm: failed to get objstr.',
                          logging.critical)
        DisplaySelection.exit_now(1)

    success,searchFile,reverseLists = \
        ReverseLists.open_searchfile_reverselists(
        'DisplaySelection.main:')
    if not success:
        DisplaySelection.exit_now(1)

    print '<BR><B>Edit chapter names for this selection:</B><BR><BR>'

    success = DisplaySelection.print_title(objID, version, name, searchFile)
    if not success:
        DisplaySelection.exit_now(1)

    ryw.db_print2('<BR>ChapterListForm.py entered.<BR>', 38)
    
    nameTriple = DisplaySelection.get_file_paths2(
        objID, version, searchFile = searchFile)
    if not nameTriple:
        DisplaySelection.exit_now(1)
    rfpath,chapterListPath,chapterFullName = nameTriple
    if not rfpath:
        DisplaySelection.exit_now(1)

    reqList = ShowQueue.read_list(rfpath)
    if not reqList:
        ryw.give_news('This selection is empty.<BR>', logging.info)
        print '<BR>'
        print_links(objID, version, name)
        DisplaySelection.exit_now(0)

    ryw.db_print2('ChapterListForm.py: gotten selection list.', 38)

    success,chapterList = ChapterList.create_and_initialize(
        objID + '#' + str(version),
        reqList, searchFile, reverseLists,
        chapterFullName)
    if not success:
        ryw.give_bad_news('ChapterList.create_and_initialize failed: ' +
                          objID + '#' + str(version), logging.error)
        DisplaySelection.exit_now(1)

    page = chapterList.make_form_string()
    print page
    
    ryw_view.print_footer()

    reverseLists.done()
    searchFile.done()