def _format_author(name, server):
    '''Create an armory-linked author name.'''
    # If there is no server, just return name.
    if server == "": return name
    locale,server_name = server.split("-")
    locale      = locale.lower()
    server_name = server_name.replace(" ", "-").lower()
    return ARMORY_LINK % (locale, server_name, urllib.quote(name.encode("utf-8")), escape(name))
def generate_edit_page(path, macro=None, save_values={}, macro_id=None):
    '''
    Generate edit page via template.  Exceptions propogated upwards.
    Propogates exceptions up.
    '''
    # Two parts to this page: macro form and link form.
    macro_form_html       = ''
    macro_link_html       = ''

    # Start filling in the macro form template
    macro_form_template_values = {
        'intro_text'      : FORM_MACRO_INPUT_HELP,
        'macro_process':    URL_MACRO_PROCESS,
        'macro_input_form': FORM_MACRO_INPUT,}
    
    # If we got a macro_id, attempt to get the macro from it.
    macro_obj = None
    if valid(macro_id):
        macro_obj = get_macro_obj_from_id(macro_id)
        macro     = macro_obj.macro
    elif valid(macro):
        # Import big modules locally to avoid unneccesary work.
        from macro.interpret.interpreter import MacroInterpreter
        macro_obj = MacroInterpreter().interpret_macro(macro)

     # If we got a good macro, display its interpretation
    if valid(macro):
        # Add the macro to the form.
        if macro_obj.macro_changed:
            macro_form_template_values['macro'] = _render_clean_cmd(macro_obj)
            macro_form_template_values['changed'] = MACRO_CHANGED
        else:
            macro_form_template_values['macro'] = macro

        # Grab the templates for both the interpretation and the
        # processed macro, and populate them.
        macro_form_template_values['processed_macro_html'] = \
           render_macro(macro_obj, path)
        
        # If we have a valid macro that we could try saving,
        # generate form.  Also, only do this if we didn't come
        # directly from a view--no need to re-save a macro.
        if macro_obj.macro_good and not macro_id:
            macro_unesc = _render_clean_cmd(macro_obj)
            macro_esc   = escape(macro_unesc)
            macro_link_template_values = {
                'title_show'      : "none",
                'title_hide'      : "block",
                'notes_show'      : "none",
                'notes_hide'      : "block",
                'link_process'    : URL_SAVE_PROCESS,
                'macro_input_form': FORM_MACRO_INPUT,
                'macro'           : macro_unesc,
                'macro_esc'       : macro_esc,
                'macro_is_esc '   : FORM_MACRO_ESC,
                'title'           : FORM_SAVE_TITLE,
                'name'            : FORM_SAVE_NAME,
                'notes'           : FORM_SAVE_NOTES,
                'server'          : FORM_SAVE_SERVER,
                'classes'         : FORM_SAVE_CLASSES,
                'tags'            : FORM_SAVE_TAGS,
                'note_limit'      : NOTES_TEXT_LENGTH,
                'note_ch_left'    : NOTES_TEXT_LENGTH,
                'class_list'      : translate_classmap(),
                'tag_def_list'    : TAG_LIST,
                'tag_list'        : '',
                'server_list'     : render_template('servers.template', path=path),
                'selected_server' : '',
                'curr_version'    : "%s.%s.%s" % (MAJOR_VERSION,
                                                  MINOR_VERSION,
                                                  PATCH_VERSION),
                }
            
            # Is this another save attempt after errors?  If so, update
            # with errors and previous values.
            macro_link_template_values.update(save_values)

            # Render the template.
            macro_link_html = render_template('save_form.template',
                                              macro_link_template_values,
                                              path)
    
    # Add in the link html.
    macro_form_template_values['macro_link_html'] = \
           macro_link_html

    # Render the macro form template html.
    ret_page  = render_template('macro_form.template',
                                macro_form_template_values,
                                path)

    return render_template('base.template',
                           {'content': ret_page },
                           path)