Beispiel #1
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 #2
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})
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 #4
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 #6
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 #7
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
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
Beispiel #9
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 #10
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 #11
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 #13
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 #14
0
    def test_process2(self):
        t = SimpleTemplate("""
$if True:
    test
$endif
""")
        body = t.render({})
        self.assertEqual("""
    test

""", body)
Beispiel #15
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 #16
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 #17
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 #18
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 #19
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 #20
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 #21
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 #22
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 #23
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 #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
#!/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 #26
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 #27
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 #28
0
#!/home/minori/.pyenv/shims/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 #29
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 #30
0
#!/home/minori/.pyenv/shims/python
# coding: utf-8

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

value_dic = {"rsslist":[x for x in Rssurl.select(order_by = "id")]}

res = Response()
p = path.join(path.dirname(__file__), "urllist.html")
t = SimpleTemplate(file_path = p)
body = t.render(value_dic)
res.set_body(body)
print res

Beispiel #31
0
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
Beispiel #32
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:
            content += radio_parts % (radio_check, item['customer'], item['customer'])
Beispiel #33
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 #34
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 #35
0
 def get_form(self, value=""):
     body = ("""<input type="submit" value="${label}" """
             """ ${attrs} />""")
     t = SimpleTemplate(body)
     return t.render({"label": self.label, "attrs": self.attrs})
Beispiel #36
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 #37
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 #38
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

try:
    cur.execute('CREATE TABLE language_pole (name text, value int);')
except:
    pass

content = ""
req = Request()
if 'language' in req.form:
    lang = req.form['language'].value
    increment(cur, lang)

lang_dict = {}
cur.execute("SELECT name, value FROM language_pole;")
for res in cur.fetchall():
    lang_dict[res[0]] = res[1]
cur.close()

lang_list = []
for lang in ['Perl', 'PHP', 'Python', 'Ruby']:
    num = lang_dict.get(lang, 0)
    lang_list.append([lang, str(num)])

param_dict = {'languages': tuple(lang_list)}

renderer = SimpleTemplate(
    file_path=get_absolute_path('../template/favorite_language.html'))
res = Response()
res.set_body(renderer.render(param_dict=param_dict))
print(res.headers)
print('\n')
print(res.body)
Beispiel #40
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})