123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- from flask import Flask, redirect, render_template, request, url_for
-
- from yird.services.posts import PostsService
-
- from yird.settings import Settings
-
- app = Flask(__name__)
- yird_settings = Settings()
-
-
- @app.route('/admin')
- def index():
- posts = PostsService.get_posts()
- return render_template('index.html.j2', posts=posts)
-
-
- @app.route('/admin/posts/new')
- def new_post():
- form = PostsService.get_post_form()
- return render_template('posts/form.html.j2', post=False, form=form)
-
-
- @app.route('/admin/posts', methods=["POST"])
- def create_post():
- PostsService.create_post(request.form)
- return redirect(url_for('index'))
-
-
- @app.route('/admin/posts/<post_id>')
- def edit_post(post_id):
- post = PostsService.get_post(post_id)
- form = PostsService.get_post_form(post)
- return render_template('posts/form.html.j2', post=post, form=form)
-
-
- @app.route('/admin/posts/<post_id>', methods=["POST"])
- def update_post(post_id):
- PostsService.update_post(post_id, request.form)
- return redirect(url_for('index'))
-
-
- @app.route('/admin/generate')
- def generate():
- PostsService.generate_posts()
- return redirect(url_for('index'))
-
- if __name__ == "__main__":
- app.run(debug=True)
|