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.9KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. from flask import Flask, flash, 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. 'SECRET_KEY': b'flasndfjlasfnlajsnfs'
  11. }
  12. app.config.update(params)
  13. webpack = Webpack()
  14. webpack.init_app(app)
  15. yird_settings = Settings()
  16. @app.context_processor
  17. def inject_site_name():
  18. return {
  19. "site_name": yird_settings.SITE_NAME
  20. }
  21. @app.context_processor
  22. def inject_git_status():
  23. return GitService.get_status()
  24. @app.route('/admin')
  25. def index():
  26. posts = PostsService.get_posts()
  27. return render_template('index.html.j2', posts=posts)
  28. @app.route('/admin/posts/new')
  29. def new_post():
  30. form = PostsService.get_post_form()
  31. return render_template('posts/form.html.j2', post=False, form=form)
  32. @app.route('/admin/posts', methods=["POST"])
  33. def create_post():
  34. PostsService.create_post(request.form)
  35. return redirect(url_for('index'))
  36. @app.route('/admin/posts/<post_id>')
  37. def edit_post(post_id):
  38. post = PostsService.get_post(post_id)
  39. form = PostsService.get_post_form(post)
  40. return render_template('posts/form.html.j2', post=post, form=form)
  41. @app.route('/admin/posts/<post_id>', methods=["POST"])
  42. def update_post(post_id):
  43. PostsService.update_post(post_id, request.form)
  44. return redirect(url_for('index'))
  45. @app.route('/admin/generate')
  46. def generate():
  47. PostsService.generate_posts()
  48. flash('Generated static files successfully')
  49. return redirect(url_for('index'))
  50. @app.route('/admin/repo', methods=["GET"])
  51. def repo():
  52. return render_template('repo/index.html.j2')
  53. @app.route('/admin/repo', methods=["POST"])
  54. def git_init():
  55. GitService.init()
  56. return redirect(url_for('index'))
  57. if __name__ == "__main__":
  58. app.run()