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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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.route('/admin')
  15. def index():
  16. posts = PostsService.get_posts()
  17. return render_template('index.html.j2', posts=posts)
  18. @app.route('/admin/posts/new')
  19. def new_post():
  20. form = PostsService.get_post_form()
  21. return render_template('posts/form.html.j2', post=False, form=form)
  22. @app.route('/admin/posts', methods=["POST"])
  23. def create_post():
  24. PostsService.create_post(request.form)
  25. return redirect(url_for('index'))
  26. @app.route('/admin/posts/<post_id>')
  27. def edit_post(post_id):
  28. post = PostsService.get_post(post_id)
  29. form = PostsService.get_post_form(post)
  30. return render_template('posts/form.html.j2', post=post, form=form)
  31. @app.route('/admin/posts/<post_id>', methods=["POST"])
  32. def update_post(post_id):
  33. PostsService.update_post(post_id, request.form)
  34. return redirect(url_for('index'))
  35. @app.route('/admin/generate')
  36. def generate():
  37. PostsService.generate_posts()
  38. return redirect(url_for('index'))
  39. if __name__ == "__main__":
  40. app.run()