A Python content management system designed for kirsle.net featuring a blog, comments and photo albums. https://rophako.kirsle.net/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

77 lines
2.0KB

  1. __version__ = '0.01'
  2. from flask import Flask, g, request, session, render_template, send_file
  3. import jinja2
  4. import os.path
  5. import config
  6. app = Flask(__name__)
  7. app.DEBUG = config.DEBUG
  8. app.SECRET_KEY = config.SECRET_KEY
  9. # Load all the blueprints!
  10. from rophako.modules.account import mod as AccountModule
  11. app.register_blueprint(AccountModule)
  12. # Custom Jinja handler to support custom- and default-template folders for
  13. # rendering templates.
  14. app.jinja_loader = jinja2.ChoiceLoader([
  15. jinja2.FileSystemLoader("site/www"), # Site specific.
  16. jinja2.FileSystemLoader("rophako/www"), # Default
  17. ])
  18. @app.before_request
  19. def before_request():
  20. """Called before all requests. Initialize global template variables."""
  21. # Default template vars.
  22. g.info = {
  23. "app": {
  24. "name": "Rophako",
  25. "version": __version__,
  26. "author": "Noah Petherbridge",
  27. },
  28. "uri": request.path.split("/")[1:],
  29. }
  30. @app.context_processor
  31. def after_request():
  32. """Called just before render_template. Inject g.info into the template vars."""
  33. return g.info
  34. @app.route("/<path:path>")
  35. def catchall(path):
  36. """The catch-all path handler. If it exists in the www folders, it's sent,
  37. otherwise we give the 404 error page."""
  38. # Search for this file.
  39. for root in ["site/www", "rophako/www"]:
  40. abspath = os.path.abspath("{}/{}".format(root, path))
  41. print abspath
  42. print abspath + ".html"
  43. if os.path.isfile(abspath):
  44. return send_file(abspath)
  45. elif not "." in path and os.path.isfile(abspath + ".html"):
  46. return render_template(path + ".html")
  47. return not_found("404")
  48. @app.route("/")
  49. def index():
  50. print "INDEX PAGE"
  51. return catchall("index")
  52. @app.errorhandler(404)
  53. def not_found(error):
  54. print "NOT FOUND"
  55. return render_template('errors/404.html', **g.info), 404
  56. # Domain specific endpoints.
  57. if config.SITE_NAME == "kirsle.net":
  58. import rophako.modules.kirsle_legacy