Beispiel #1
0
 def get_form(self,value=''):
   body = ("""<input type="text" name"${name}"
                     value="${value}" """
           """${attrs} />""")
   t = SimpleTemplate(body)
   return t.render({'name':self.name, 'value':value,
                    'attrs':self.attrs})
Beispiel #2
0
def listurl(_request):
    res=Response()
    rsslist=Rssurl.select()
    t=SimpleTemplate(file_path=relativepath('urllist.html'))
    body=t.render({'rsslist': rsslist})
    res.set_body(body)
    return res
Beispiel #3
0
def listurl(_request):
    res = Response()
    rsslist = Rssurl.select()
    t = SimpleTemplate(file_path=relativepath('urllist.html'))
    body = t.render({'rsslist': rsslist})
    res.set_body(body)
    return res
Beispiel #4
0
 def display(self, values={}, errors={}):
     container = ""
     for f in self.forms:
         container += f.display(values.get(f.name, ""), errors.get(f.name, ""))
         container += """<br clear="all" />"""
     body = """<form ${attrs}>\n""" """${container}\n""" """</form>\n"""
     t = SimpleTemplate(body)
     return t.render({"attrs": self.attrs, "container": container})
Beispiel #5
0
 def get_form(self, value=""):
     body = """<textarea name="${name}" ${attrs}>${value}</textarea>"""
     t = SimpleTemplate(body)
     return t.render({
         "name": self.name,
         "value": value,
         "attrs": self.attrs
     })
Beispiel #6
0
def login_form(_request, values={}, errors={}):
    body = base_body % ("${form.display(values, errors)}")
    res = Response()
    t = SimpleTemplate(body)
    values["password"] = ""
    body = t.render({"form": loginform, "values": values, "errors": errors})
    res.set_body(body)
    return res
Beispiel #7
0
def index(_request, foo="", d={"counter": 0}):
    body = base_body % ("<p>Logged in!</p>")
    res = Response()
    t = SimpleTemplate(body)
    body = t.render(d)
    d["counter"] += 1
    res.set_body(body)
    return res
Beispiel #8
0
 def test_handle_value2(self):
     dic = {'value':'actual'}
     t = SimpleTemplate('${value}value')
     m = value_pat.search(t.lines[0])
     self.assertIsNotNone(m)
     cur, o = t.handle_value(m, 0, dic)
     self.assertEqual(0, cur)
     self.assertEqual('actualvalue\n', o)
Beispiel #9
0
def index(_request, d={"counter": 0}):
    body = """<html><body><p>${counter}</p></body></html>"""
    res = Response()
    t = SimpleTemplate(body)
    body = t.render(d)
    d["counter"] += 1
    res.set_body(body)
    return res
Beispiel #10
0
def login_form(_request, values={}, errors={}):
    body = base_body % ('${form.display(values, errors)}')
    res = Response()
    t = SimpleTemplate(body)
    values['password'] = ''
    body = t.render({'form': loginform, 'values': values, 'errors': errors})
    res.set_body(body)
    return res
Beispiel #11
0
def index(_request, foo='', d={'counter': 0}):
    body = base_body % ('<p>Logged in!</p>')
    res = Response()
    t = SimpleTemplate(body)
    body = t.render(d)
    d['counter'] += 1
    res.set_body(body)
    return res
Beispiel #12
0
 def get_label(self, error):
     body = ("""<label for="${name}">${label}\n"""
             """$if error:\n"""
             """<span class="error">${error}</span>\n"""
             """$endif\n"""
             """</label>""")
     t = SimpleTemplate(body)
     return t.render({'name': self.name, 'label': self.label, 'error': error})
Beispiel #13
0
 def get_form(self, value=''):
     body = """<textarea name="${name}" ${attrs}>${value}</textarea>"""
     t = SimpleTemplate(body)
     return t.render({
         'name': self.name,
         'value': value,
         'attrs': self.attrs
     })
def login_form(_request, values={}, errors={}):
    body = base_body % ('${form.display(values, errors)}')
    res = Response()
    t = SimpleTemplate(body)
    values['password'] = ''
    body = t.render({'form': loginform, 'values': values, 'errors': errors})
    res.set_body(body)
    return res
Beispiel #15
0
def get_add_form(values={}, errors={}):
    res = Response()
    t = SimpleTemplate(file_path=relativepath('form.html'))
    body = t.render({'message': 'RSS巡回用URLの追加',
                     'form': addform,
                     'values': values, 'errors': errors})
    res.set_body(body)
    return res
Beispiel #16
0
    def test_process(self):
        with mock.patch('simpletemplate.SimpleTemplate.process') as m:
            m.return_value = [0, '']
            t = SimpleTemplate('value')

            o = t.render()
            self.assertEqual(m.call_count, 1)
            self.assertEqual('', o)
Beispiel #17
0
 def test_handle_value(self):
     t = SimpleTemplate('${value}')
     m = value_pat.search(t.lines[0])
     self.assertIsNotNone(m)
     dict = {'value':'actual'}
     cur, o = t.handle_value(m, 0, dict)
     self.assertEqual(0, cur)
     self.assertEqual('actual\n', o)
Beispiel #18
0
def get_add_form(values={}, errors={}):
    res=Response()
    t=SimpleTemplate(file_path=relativepath('form.html'))
    body=t.render({'message': u'RSS巡回用URLの追加',
                   'form':addform,
                   'values':values, 'errors':errors})
    res.set_body(body)
    return res
Beispiel #19
0
def index(_request, d={'counter': '0'}):
    body = """<html><body><p>${counter}</p></body></html>"""
    res = Response()
    t = SimpleTemplate(body)
    body = t.render(d)
    d['counter'] = str(int(d['counter']) + 1)
    res.set_body(body)
    return res
def login_form(_request, values={}, errors={}):
    res=Response()
    t=SimpleTemplate(file_path=relativepath('form.html'))
    values['password']=''
    body=t.render({'form':loginform, 'values':values, 'errors':errors,
                   'message':u'ログイン'})
    res.set_body(body)
    return res
Beispiel #21
0
 def get_label(self, error):
     body = ("""<label for="${name}">${label}\n"""
             """$if error:\n"""
             """<span class="error">${error}</span>\n"""
             """$endif\n"""
             """</label>""")
     t = SimpleTemplate(body)
     return t.render({'name': self.name, 'label': self.label, 'error': error})
def index(_request, foo='', d={'counter': '0'}):
    body = base_body % ('<p>Logged in!</p>')
    res = Response()
    t = SimpleTemplate(body)
    body = t.render(d)
    d['counter'] = str(int(d['counter']) + 1)
    res.set_body(body)
    return res
def index(_request, d={'counter': '0'}):
    body = """<html><body><p>${counter}</p></body></html>"""
    res = Response()
    t = SimpleTemplate(body)
    body = t.render(d)
    d['counter'] = '1'
    res.set_body(body)
    return res
Beispiel #24
0
 def get_form(self, value=""):
     body = ("""<input type="text" name="${name}" value="${value}" """
             """${attrs} />""")
     t = SimpleTemplate(body)
     return t.render({
         "name": self.name,
         "value": value,
         "attrs": self.attrs
     })
Beispiel #25
0
 def get_form(self, value=''):
     body = ("""<input type="text" name="${name}" value="${value}" """
             """ ${attrs} />""")
     t = SimpleTemplate(body)
     return t.render({
         'name': self.name,
         'value': value,
         'attrs': self.attrs
     })
Beispiel #26
0
 def display(self, values={}, errors={}):
     container = ''
     for f in self.forms:
         container += f.display(values.get(f.name, ''),
                                errors.get(f.name, ''))
         container += """<br clear="all"/>"""
     body = ("""<form ${attrs}>\n""" """${container}\n""" """</form>\n""")
     t = SimpleTemplate(body)
     return t.render({'attrs': self.attrs, 'container': container})
 def test_call_stbookmarkform(self):
     p=path.join(path.dirname(__file__),"stbookmarkform.html")
     t=SimpleTemplate(file_path=p)
     value_dic={}
     value_dic["message"]="Message"
     value_dic["title"]="Title"
     value_dic["url"]="URL"
     value_dic["bookmarks"]=("Yahoo!","http://www.yahoo.co.jp")
     body=t.render(value_dic)
     print body
Beispiel #28
0
 def display(self, values={}, errors={}):
     container = ''
     for f in self.forms:
         container += f.display(values.get(f.name, ''), errors.get(f.name, ''))
         container += """<br clear="all" />"""
     body = ("""<form ${attrs}>\n"""
             """${container}\n"""
             """</form>\n""")
     t = SimpleTemplate(body)
     return t.render({'attrs': self.attrs, 'container': container})
Beispiel #29
0
 def get_form(self, value=''):
     body = ("""$for v in options:\n"""
             """${v[1]} : """
             """<input type="radio" name="${name}" value="${v[0]}"\n"""
             """$if value==v[0]:\n"""
             """ checked \n"""
             """$endif\n"""
             """/>\n"""
             """$endfor\n""")
     t = SimpleTemplate(body)
     return t.render({'name': self.name, 'value': value, 'options':self.options, 'attrs': self.attrs})
Beispiel #30
0
 def get_form(self, value=''):
     body=("""$for v in options:\n"""
           """${v[1]} : """
           """<input type="radio" name="${name}" value="${v[0]}"\n"""
           """$if value == v[0]:\n"""
           """ checked \n"""
           """$endif\n"""
           """>\n"""
           """$endfor\n""")
     t = SimpleTemplate(body)
     return t.render({'name': self.name, 'value': value, 'options': self.options, 'attrs': self.attrs})
Beispiel #31
0
    def test_process2(self):
        t = SimpleTemplate("""
$if True:
    test
$endif
""")
        body = t.render({})
        self.assertEqual("""
    test

""", body)
Beispiel #32
0
def get_add_form(values={}, errors={}):
    res = Response()
    t = SimpleTemplate(file_path=relativepath("form.html"))
    body = t.render({
        "message": u"RSS巡回用URLの追加",
        "form": addform,
        "values": values,
        "errors": errors
    })
    res.set_body(body)
    return res
Beispiel #33
0
def get_edit_form(item_id, values={}, errors={}):
    res = Response()
    t = SimpleTemplate(file_path=relativepath('form.html'))
    if not values:
        for item in Rssurl.select(id=item_id):
            pass
        values = {'item_id': item_id, 'title':item.title, 'url': item.url}
    body = t.render({'message': 'RSS巡回用URLの編集',
                     'form': editform,
                     'values': values, 'errors': errors})
    res.set_body(body)
    return res
Beispiel #34
0
 def get_form(self, value=''):
     body = ("""<select name="${name}" ${attrs}>\n"""
             """$for v in options:\n"""
             """<option value="${v[0]}"\n"""
             """$if value==v[0]:\n"""
             """ selected \n"""
             """$endif\n"""
             """>${v[1]}</option>\n"""
             """$endfor\n"""
             """</select>\n""")
     t = SimpleTemplate(body)
     return t.render({'name': self.name, 'value': value, 'options': self.options, 'attrs': self.attrs})
Beispiel #35
0
def login_form(_request, values={}, errors={}):
    res = Response()
    t = SimpleTemplate(file_path=relativepath("form.html"))
    values["password"] = ""
    body = t.render({
        "form": loginform,
        "values": values,
        "errors": errors,
        "message": u"ログイン"
    })
    res.set_body(body)
    return res
Beispiel #36
0
def get_edit_form(item_id, values={}, errors={}):
    res=Response()
    t=SimpleTemplate(file_path=relativepath('form.html'))
    if not values:
        for item in Rssurl.select(id=item_id):
            pass
        values={'item_id':item_id, 'title':item.title, 'url':item.url}
    body=t.render({'message': u'RSS巡回用URLの編集',
                   'form':editform,
                   'values':values, 'errors':errors})
    res.set_body(body)
    return res
Beispiel #37
0
def add(_request, title='', url=''):
    res=Response()
    values, errors=addform.validate({'title':title, 'url':url})
    if [ x for x in Rssurl.select(url=url)]:
        errors['url']=u'このURLは登録済みです'
    if errors:
        return get_add_form(values, errors)
    Rssurl(title=title, url=url)
    t=SimpleTemplate(file_path=relativepath('posted.html'))
    body=t.render({'message': u'巡回用URLを追加しました'})
    res.set_body(body)
    return res
Beispiel #38
0
def add(_request, title='', url=''):
    res = Response()
    values, errors = addform.validate({'title': title, 'url': url})
    if [ x for x in Rssurl.select(url=url)]:
        errors['url'] = "このURLは登録済みです"
    if errors:
        return get_add_form(values, errors)
    Rssurl(title=title, url=url)
    t = SimpleTemplate(file_path=relativepath('posted.html'))
    body = t.render({'message': '巡回用URLを追加しました'})
    res.set_body(body)
    return res
Beispiel #39
0
def add(_request, title="", url=""):
    res = Response()
    values, errors = addform.validate({"title": title, "url": url})
    if [x for x in Rssurl.select(url=url)]:
        errors["url"] = u"このURLは登録済みです"
    if errors:
        return get_add_form(values, errors)
    Rssurl(title=title, url=url)
    t = SimpleTemplate(file_path=relativepath("posted.html"))
    body = t.render({"message": u"巡回用URLを追加しました"})
    res.set_body(body)
    return res
Beispiel #40
0
 def get_form(self, value=''):
     body = ("""<select name="${name}" ${attrs}>/\n"""
             """$for v in options:\n"""
             """<option value="${v[0]}"\n"""
             """$if value==v[0]:\n"""
             """ selected \n"""
             """$endif\n"""
             """>${v[1]}</option>\n"""
             """$endfor\n"""
             """</select>\n""")
     t = SimpleTemplate(body)
     return t.render({'name': self.name, 'value': value, 'options':self.options, 'attrs': self.attrs})
Beispiel #41
0
def login_form(_request, values={}, errors={}):
    res = Response()
    t = SimpleTemplate(file_path=relativepath('form.html'))
    values['password'] = ''
    body = t.render({
        'form': loginform,
        'values': values,
        'errors': errors,
        'message': u'ログイン'
    })
    res.set_body(body)
    return res
Beispiel #42
0
 def get_form(self, value=""):
     body = (
         """$for v in options:\n"""
         """${v[1]} : """
         """<input type="radio" name="${name}" value="${v[0]}"\n"""
         """$if value==v[0]:\n"""
         """ checked \n"""
         """$endif\n"""
         """>\n"""
         """$endfor\n"""
     )
     t = SimpleTemplate(body)
     return t.render({"name": self.name, "value": value, "options": self.options, "attrs": self.attrs})
Beispiel #43
0
def edit(_request, item_id, title='', url=''):
    res=Response()
    values, errors=editform.validate({'item_id':item_id,
                            'title':title, 'url':url})
    if errors:
        return get_edit_form(item_id, values, errors)
    for item in Rssurl.select(id=item_id):
        item.title=title
        item.url=url
    t=SimpleTemplate(file_path=relativepath('posted.html'))
    body=t.render({'message': u'巡回用URLを編集しました'})
    res.set_body(body)
    return res
Beispiel #44
0
def index(_request):
    rsslist = []
    try:
        for rss in Rssurl.select(order_by='id'):
            rsslist.extend(parse_rss(rss.url))
    except:
        pass
    res = Response()
    p = path.join(path.dirname(__file__), 'rsslist.html')
    t = SimpleTemplate(file_path=p)
    body = t.render({'rsslist': rsslist})
    res.set_body(body)
    return res
Beispiel #45
0
 def get_form(self, value=""):
     body = (
         """<select name="${name}" ${attrs}>\n"""
         """$for v in options:\n"""
         """<option value="${v[0]}"\n"""
         """$if value==v[0]:\n"""
         """ selected \n"""
         """$endif\n"""
         """>${v[1]}</option>\n"""
         """$endfor\n"""
         """</select>\n"""
     )
     t = SimpleTemplate(body)
     return t.render({"name": self.name, "value": value, "options": self.options, "attrs": self.attrs})
Beispiel #46
0
def index(_request):
    rsslist=[]
    try:
        for rss in Rssurl.select(order_by='id'):
            rsslist.extend(parse_rss(rss.url))
    except:
        pass
    
    res=Response()
    p=path.join(path.dirname(__file__), 'rsslist.html')
    t=SimpleTemplate(file_path=p)
    body=t.render({'rsslist':rsslist[:20]})
    res.set_body(body)
    return res
Beispiel #47
0
def edit_form(_request, item_id, values={}, errors={}):
    res = Response()
    t = SimpleTemplate(file_path=relativepath("form.html"))
    if not values:
        for item in Rssurl.select(id=item_id):
            pass
        values = {"item_id": item_id, "title": item.title, "url": item.url}
    body = t.render({
        "message": u"RSS巡回用URLの編集",
        "form": editform,
        "values": values,
        "errors": errors
    })
    res.set_body(body)
    return res
Beispiel #48
0
def edit(_request, item_id, title="", url=""):
    res = Response()
    values, errors = editform.validate({
        "item_id": item_id,
        "title": title,
        "url": url
    })
    if errors:
        return edit_form(item_id, values, errors)
    for item in Rssurl.select(id=item_id):
        item.title = title
        item.url = url
        item.update()
    t = SimpleTemplate(file_path=relativepath("posted.html"))
    body = t.render({"message": u"巡回用URLを編集しました"})
    res.set_body(body)
    return res
Beispiel #49
0
        pizza.sauce_color = 'label-success'
    elif pizza.sauce == u'南蛮ソース':
        pizza.sauce_color = 'label-info'
    else:
        pizza.sauce_color = 'label-danger'
    pizza.cart_count_msize = 0
#     if pizza.id in self.msize_carts: pizza.cart_count_msize = self.msize_carts[pizza.id]
    pizza.cart_count_lsize = 0
#     if pizza.id in self.lsize_carts: pizza.cart_count_lsize = self.lsize_carts[pizza.id]

value_dic = {
    'nav_index': True,
    'nav_cart': False,
    'nav_history': False,
    'pizzas': pizzas,
    'login_error': False,
    'username': '',
    'login': False,
    'anonymous': True,
    'cart_count': 0,
}

html = u''
filenames = ['head.html','head.html', 'nav.html', 'index.html', 'foot.html']
for fname in filenames:
    p = path.join(path.dirname(__file__), '../templates', fname)
    t = SimpleTemplate(file_path=p)
    html += t.render(value_dic)

print(html)
Beispiel #50
0
template_path = '/var/www/html/cpy/result.html'

if str == "none":
    body = u"テキストフィールドに検索する文字を入力してください"
    res = Response()
    res.set_body(get_htmltemplate() % body)
    print res

elif radio == "custini":
    cur.execute("""SELECT * FROM main WHERE custini = '%s' FOR UPDATE""" % str)
    con.commit()
    temp = cur.fetchall()
    if temp:
        item = temp[0]
        t = SimpleTemplate(file_path = template_path)
        body = t.render(item)
        res = Response()
        res.set_body(body)
        print res
    else:
        notapplicable()

elif radio == "customer":
    cur.execute("""SELECT * FROM main WHERE customer LIKE '%%%s%%' FOR UPDATE""" %
            (MySQLdb.escape_string(str)))
    con.commit()
    temp = cur.fetchall()
    if temp:
        radio_check = "checked"
        for item in temp:
Beispiel #51
0
p = path.join(path.dirname(__file__), "editform.html")

if not f.getvalue("posted"):
    id = f.getvalue("id")
    rss = Rssurl(id=int(id))
    value_dic.update({"title": rss.title, "url": rss.url, "item_id": id})
else:
    id = f.getvalue("id")
    title = unicode(f.getvalue("title", ""), "utf-8", "ignore")
    url = unicode(f.getvalue("url", ""), "utf-8", "ignore")
    value_dic.update({"title": title, "url": url, "item_id": id})
    if not title:
        errors["title"] = u"タイトルを入力してください"
    if not url.startswith("http://"):
        errors["url"] = u"正しいURLを入力してください"

    if not errors:
        rss = Rssurl(id=int(f.getvalue("id")))
        rss.title = unicode(f.getvalue("title", ""), "utf-8", "ignore")
        rss.url = f.getvalue("url", "")
        rss.update()
        p = path.join(path.dirname(__file__), "posted.html")
        value_dic["message"] = u"RSS取得を編集しました"

t = SimpleTemplate(file_path=p)
res = Response()
body = t.render(value_dic)
res.set_body(body)
print res
Beispiel #52
0
def index(_request, name='', body='', submit=''):
    res = Response()
    t = SimpleTemplate(htmlbody)
    body = t.render({'name': name, 'body': body})
    res.set_body(body)
    return res
Beispiel #53
0
from widgettest_classes import Profile, form
import cgitb

cgitb.enable()

req = Request()
values = {}
[
    values.update({k: unicode(req.form.getvalue(k, ""), "utf-8", "ignore")})
    for k in req.form.keys()
]
cvalues, errors = form.validate(values)
if len(req.form.keys()) == 0:
    errors = {"foo": "bar"}

res = Response()
p = path.join(path.dirname(__file__), "questionform.html")
t = SimpleTemplate(file_path=p)

post_values = {
    "form": form,
    "values": values,
    "errors": errors,
    "dateposted": False
}
if not errors:
    post_values.update(dateposted=True)
body = t.render(post_values)
res.set_body(body)
print res
Beispiel #54
0
 def get_form(self, value=''):
     body="""<textarea name="${name}" ${attrs}>${value}</textarea>"""
     t=SimpleTemplate(body)
     return t.render({'name':self.name, 'value':value,
                      'attrs':self.attrs})
Beispiel #55
0
 def get_form(self, value=''):
     body=("""<input type="reset" value="${label}" """
           """ ${attrs} />""")
     t=SimpleTemplate(body)
     return t.render({'label':self.label, 'attrs':self.attrs})
Beispiel #56
0
p = path.join(path.dirname(__file__), 'editform.html')

if not f.getvalue('posted'):
    id = f.getvalue('id')
    rss = Rssurl(id=int(id))
    value_dic.update({'title': rss.title, 'url': rss.url, 'item_id': id})
else:
    id = f.getvalue('id')
    title = unicode(f.getvalue('title', ''), 'utf-8', 'ignore')
    url = unicode(f.getvalue('url', ''), 'utf-8', 'ignore')
    value_dic.update({'title': title, 'url': url, 'item_id': id})
    if not title:
        errors['title'] = u'タイトルを入力してください'
    if not url.startswith('http://'):
        errors['url'] = u'正しいURLを入力してください'
    if not errors:
        rss = Rssurl(id=int(f.getvalue('id')))
        rss.title = f.getvalue('title')
        rss.url = f.getvalue('url')
        rss.update()
        p = path.join(path.dirname(__file__), 'posted.html')
        value_dic['message'] = u'RSS取得URLを編集しました'

t = SimpleTemplate(file_path = p)
res = Response()
body = t.render(value_dic)
res.set_body(body)

print res
Beispiel #57
0
#!/usr/bin/python
# coding: utf-8

from simpletemplate import SimpleTemplate
from rssurl import Rssurl
from os import path
from httphandler import Request, Response
from rssparser import parse_rss
import cgitb
cgitb.enable()

rsslist = []
try:
    # TODO: 実装
    for rss in Rssurl.select(order_by='id'):
        rsslist.extend(parse_rss(rss.url))
except:
    pass

res = Response()
p = path.join(path.dirname(__file__), 'rsslist.html')
t = SimpleTemplate(file_path=p)
body = t.render({'rsslist': rsslist[:20]})
res.set_body(body)

print res
Beispiel #58
0
#!/usr/bin/env python
# coding: utf-8

from simpletemplate import SimpleTemplate
from rssurl import Rssurl
from os import path
from httphandler import Request, Response
from rssparser import parse_rss
import cgitb; cgitb.enable()

rsslist=[]
try:
    for rss in Rssurl.select(order_by='id'):
        rsslist.extend(parse_rss(rss.url))
except:
    pass

res=Response()
p=path.join(path.dirname(__file__), 'rsslist.html')
t=SimpleTemplate(file_path=p)
body=t.render({'rsslist':rsslist[:20]})
res.set_body(body)
print res

Beispiel #59
0
#!/usr/bin/env python
# coding: utf-8

from simpletemplate import SimpleTemplate
from os import path
from httphandler import Request, Response
from widgettest_classes import Profile, form

import cgitb; cgitb.enable()
req=Request()
values={}
[values.update({k:req.form.getvalue(k, '')})
                    for k in req.form.keys()]
cvalues, errors=form.validate(values)
if len(req.form.keys())==0:
    errors={'foo':'bar'}

res=Response()
p=path.join(path.dirname(__file__), 'questionform.html')
t=SimpleTemplate(file_path=p)

post_values={'form':form, 'values':values, 'errors':errors,
             'dataposted':False}
if not errors:
    post_values.update(dataposted=True)
body=t.render(post_values)

res.set_body(body)
print res