|
1 | 1 | import datetime
|
| 2 | +import ntpath |
2 | 3 | import shutil
|
3 | 4 |
|
4 | 5 | import markdown
|
5 |
| -import ntpath |
6 | 6 | from flask import Flask, redirect, render_template, request, url_for
|
| 7 | + |
7 | 8 | from manager_utils import *
|
8 | 9 | from settings import BLOG_CATEGORIES
|
9 | 10 |
|
10 |
| -app = Flask(__name__, template_folder='manager_app/templates', static_folder='manager_app/static') |
| 11 | +app = Flask( |
| 12 | + __name__, |
| 13 | + template_folder="manager_app/templates", |
| 14 | + static_folder="manager_app/static", |
| 15 | +) |
11 | 16 | app.config.update(
|
12 |
| - DEBUG=True, |
13 |
| - SECRET_KEY=b'sC&wJQ35C3jR', |
14 |
| - SQLALCHEMY_TRACK_MODIFICATIONS = False |
| 17 | + DEBUG=True, SECRET_KEY=b"sC&wJQ35C3jR", SQLALCHEMY_TRACK_MODIFICATIONS=False |
15 | 18 | )
|
16 | 19 |
|
| 20 | + |
17 | 21 | @app.route("/")
|
18 | 22 | def index():
|
19 | 23 | posts = get_posts()
|
20 |
| - resources = info['resources'] |
| 24 | + resources = info["resources"] |
21 | 25 | current_day = datetime.date.today()
|
22 | 26 | today = datetime.date.strftime(current_day, "%B %d, %Y")
|
23 | 27 |
|
24 |
| - return render_template("index.html", today=today, |
25 |
| - b_categories=BLOG_CATEGORIES, |
26 |
| - posts=posts, |
27 |
| - resources=resources) |
| 28 | + return render_template( |
| 29 | + "index.html", |
| 30 | + today=today, |
| 31 | + b_categories=BLOG_CATEGORIES, |
| 32 | + posts=posts, |
| 33 | + resources=resources, |
| 34 | + ) |
| 35 | + |
28 | 36 |
|
29 |
| -@app.route("/save_post", methods=['POST']) |
| 37 | +@app.route("/save_post", methods=["POST"]) |
30 | 38 | def save_post():
|
31 | 39 | # Validate empty fields?
|
32 |
| - post_type = request.form['post-type'] |
33 |
| - if request.form['post-type'] == 'blog': |
| 40 | + post_type = request.form["post-type"] |
| 41 | + if request.form["post-type"] == "blog": |
34 | 42 | data = {
|
35 |
| - 'title' : request.form['b_title'], |
36 |
| - 'summary' : request.form['b_summ'], |
37 |
| - 'authors' : get_comma_separated(request.form['b_authors']), |
38 |
| - 'date' : request.form['b_date'], |
39 |
| - 'tags' : get_comma_separated(request.form['b_tags']), |
40 |
| - 'slug' : request.form['b_slug'], |
41 |
| - 'post_content' : request.form['post_content'], |
42 |
| - 'category' : request.form['b_category'] |
| 43 | + "title": request.form["b_title"], |
| 44 | + "summary": request.form["b_summ"], |
| 45 | + "authors": get_comma_separated(request.form["b_authors"]), |
| 46 | + "date": request.form["b_date"], |
| 47 | + "tags": get_comma_separated(request.form["b_tags"]), |
| 48 | + "slug": request.form["b_slug"], |
| 49 | + "post_content": request.form["post_content"], |
| 50 | + "category": request.form["b_category"], |
43 | 51 | }
|
44 | 52 |
|
45 |
| - ensure_authors(data['authors']) |
| 53 | + ensure_authors(data["authors"]) |
46 | 54 | save_md_file(post_type, data)
|
47 | 55 |
|
48 | 56 | else:
|
49 | 57 | data = {
|
50 |
| - 'slug' : request.form['f_slug'], |
51 |
| - 'tags' : get_comma_separated(request.form['f_tags']), |
52 |
| - 'title' : request.form['f_title'], |
53 |
| - 'post_content' : request.form['post_content'] |
| 58 | + "slug": request.form["f_slug"], |
| 59 | + "tags": get_comma_separated(request.form["f_tags"]), |
| 60 | + "title": request.form["f_title"], |
| 61 | + "post_content": request.form["post_content"], |
54 | 62 | }
|
55 | 63 | save_md_file(post_type, data)
|
56 |
| - |
| 64 | + |
57 | 65 | return 'Post saved! Remember re-build the site to see the changes. <a href="/">Return</a>'
|
58 |
| - |
59 |
| -@app.route("/action/<string:ptype>/<string:option>/<string:post>", methods=['GET']) |
| 66 | + |
| 67 | + |
| 68 | +@app.route("/action/<string:ptype>/<string:option>/<string:post>", methods=["GET"]) |
60 | 69 | def postman(ptype, option, post):
|
61 |
| - if option == 'edit': |
| 70 | + if option == "edit": |
62 | 71 | posts = get_posts()
|
63 | 72 |
|
64 |
| - if ptype == 'blog': |
65 |
| - filename, category = post.split('@') |
66 |
| - blog_post_path = os.path.join('data', 'blog', category, filename) |
67 |
| - |
| 73 | + if ptype == "blog": |
| 74 | + filename, category = post.split("@") |
| 75 | + blog_post_path = os.path.join("data", "blog", category, filename) |
| 76 | + |
68 | 77 | body, metadata = parse_file(blog_post_path)
|
69 | 78 |
|
70 | 79 | postdata = {
|
71 |
| - "title" : metadata["title"][0], |
72 |
| - "summary" : metadata["summary"][0], |
73 |
| - "authors" : ','.join(metadata["authors"]), |
74 |
| - "date" : metadata["date"][0], |
75 |
| - "tags" : ','.join(metadata["tags"]), |
76 |
| - "slug" : metadata["slug"][0], |
77 |
| - "category" : category, |
78 |
| - "content": body |
| 80 | + "title": metadata["title"][0], |
| 81 | + "summary": metadata["summary"][0], |
| 82 | + "authors": ",".join(metadata["authors"]), |
| 83 | + "date": metadata["date"][0], |
| 84 | + "tags": ",".join(metadata["tags"]), |
| 85 | + "slug": metadata["slug"][0], |
| 86 | + "category": category, |
| 87 | + "content": body, |
79 | 88 | }
|
80 |
| - |
81 |
| - return render_template("edit_page.html", postdata=postdata, posts=posts, edit_type='blog') |
| 89 | + |
| 90 | + return render_template( |
| 91 | + "edit_page.html", postdata=postdata, posts=posts, edit_type="blog" |
| 92 | + ) |
82 | 93 | else:
|
83 |
| - faq_post_path = os.path.join('data', 'faq', post) |
| 94 | + faq_post_path = os.path.join("data", "faq", post) |
84 | 95 | body, metadata = parse_file(faq_post_path)
|
85 | 96 |
|
86 | 97 | postdata = {
|
87 |
| - "title" : metadata["title"][0], |
88 |
| - "tags" : ','.join(metadata["tags"]), |
89 |
| - "slug" : metadata["slug"][0], |
90 |
| - "content": body |
| 98 | + "title": metadata["title"][0], |
| 99 | + "tags": ",".join(metadata["tags"]), |
| 100 | + "slug": metadata["slug"][0], |
| 101 | + "content": body, |
91 | 102 | }
|
92 |
| - |
93 |
| - return render_template("edit_page.html", postdata=postdata, posts=posts, edit_type='faq') |
| 103 | + |
| 104 | + return render_template( |
| 105 | + "edit_page.html", postdata=postdata, posts=posts, edit_type="faq" |
| 106 | + ) |
94 | 107 |
|
95 | 108 | else:
|
96 |
| - if ptype == 'blog': |
97 |
| - filename, category = post.split('@') |
98 |
| - delete_post(os.path.join('data', 'blog', category, filename), docs_dir='b') |
| 109 | + if ptype == "blog": |
| 110 | + filename, category = post.split("@") |
| 111 | + delete_post(os.path.join("data", "blog", category, filename), docs_dir="b") |
99 | 112 | else:
|
100 |
| - delete_post(os.path.join('data', 'faq', post), docs_dir='faq') |
| 113 | + delete_post(os.path.join("data", "faq", post), docs_dir="faq") |
101 | 114 |
|
102 | 115 | return 'Post deleted! Do not forget to rebuild the site to remove the remaining references. <a href="/">Return</a>'
|
103 | 116 |
|
| 117 | + |
104 | 118 | if __name__ == "__main__":
|
105 | 119 | app.run()
|
0 commit comments