scripts and tools to administer the lingy.in public unix / tilde
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

68 rindas
2.3KB

  1. from flask import Flask, redirect, url_for, render_template, request
  2. app=Flask(__name__)
  3. @app.route("/")
  4. def home():
  5. app.route('/')
  6. u_list = [];
  7. with open("user_list.txt") as u_file:
  8. for line in u_file:
  9. u_list.append(line);
  10. return render_template("index.html", u_list=u_list)
  11. def home2(name):
  12. # app.route('/home2/<name>')
  13. # return redirect(url_for('home'))
  14. return render_template("home.html")
  15. def success(name):
  16. return "welcome %s" % name
  17. # this is a weird way to do this
  18. # right?
  19. def widg_fun(widg):
  20. if(widg.w_type == "input"):
  21. return "input id=id_%s name=%s type=text></input"%(widg.w_name, widg.w_name)
  22. elif(widg.w_type == "textarea"):
  23. return "textarea cols=40 id=id_%s name=%s rows=10 required=\"\""%(widg.w_name, widg.w_name)
  24. elif(widg.w_type == "check"):
  25. return "input id=id_%s name=%s type=checkbox required=\"\""%(widg.w_name, widg.w_name)
  26. return widg.w_type;
  27. def req():
  28. class Widg:
  29. def __init__(self, w_name, w_type, w_opt):
  30. self.w_name = w_name
  31. self.w_type = w_type
  32. self.w_opt = w_opt
  33. rt = {
  34. "username": Widg("username", "input", None),
  35. "displayname": Widg("displayname", "input", None),
  36. "prefer display name?": Widg("default_disp", "check", None),
  37. "email for account lockout / registration confirmation (optional)": Widg("email", "input", None),
  38. "SSH public key": Widg("pub_key", "textarea", None),
  39. "shell of choice": Widg("shell", "choice", [("bash", "/bin/bash"), ("ksh", "/bin/ksh")]),
  40. "have you read the rules?": Widg("rule_read", "check", None)
  41. };
  42. # uhhh is this how you're supposed to do this?
  43. return render_template("req.html", req_tab = rt, widg_fun = widg_fun)
  44. def login():
  45. if request.method == "POST":
  46. user = request.form["nm"]
  47. return redirect(url_for('success', name = user))
  48. else:
  49. return redirect(url_for('home'))
  50. if __name__=="__main__":
  51. app.add_url_rule('/home2/<name>', 'home2', home2)
  52. app.add_url_rule('/success/<name>', 'success', success)
  53. app.add_url_rule('/login', 'login', login, methods = ['POST', 'GET'])
  54. app.add_url_rule('/req', 'req', req, methods = ['POST', 'GET'])
  55. app.run(host="104.248.118.130",debug=True)