A flat-file CMS written in Python and Flask
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.

app.py 1.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. from flask import Flask, redirect, render_template, request, url_for
  2. from flask_webpack import Webpack
  3. from yird.services.git import GitService
  4. from yird.services.posts import PostsService
  5. from yird.settings import Settings
  6. app = Flask(__name__)
  7. params = {
  8. 'DEBUG': True,
  9. 'WEBPACK_MANIFEST_PATH': '../manifest.json'
  10. }
  11. app.config.update(params)
  12. webpack = Webpack()
  13. webpack.init_app(app)
  14. yird_settings = Settings()
  15. @app.context_processor
  16. def inject_site_name():
  17. return {
  18. "site_name": yird_settings.SITE_NAME
  19. }
  20. @app.context_processor
  21. def inject_git_status():
  22. return GitService.get_status()
  23. @app.route('/admin')
  24. def index():
  25. posts = PostsService.get_posts()
  26. return render_template('index.html.j2', posts=posts)
  27. @app.route('/admin/posts/new')
  28. def new_post():
  29. form = PostsService.get_post_form()
  30. return render_template('posts/form.html.j2', post=False, form=form)
  31. @app.route('/admin/posts', methods=["POST"])
  32. def create_post():
  33. PostsService.create_post(request.form)
  34. return redirect(url_for('index'))
  35. @app.route('/admin/posts/<post_id>')
  36. def edit_post(post_id):
  37. post = PostsService.get_post(post_id)
  38. form = PostsService.get_post_form(post)
  39. return render_template('posts/form.html.j2', post=post, form=form)
  40. @app.route('/admin/posts/<post_id>', methods=["POST"])
  41. def update_post(post_id):
  42. PostsService.update_post(post_id, request.form)
  43. return redirect(url_for('index'))
  44. @app.route('/admin/generate')
  45. def generate():
  46. PostsService.generate_posts()
  47. @app.route('/admin/repo', methods=["GET"])
  48. def repo():
  49. return render_template('repo/index.html.j2')
  50. @app.route('/admin/repo', methods=["POST"])
  51. def git_init():
  52. GitService.init()
  53. return redirect(url_for('index'))
  54. if __name__ == "__main__":
  55. app.run()