def handle(path, form, start_response): err = Msg(web=True) subdir = form.getvalue("subdirectory", '').lower() log.debug("form keys and vals: %s" % (dict([(k,form.getvalue(k,'')) for k in form.keys()]))) if 'submit' in form.keys(): if form.getvalue("turing",'').lower() != "yes": err.add("I can't believe you failed the Turing test. Maybe you're a sociopath?") log.debug("Turing test failed for %s" % subdir) elif validate_input(subdir, err): if make_planet(subdir, err): response_headers = [('Location', "http://%s/%s/admin.py" % (opt['domain'], subdir))] start_response("302 Found", response_headers) return [] response_headers = [('Content-type', 'text/html')] start_response("200 OK", response_headers) doc = template_vars(err, subdir, dict([(k,form.getvalue(k,'')) for k in form.keys()])) log.debug("doc: %s" % doc) return([templates.Index(doc).render().encode('utf-8', 'ignore')])
def handle(path, form, start_response): # import cgitb # cgitb.enable() err = Msg(web=True) planet_subdir = path.split(os.sep)[-2] from planet import Planet planet = Planet(direc=planet_subdir) ## Handle form input if form.has_key('PlanetName'): orig_pass = planet.password planet = update_config(planet, form, err) if form.getvalue('Timestamp') != str(planet.last_config_change): err.add("Admin page has expired! Perhaps somebody else is " + "editing this planet at the same time as you? Please " + "reload this page and try again.") #if debug: err.add("%s != %s" % (form.getvalue('Timestamp'), planet.last_config_change)) elif form.getvalue('Pass','') == '': err.add("Please enter your password at the bottom of the page.") elif form.getvalue('Pass') != orig_pass: err.add("Invalid password") else: planet.save(update_config_timestamp=True) ## Template from templates import Admin start_response("200 OK", [('Content-Type', 'text/html')]) a = Admin(template_vars(err, planet, form)).render() return [a]