2015-02-05 01:02:32 +01:00
|
|
|
#!/usr/bin/python3
|
2015-02-09 00:13:32 +01:00
|
|
|
# vim:ts=2 sw=2 sts=2 noexpandtab
|
|
|
|
import json, os
|
2015-02-06 22:03:42 +01:00
|
|
|
from flask import Flask, render_template, url_for, request
|
2015-02-09 00:13:32 +01:00
|
|
|
from werkzeug import secure_filename
|
|
|
|
|
|
|
|
uploadFolder = "upload"
|
|
|
|
|
2015-02-05 22:17:33 +01:00
|
|
|
app = Flask(__name__)
|
2015-02-09 00:13:32 +01:00
|
|
|
app.config['UPLOAD_FOLDER'] = uploadFolder
|
|
|
|
|
|
|
|
strings = None
|
|
|
|
settings = None
|
2015-02-05 01:02:32 +01:00
|
|
|
|
2015-02-05 22:17:33 +01:00
|
|
|
@app.route("/")
|
|
|
|
def index():
|
2015-02-09 00:13:32 +01:00
|
|
|
return render_template("search.html", strings=strings)
|
2015-02-05 22:17:33 +01:00
|
|
|
|
2015-02-09 00:13:32 +01:00
|
|
|
@app.route("/categories")
|
2015-02-05 22:17:33 +01:00
|
|
|
def categorys():
|
2015-02-09 00:13:32 +01:00
|
|
|
return render_template("categories.html", strings=strings)
|
2015-02-05 22:17:33 +01:00
|
|
|
|
2015-02-05 22:38:39 +01:00
|
|
|
@app.route("/create")
|
|
|
|
def create():
|
2015-02-09 00:13:32 +01:00
|
|
|
return render_template("create.html", categories=settings["categories"], strings=strings)
|
2015-02-05 22:38:39 +01:00
|
|
|
|
2015-02-06 22:03:42 +01:00
|
|
|
@app.route("/search", methods=['GET'])
|
|
|
|
def search():
|
2015-02-09 00:13:32 +01:00
|
|
|
return render_template("result.html", results=request.args.get("q", ""), strings=strings)
|
|
|
|
|
|
|
|
def getLocalString(language, descriptor):
|
|
|
|
if language in strings.keys():
|
|
|
|
if descriptor in strings[language].keys():
|
|
|
|
return strings[language][descriptor]
|
|
|
|
else:
|
|
|
|
return None
|
|
|
|
else:
|
|
|
|
return None
|
|
|
|
|
|
|
|
def init():
|
|
|
|
global strings
|
|
|
|
global settings
|
|
|
|
with open("strings.json", "r") as strings:
|
|
|
|
strings = json.load(strings)
|
|
|
|
with open("settings.json", "r") as settings:
|
|
|
|
settings = json.load(settings)
|
2015-02-06 22:03:42 +01:00
|
|
|
|
2015-02-05 22:17:33 +01:00
|
|
|
if __name__ == "__main__":
|
2015-02-09 00:13:32 +01:00
|
|
|
app.jinja_env.globals.update(getLocalString=getLocalString)
|
|
|
|
app.jinja_env.globals.update(json=json)
|
|
|
|
init()
|
|
|
|
print(settings["categories"].keys())
|
|
|
|
app.run(debug=True)
|