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.

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