#stub - to be completed.

from rlextra.ers.webwidgets import WebWidget
from rlextra.forms.qbase import QBase
from rlextra.forms.qparser import parseQdfFile

class Question(WebWidget):
    "Basis for a horizontal section in a report"

    def __init__(self, field):
        "pass in a qfield"
        self.field = field
    def renderHTML(self, context=None):
        template = """
        <tr>
            <td>%s</td>
            <td>
                <input type="text" name="%s" value="%s"/>
            </td>
            <td>%s</td>
        </tr>
        """
        return template % (self.field.getCaption(),
                           self.field.name,
                           self.field.getTextValue(),
                           self.field.shortHelp
                           )



def test(qdfFileName):
    "take qdf file and make html file next to it..."
    import os
    outFileName = os.path.splitext(qdfFileName)[0] + '.html'

    obj = parseQdfFile(qdfFileName)
    obj.makeSample()
    
    out = open(outFileName, 'w')
    out.write("""
    <html><head><title>Test questionnaire from file %s</title></head>
    <body><h1>Questionnaire from %s</h1>
    """    % (qdfFileName, qdfFileName))

    html = obj.makeHtmlForm()
    out.write(html)
    out.write("<hr></body></html>\n")
    out.close()
    print 'wrote %s' % outFileName
    
    
if __name__=='__main__':
    import sys
    if len(sys.argv) <> 2:
        print 'usage: q2html.py myfile.qdf -> myfile.html'
    else:
        arg = sys.argv[1]
        test(arg)



    