index + db

This commit is contained in:
gauthiier
2020-01-25 10:57:13 +01:00
parent afc71795d1
commit 56aab9e545
19 changed files with 6027 additions and 158 deletions
+40 -22
View File
@@ -31,28 +31,6 @@ def read_index(d, fn):
return index_data
# def add_selected_kw_index(d, fn, kw):
# fp = os.path.join(d, fn)
# if not os.path.isfile(fp):
# return False
# with open(fp) as f:
# index_data = json.load(f)
# if kw not in index_data['orphan']:
# return False
# v = index_data['orphan'].pop(kw)
# if kw not in index_data['selected']:
# index_data['selected'][kw] = []
# index_data['selected'][kw] += v
# with open(fp, 'w') as fout:
# json.dump(index_data, fout, indent=4, sort_keys=True, ensure_ascii=False)
# return True
def modify_selected_kw_index(d, fn, kw, action="add"):
fp = os.path.join(d, fn)
@@ -85,6 +63,15 @@ def modify_selected_kw_index(d, fn, kw, action="add"):
return True
def read_index_master(d, fn):
fp = os.path.join(d, fn)
if not os.path.isfile(fp):
return False
with open(fp) as f:
index_data = json.load(f, object_pairs_hook=OrderedDict)
return index_data
@app.route('/index', methods = ['GET'])
def index():
@@ -114,6 +101,37 @@ def indexfn(fn):
return "ok"
return "-"
@app.route('/index-master', methods = ['GET', 'POST'])
def indexmaster():
if request.method == 'GET':
data = read_index_master(config.index['path'], config.index['master'])
if data is not None:
return render_template("indx.master.html", fn="INDEX [MASTER]", master=data)
else:
return "File: " + os.path.join(config.index['path'], config.index['master']) + "does not exist."
elif request.method == 'POST':
data = request.form
a = data.get('action')
print(a)
if a == "regex":
logging.info("POST REGEX " + data.get('kw') + " ++ " + data.get('reg'))
reg = json.loads(data.get('reg').replace("'", ""))
print(type(data.get('reg')))
return "POST REGEX " + data.get('kw') + " ++ " + data.get('reg')
# if modify_selected_kw_index(config.index['path'], fn, data.get('kw')):
# return "ok"
elif a == "collate":
logging.info("POST COLLATE " + data.get('kw') + " ++ " + data.get('col'))
return "POST COLLATE " + data.get('kw') + " ++ " + data.get('col')
# if modify_selected_kw_index(config.index['path'], fn, data.get('kw'), action="delete"):
# return "ok"
elif a == "delete":
logging.info("POST DELETE " + data.get('kw'))
return "POST DELETE " + data.get('kw')
# if modify_selected_kw_index(config.index['path'], fn, data.get('kw'), action="delete"):
# return "ok"
return "-"
'''
XML
+12
View File
@@ -0,0 +1,12 @@
$(document).ready(function(){
$('.delete, .regex, .collate').click(function(e) {
var li = $(this).parent("li");
var reg = li.children(".regex_input")[0].value;
var col = li.children(".collate_input")[0].value;
$.post('/index-master', {'action': $(this).attr('class'), 'kw': li.data("kw"), 'reg': reg, 'col': col}, function(d) {
if(d === 'ok') {
location.reload();
}
});
});
});
+28
View File
@@ -0,0 +1,28 @@
<html>
<head>
<meta charset="utf-8">
<title>{{fn}}</title>
<script type="text/javascript" src="{{ url_for('static',filename='jquery-3.2.1.min.js') }}" charset="utf-8"></script>
<script type="text/javascript" src="{{ url_for('static',filename='indx.master.js') }}"></script>
</head>
<body>
<h1>{{fn}}</h1>
<div id="all">
<h2>Selected</h2>
<ul>
{% for kw, s in master.items() %}
<li data-kw="{{kw}}" data-list="master">{{kw}} - <input type="text" class="regex_input" value="{{s.regex}}"> <button class="regex">+</button> - <input type="text" class="collate_input" value=""> <button class="collate">+</button> - <button class="delete">-</button>
<ul>
{% for i in s.indx %}
<li>{{i}}</li>
{% endfor %}
</ul>
</li>
{% endfor %}
</ul>
<hr>
<hr>
<hr>
</div>
</body>
</html>