diff --git a/app.py b/app.py index ee3ad4d..ee64489 100644 --- a/app.py +++ b/app.py @@ -7,7 +7,7 @@ import schema import os from functools import wraps -from flask import Flask, g, jsonify, render_template, request, abort, redirect, session +from flask import Flask, g, jsonify, render_template, request, abort, redirect, session, flash from flask_caching import Cache from flask_session import Session from ffmpy import FFmpeg @@ -135,9 +135,52 @@ def route_admin_songs_id(id): categories = list(db.categories.find({})) song_skins = list(db.song_skins.find({})) + makers = list(db.makers.find({})) + user = db.users.find_one({'username': session['username']}) return render_template('admin_song_detail.html', - song=song, categories=categories, song_skins=song_skins) + song=song, categories=categories, song_skins=song_skins, makers=makers, admin=user) + + +@app.route('/admin/songs/', methods=['POST']) +@admin_required +def route_admin_songs_id_post(id): + song = db.songs.find_one({'id': id}) + if not song: + return abort(404) + + user = db.users.find_one({'username': session['username']}) + user_level = user['user_level'] + + output = {'title_lang': {}, 'subtitle_lang': {}, 'courses': {}} + if user_level >= 100: + output['enabled'] = True if request.form.get('enabled') else False + + output['title'] = request.form.get('title') or None + output['subtitle'] = request.form.get('subtitle') or None + for lang in ['ja', 'en', 'cn', 'tw', 'ko']: + output['title_lang'][lang] = request.form.get('title_%s' % lang) or None + output['subtitle_lang'][lang] = request.form.get('subtitle_%s' % lang) or None + + for course in ['easy', 'normal', 'hard', 'oni', 'ura']: + if request.form.get('course_%s' % course): + output['courses'][course] = {'stars': int(request.form.get('course_%s' % course)), + 'branch': True if request.form.get('branch_%s' % course) else False} + else: + output['courses'][course] = None + + output['category_id'] = int(request.form.get('category_id')) + output['type'] = request.form.get('type') + output['offset'] = float(request.form.get('offset')) or None + output['skin_id'] = int(request.form.get('skin_id')) or None + output['preview'] = float(request.form.get('preview')) or None + output['volume'] = float(request.form.get('volume')) or None + output['maker_id'] = int(request.form.get('maker_id')) or None + + db.songs.update_one({'id': id}, {'$set': output}) + flash('Changes saved.') + + return redirect('/admin/songs/%s' % id) @app.route('/api/preview') diff --git a/public/src/css/admin.css b/public/src/css/admin.css index 5b2f22d..7445630 100644 --- a/public/src/css/admin.css +++ b/public/src/css/admin.css @@ -122,4 +122,11 @@ h1 small { .checkbox input { margin-right: 3px; margin-left: 5px; -} \ No newline at end of file +} + +.message { + background: #2c862f; + padding: 15px; + margin-bottom: 10px; + color: white; +} diff --git a/templates/admin_song_detail.html b/templates/admin_song_detail.html index 322c835..a8e2d54 100644 --- a/templates/admin_song_detail.html +++ b/templates/admin_song_detail.html @@ -1,43 +1,46 @@ {% extends 'admin.html' %} {% block content %}

{{ song.title }} (ID: {{ song.id }})

+{% for message in get_flashed_messages() %} +
{{ message }}
+{% endfor %}
- +

Title

- + - + - + - + - + - +

Subtitle

- + - + - + - + - + - +
@@ -78,7 +81,37 @@

- + +
+ +
+

+ +
+ +
+

+ +
+ +
+

+ +
+ +
+

+
diff --git a/tools/migrate_db.py b/tools/migrate_db.py index 7ae71c6..9f88bfd 100644 --- a/tools/migrate_db.py +++ b/tools/migrate_db.py @@ -5,7 +5,7 @@ import sqlite3 from pymongo import MongoClient client = MongoClient() -#client.drop_database('taiko') +client.drop_database('taiko') db = client.taiko sqdb = sqlite3.connect('taiko.db') sqdb.row_factory = sqlite3.Row @@ -26,10 +26,10 @@ def migrate_songs(): 'enabled': True if row['enabled'] else False, 'category_id': row['category'], 'type': row['type'], - 'offset': row['offset'], + 'offset': row['offset'] or 0, 'skin_id': row['skin_id'], - 'preview': row['preview'], - 'volume': row['volume'], + 'preview': row['preview'] or 0, + 'volume': row['volume'] or 1.0, 'maker_id': row['maker_id'], 'hash': row['hash'], 'order': row['id']