diff --git a/.gitignore b/.gitignore index da39247..63ebf93 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ *.swp *.swo backup +uploadTest +torrentFiles/* diff --git a/indexer.py b/indexer.py index c302593..2d5ff5e 100644 --- a/indexer.py +++ b/indexer.py @@ -1,23 +1,60 @@ #!/usr/bin/python3 #/* vim:set ts=2 set noexpandtab */ +import json from flask import Flask, render_template, url_for, request +from werkzeug import secure_filename app = Flask(__name__) +strings = None +settings = None @app.route("/") def index(): - return render_template("search.html") + return render_template("search.html", language="english", categories=settings["categories"], strings=strings) -@app.route("/categorys") +@app.route("/categories") def categorys(): - return render_template("categorys.html") + return render_template("categories.html", categories=settings["categories"]) -@app.route("/create") +@app.route("/create", methods=['GET','POST']) def create(): - return render_template("create.html") + if request.method == "GET": + return render_template("create.html", language="english", categories=settings["categories"], strings=strings, errors=None) + elif request.method == "POST": + uploadfile = request.files["torrentFile"] + filename = secure_filename(uploadfile.filename) + # TODO: Create unique filename so that existing files doesn't get overwritten + uploadfile.save("torrentFiles/" + filename) + # TODO: Process inputdate from the form and save it to the (until now) non-existing DB + print(request.form["name"]) + return "\o/" @app.route("/search", methods=['GET']) def search(): - return render_template("result.html", results=request.args.get("q", "")) + return render_template("result.html", results=request.args.get("q", "")) + +def init(): + global strings + global settings + with open("strings.json") as stringsJson: + strings = json.load(stringsJson) + + with open("settings.json") as settingsJson: + settings = json.load(settingsJson) + +def getLocalString(language, descriptor): + global strings + if language in strings.keys(): + if descriptor in strings[language].keys(): + return strings[language][descriptor] + else: + return descriptor + else: + return descriptor + if __name__ == "__main__": - app.run(debug=True) + init() + app.jinja_env.globals.update(getLocalString=getLocalString) + app.jinja_env.globals.update(json=json) + app.jinja_env.globals.update(sorted=sorted) + app.run(debug=True) diff --git a/static/js/create.js b/static/js/create.js index 49b1131..e899972 100644 --- a/static/js/create.js +++ b/static/js/create.js @@ -7,28 +7,28 @@ window.onload = function () { customizeUploadButton() } -function fillDropdownByValue(value, dropdownToFill) { - dropdownToFill.getElementsByClassName("text")[0].innerHTML = "Subcategory" - var dropdownToFillUl = dropdownToFill.getElementsByClassName("dropdown-menu")[0] - dropdownToFillUl.innerHTML = "" - - subCategory = getDescriptorByLocalString("english", value) - catList = document.getElementById("subcategory_list") - catList.innerHTML = "" - categories = global_categories[subCategory].sort() - for(var key in categories) { - var newEntry = document.createElement("li") - var newEntryLink = document.createElement("a") - newEntry.setAttribute("role", "presentation") - newEntryLink.setAttribute("role", "menuitem") - newEntryLink.tabIndex = -1 - newEntryLink.href = "#" - newEntryLink.innerHTML = getLocalString("english", categories[key]) - newEntryLink.onclick = function(){ setDropdownButtonText(this.innerHTML, this.parentElement.parentElement.parentElement) } - newEntry.appendChild(newEntryLink) - dropdownToFillUl.appendChild(newEntry) - } -} +//function fillDropdownByValue(value, dropdownToFill) { +// dropdownToFill.getElementsByClassName("text")[0].innerHTML = "Subcategory" +// var dropdownToFillUl = dropdownToFill.getElementsByClassName("dropdown-menu")[0] +// dropdownToFillUl.innerHTML = "" +// +// subCategory = getDescriptorByLocalString("english", value) +// catList = document.getElementById("subcategory_list") +// catList.innerHTML = "" +// categories = global_categories[subCategory].sort() +// for(var key in categories) { +// var newEntry = document.createElement("li") +// var newEntryLink = document.createElement("a") +// newEntry.setAttribute("role", "presentation") +// newEntryLink.setAttribute("role", "menuitem") +// newEntryLink.tabIndex = -1 +// newEntryLink.href = "#" +// newEntryLink.innerHTML = getLocalString("english", categories[key]) +// newEntryLink.onclick = function(){ setDropdownButtonText(this.innerHTML, this.parentElement.parentElement.parentElement) } +// newEntry.appendChild(newEntryLink) +// dropdownToFillUl.appendChild(newEntry) +// } +//} function setDropdownButtonText(text, dropdownButton) { var dropdownTextSpan = dropdownButton.getElementsByClassName("text")[0] @@ -38,51 +38,38 @@ function setDropdownButtonText(text, dropdownButton) { function sortCategories(categories) { var sortedCategories = [] for(var key in categories) { - sortedCategories.push(key) + sortedCategories.push(categories[key]) } sortedCategories.sort() return sortedCategories } +// Fill a defined dropdown with values. +// These values will be generated out of the categories.json function fillDropdownByValue(value, dropdownToFill) { dropdownToFill.getElementsByTagName("button")[0].disabled = false dropdownToFill.getElementsByClassName("text")[0].innerHTML = "Subcategorie" var dropdownToFillUl = dropdownToFill.getElementsByClassName("dropdown-menu")[0] dropdownToFillUl.innerHTML = "" - switch(value) { - case "Action": - for(i = 0; i < 10; i++) { - //
CATEGORIES
+{% endblock content%} diff --git a/templates/categorys.html b/templates/categorys.html deleted file mode 100644 index 3200c46..0000000 --- a/templates/categorys.html +++ /dev/null @@ -1,9 +0,0 @@ - -{% extends "index.html" %} -{% block title %}{{ super() }} - Categorys{% endblock%} -{% set active_page = "categorys" %} -{% block content %} -CATEGORYS
-{% endblock content%} diff --git a/templates/create.html b/templates/create.html index dbe3806..22d29af 100644 --- a/templates/create.html +++ b/templates/create.html @@ -2,91 +2,102 @@ vim: ts=2 noexpandtab --> {% extends "index.html" %} -{% block title %}{{ super() }} - Create{% endblock%} +{% block title %}{{ super() }} - {{ getLocalString(language, "create") }}{% endblock%} {% set active_page = "create" %} {% block content %} - - + +