from quixote import get_publisher, get_request, redirect
from quixote.directory import Directory
from quixote.html import htmltext

import os

import wcs
import wcs.forms.root
import wcs.forms.preview
from wcs.qommon import _
from wcs.qommon import template
from wcs.qommon import errors
from wcs.qommon.form import *
from wcs.roles import logged_users_role

from wcs.qommon import emails

OldFormPage = wcs.forms.root.FormPage

class AlternateFormPage(OldFormPage):
    def form_side(self, *args, **kwargs):
        form_side_html = OldFormPage.form_side(self, *args, **kwargs)
        # add a 'Steps' title
        form_side_html = str(form_side_html).replace('<ol>', '<h2>%s</h2>\n<ol>' % _('Steps'))
        get_response().filter['gauche'] = form_side_html
        get_response().filter['steps'] = form_side_html
        return

wcs.forms.root.FormPage = AlternateFormPage
wcs.forms.root.PublicFormStatusPage.form_page_class = AlternateFormPage
wcs.forms.preview.PreviewFormPage.__bases__ = (AlternateFormPage,)


OldFormsRootDirectory = wcs.forms.root.RootDirectory

class AlternateFormsRootDirectory(OldFormsRootDirectory):
    def form_list(self, *args, **kwargs):
        form_list = OldFormsRootDirectory.form_list(self, *args, **kwargs)
        return htmltext(str(form_list).replace('h2>', 'h3>'))

wcs.forms.root.RootDirectory = AlternateFormsRootDirectory
