From 33c4f6af28e9eab476cba6e30c90c656ae3401b5 Mon Sep 17 00:00:00 2001 From: Kim Diallo Date: Sat, 3 Jan 2026 02:46:05 +0100 Subject: [PATCH] src/dlw/admin.py aktualisiert --- src/dlw/admin.py | 68 +++++++++--------------------------------------- 1 file changed, 12 insertions(+), 56 deletions(-) diff --git a/src/dlw/admin.py b/src/dlw/admin.py index 25c5b5d..0ac6a8e 100644 --- a/src/dlw/admin.py +++ b/src/dlw/admin.py @@ -9,77 +9,33 @@ app.config['UPLOAD_FOLDER'] = os.path.join(os.getcwd(), 'downloads') app.config['CONTENT_FOLDER'] = os.path.join(os.getcwd(), 'content') app.secret_key = os.getenv('FLASK_SECRET_KEY', 'dev-key-123') -# Verzeichnisse sicherstellen os.makedirs(app.config['UPLOAD_FOLDER'], exist_ok=True) os.makedirs(app.config['CONTENT_FOLDER'], exist_ok=True) -def generate_markdown_content(data, slug): - return f"""--- -Title: {data['title']} -Date: {time.strftime("%Y-%m-%d %H:%M")} -Slug: {slug} -Description: {data['description']} -Abstract: {data['abstract']} -PDF_Download: /downloads/{slug}.pdf -Audio_Download: /downloads/{slug}.mp3 ---- - -{data['article_body']} -""" - @app.route('/', methods=['GET']) def index(): - form_html = """ -

Blog Admin

-
+ return """

Blog Admin


-
-
-
- PDF:
- MP3:
- -
- """ - return render_template_string(form_html) +
+ """ @app.route('/preview', methods=['POST']) def preview(): data = request.form slug = secure_filename(data['title']).lower().replace('-', '_') - - # Dateien temporär speichern (vereinfacht für dieses Beispiel) - if 'pdf_file' in request.files: - request.files['pdf_file'].save(os.path.join(app.config['UPLOAD_FOLDER'], f"{slug}.pdf")) - if 'audio_file' in request.files: - request.files['audio_file'].save(os.path.join(app.config['UPLOAD_FOLDER'], f"{slug}.mp3")) - - markdown_content = generate_markdown_content(data, slug) - return render_template_string(""" -

Vorschau: {{ title }}

-
{{ content }}
+ return render_template_string("""

Vorschau: {{ title }}

- - -
- """, title=data['title'], content=markdown_content, slug=slug) + + """, + title=data['title'], body=data['article_body'], slug=slug) @app.route('/publish', methods=['POST']) def publish(): - slug = request.form.get('slug') - content = request.form.get('content') - title = request.form.get('title') - - file_path = os.path.join(app.config['CONTENT_FOLDER'], f"{slug}.md") - with open(file_path, 'w') as f: - f.write(content) - - # Git Workflow - success, msg = git_ops.commit_and_push_article(file_path, [], title) + slug, title, content = request.form.get('slug'), request.form.get('title'), request.form.get('content') + path = os.path.join(app.config['CONTENT_FOLDER'], f"{slug}.md") + with open(path, 'w') as f: f.write(content) + success, msg = git_ops.commit_and_push_article(path, [], title) flash(msg) - return redirect(url_for('index')) - -if __name__ == '__main__': - app.run(debug=True) \ No newline at end of file + return redirect(url_for('index')) \ No newline at end of file