def new(self): """docstring for new""" if not get_user(): body = Template.Kind_Body % (Template.Kind_Top,"Not Login!","") html = Template.HTML % ("Not login!",body) return html if get_field('action') != 'new': form = """ <form action="new" method="POST" accept-charset="utf-8"> <input type="hidden" name="action" value="new"> <div><input type="text" name="kind_name" value=""><span>Kind Name</span></div> <div><input type="text" name="kind_shortname" value=""><span>Kind Short Name</span></div> <p><input type="submit" value="新增"></p> </form> """ body = Template.Kind_Body %(Template.Kind_Top,form,"") html = Template.HTML % ("New Kind",body) return html else: kind_name = get_field('kind_name') kind_shortname = get_field('kind_shortname') kind_id = int(get_time_str()) kind_count = 0 sql = """insert into kind values (%s,%s,%s,%s)""" execute_sql_in_4bbs(sql,[kind_id,kind_name,kind_count,kind_shortname]) return redirect("/kind")
def edit(self): if not get_user(): body = Template.Kind_Body % (Template.Kind_Top,"Not Login!","") html = Template.HTML % ("Not login!",body) return html if get_field('action') != 'edit': kind_id = get_field('kind_id') if not kind_id: Body = Template.Kind_Body % (Template.Kind_Top,"Error Parameters!","") return Template.HTML % ("Error!",Body) sql = """select * from kind where kind_id=%s""" % kind_id count,res = execute_sql_in_4bbs(sql,"SHOW") kind_name = res[0][1] kind_shortname= res[0][3] form = """ <form action="edit" method="POST" accept-charset="utf-8"> <input type="hidden" name="action" value="edit"> <div><input type="text" name="kind_name" value="%s"><span>Kind Name</span></div> <div><input type="text" name="kind_shortname" value="%s"><span>Kind Short Name</span></div> <input type="hidden" name="kind_id" value="%s"> <p><input type="submit" value="编辑"></p> </form> """ % (kind_name,kind_shortname,kind_id) body = Template.Kind_Body % (Template.Kind_Top,form,"") html = Template.HTML % ("Edit Kind",body) return html else: kind_id = int(get_field('kind_id')) kind_name = get_field('kind_name') kind_shortname = get_field('kind_shortname') sql = """UPDATE kind SET kind_name=%s,kind_shortname=%s where kind_id=%s""" execute_sql_in_4bbs(sql,[kind_name,kind_shortname,kind_id]) return redirect("/kind")
def login(self): content = htmltext('') if get_field("name"): session = get_session() session.set_user(get_field("name")) # This is the important part. content += htmltext( '<p>Welcome, %s! Thank you for logging in.</p>') % get_user() content += href("..", "go back") else: content += htmltext('<p>Please enter your name here:</p>\n' '<form method="POST" action="login">' '<input name="name" />' '<input type="submit" />' '</form>') return format_page("Quixote Session Demo: Login", content)
def login(self): content = htmltext('') if get_field("name"): session = get_session() session.set_user(get_field("name")) # This is the important part. content += htmltext( '<p>Welcome, %s! Thank you for logging in.</p>') % get_user() content += href("..", "go back") else: content += htmltext( '<p>Please enter your name here:</p>\n' '<form method="POST" action="login">' '<input name="name" />' '<input type="submit" />' '</form>') return format_page("Quixote Session Demo: Login", content)
def delete(self): if not get_user(): body = Template.Kind_Body % (Template.Kind_Top,"Not Login!","") html = Template.HTML % ("Not login!",body) return html kind_id = get_field('kind_id') sql = """DELETE FROM kind where kind_id=%s""" execute_sql_in_4bbs(sql,[kind_id]) return redirect("/kind")
def stopper(): stop = get_field("stop") if stop: player.kill() return simplepage(body = "%s stopped." % song) else: f = Form() f.add_submit("stop", "Stop") return simplepage(body= ("Playing %s" % song) + f.render())
def login(self): if get_field('action') != 'login': form = """ <form action="login" method="POST" accept-charset="utf-8"> <input type="hidden" name="action" value="login"> <div><input type="text" name="name" value=""><span>Name</span></div> <div><input type="text" name="password" value=""><span>Password</span></div> <p><input type="submit" value="登陆"></p> </form> """ body = Template.Kind_Body % (Template.Kind_Top,form,"") html = Template.HTML % ("Login",body) return html else: name = get_field('name') password = get_field('password') if name == 'Peter' and password == '112358132134art': this_session = get_session() this_session.set_user('Peter') return redirect('/kind')
def selector(songs): global player, song chosen = get_field("select") if chosen: song = chosen player = play(song) redirect("stopper") # works with Mozilla, but not with lynx/elinks else: f = Form() f.add_single_select("select", options=songs) f.add_submit("play", "Play!") return f.render()