def textarea_field(data): textarea_doc, textarea_tag, textarea_text = Doc(defaults={}, errors={}).tagtext() with textarea_tag('div', klass="form-group"): with textarea_tag('label', ('for', data['id'])): textarea_text(modeler(data)) with textarea_doc.textarea(('v-model', data['vmodel']), name=data['name'], rows=data['rows'], placeholder=data['placeholder'], id=data['id'], klass='form-control'): pass return textarea_doc.getvalue()
def demoForm(self): defaults = self.defaults.copy() errors = {} request = self.request() if request.hasField('message'): subject = self.request().field('subject') defaults['subject'] = subject if not subject: errors['subject'] = 'Please add the subject of your message.' elif self.isSpam(subject): errors['subject'] = 'Your subject looks like spam!' message = self.request().field('message') defaults['message'] = message if not message: errors['message'] = 'You did not enter a message!' elif self.isSpam(message): errors['message'] = 'Your message looks like spam!' else: subject = message = None doc = Doc(defaults=defaults, errors=errors) tag, text = doc.tag, doc.text if message and not errors: with tag('p', klass='success'): text('Congratulations! You have sent the following message:') with tag('div', klass='output'): with tag('p'): with tag('strong'): text(subject) with tag('p'): text(message) with tag('a', href='YattagDemo'): text('Try sending another message.') else: with tag('h2'): text('Demo contact form') with tag('form', action="YattagDemo"): doc.input(name='subject', type='text', size=80) with doc.textarea(name='message', cols=80, rows=8): pass doc.stag('input', type='submit', value='Send my message') return doc.getvalue()
def test_textarea(self): doc, tag, text = Doc(defaults={ 'contact_message': 'You just won the lottery!' }, errors={ 'contact_message': 'Your message looks like spam.' }).tagtext() with tag('p'): with doc.textarea(('data-my-data', '12345'), name='contact_message'): pass root = ET.fromstring(doc.getvalue()) self.assertEqual(root[1].attrib['class'], 'error') self.assertEqual(root[1].attrib['data-my-data'], '12345') self.assertEqual(root[1].text, 'You just won the lottery!')
def test_textarea(self): doc, tag, text = Doc( defaults = { 'contact_message': 'You just won the lottery!' }, errors = { 'contact_message': 'Your message looks like spam.' } ).tagtext() with tag('p'): with doc.textarea(('data-my-data', '12345'), name = 'contact_message'): pass root = ET.fromstring(doc.getvalue()) self.assertEqual( root[1].attrib['class'], 'error' ) self.assertEqual( root[1].attrib['data-my-data'], '12345' ) self.assertEqual( root[1].text, 'You just won the lottery!' )
class MyHtml(HtmlCreator): def initDocTagText(self): self.doc, self.tag, self.text = Doc( defaults={ 'title': 'Untitled', 'contact_message': 'You just won the lottery!' } ).tagtext() def design_header(self): with self.tag('head'): with self.tag('title'): self.text('A title.') def design_body(self): with self.tag('body'): with self.tag('h1'): self.text('Contact form') with self.tag('form', action=""): self.doc.input(name='title', type='text') with self.doc.textarea(name='contact_message'): pass self.doc.stag('input', type='submit', value='Send my message')
from yattag import Doc from yattag import indent doc, tag, text, line = Doc(defaults={ 'title': 'Untitled', 'contact_message': 'You just won the lottery!' }, errors={ 'contact_message': 'Your message looks like spam.' }).ttl() line('h1', 'Contact form') with tag('form', action=""): doc.input(name='title', type='text') with doc.textarea(name='contact_message'): pass doc.stag('input', type='submit', value='Send my message') result = indent(doc.getvalue(), indentation=' ', newline='\r\n', indent_text=True) print(result)
def lambda_handler(event, context): global visitorcount visitorcount += 1 print("You're the " + str(visitorcount) + " visitor") configuration = yaml.load(open("config.yaml").read()) questions = configuration['Questions'] title = configuration['Title'] author = configuration['Author'] image = configuration['Image'] theme = configuration['Theme'] questionsNames = list() for questionIterator in questions: questionsNames.append(questionIterator) questionsNames.sort() doc, tag, text = Doc().tagtext() with tag('html'): with tag('body'): doc.stag('br') doc.stag('br') doc.stag('br') with tag('div', align='center'): doc.stag( 'font', size="6", style="font-weight: bold; font-family: verdana; color:#" + str(theme) + ";") text(title) doc.stag('br') doc.stag('font', size="2", style="font-weight: bold; font-family: verdana") text("by " + author) doc.stag('br') doc.stag('img', src=image, width="500") doc.stag('br') doc.stag('br') with tag('form', action="submitsurvey"): with tag('div', style= "margin-left: auto; margin-right: auto; width: 40%;"): for questionName in questionsNames: questionLabel = questions[questionName]['Label'] questionType = questions[questionName]['Type'] doc.stag( 'font', size="4", style= "font-weight: bold; font-family: verdana; color:#" + str(theme) + ";") text(questionLabel) doc.stag('br') if (questionType == "Text"): with doc.textarea( name=questionName, style="width: 100%; border-color: #" + str(theme) + "; ", rows="5"): pass if (questionType == "ShortText"): with doc.textarea( name=questionName, style="width: 100%; border-color: #" + str(theme) + "; ", rows="1"): pass if (questionType == "Radio"): values = questions[questionName]['Values'] for valueIterator in values: value = questions[questionName]['Values'][ valueIterator] doc.input(name=questionName, type='radio', value=value, style="border-color: #" + str(theme) + "; ") doc.stag( 'font', size="2", style= "font-weight: normal; font-family: verdana; color:black" ) text(str(value)) doc.stag('br') doc.stag('br') doc.stag('br') doc.stag( 'input', type="submit", value="Send!", style="background-color: #" + str(theme) + "; border: none; color: white; float: right; padding: 15px 32px; text-align: center; text-decoration: none; display: inline-block; font-size: 16px; margin: 4px 2px; cursor: pointer;" ) htmlResult = doc.getvalue() return { 'statusCode': "200", 'body': htmlResult, 'headers': { 'Content-Type': 'text/html', } }
def lambda_handler(event, context): configuration = yaml.load(open("config.yaml").read()) questions = configuration['Questions'] title = configuration['Title'] author = configuration['Author'] image = configuration['Image'] theme = configuration['Theme'] questionsNames = list() for questionIterator in questions: questionsNames.append(questionIterator) questionsNames.sort() doc, tag, text = Doc().tagtext() with tag('html'): with tag('body'): doc.stag('br') doc.stag('br') doc.stag('br') with tag('div', align='center'): with doc.tag( 'div', style= "font-size: medium;font-weight: bold; font-family: verdana; color:#" + str(theme) + ";"): text(title) doc.stag('br') with doc.tag( 'div', style= "font-size: small; font-weight: bold; font-family: verdana;" ): text("by " + author) doc.stag('br') doc.stag('img', src=image, width="500") doc.stag('br') doc.stag('br') with tag('form', action="submitsurvey", style="margin-left: auto; margin-right: auto; width: 70%;" ): for questionName in questionsNames: with tag('div'): questionLabel = questions[questionName]['Label'] questionType = questions[questionName]['Type'] #doc.stag('font', size="4", style="font-weight: bold; font-family: verdana; color:#" + str(theme) + ";") with doc.tag( 'div', style= "font-size: medium;font-weight: bold; font-family: verdana; color:#" + str(theme) + ";"): doc.asis(questionLabel) doc.stag('br') if (questionType == "Text"): with doc.textarea( name=questionName, style="width: 100%; border-color: #" + str(theme) + "; ", rows="5"): pass if (questionType == "ShortText"): with doc.textarea( name=questionName, style="width: 100%; border-color: #" + str(theme) + "; ", rows="1"): pass if (questionType == "Radio"): values = questions[questionName]['Values'] for valueIterator in values: value = questions[questionName]['Values'][ valueIterator] with doc.tag( 'div', style= "font-size: small; font-weight: normal; font-family: verdana; color:black;" ): doc.input(name=questionName, type='radio', value=value, style="border-color: #" + str(theme) + "; ") text(" " + str(value)) doc.stag('br') if (questionType == "CheckBox"): with tag( 'fieldset', style= "border: 0px; padding: 0px; font-size: small; font-weight: normal; font-family: verdana; color:black;" ): values = list( questions[questionName]['Values']) for valueIterator in values: value = questions[questionName]['Values'][ valueIterator] field_name = questionName + "_" + "".join([ c if c.isalnum() else "_" for c in value.lower() ]) doc.input(name=field_name, type='hidden', value="0", style="border-color: #" + str(theme) + "; ") doc.input(name=field_name, id=field_name, type='checkbox', value="1", style="border-color: #" + str(theme) + "; ") text(" " + str(value)) doc.stag('br') doc.stag('br') doc.stag('br') doc.stag( 'input', type="submit", value="Send!", style="background-color: #" + str(theme) + "; border: none; color: white; float: right; padding: 15px 32px; text-align: center; text-decoration: none; display: inline-block; font-size: 16px; margin: 4px 2px; cursor: pointer;" ) htmlResult = doc.getvalue() return { 'statusCode': "200", 'body': htmlResult, 'headers': { 'Content-Type': 'text/html', } }