Fix + JS hack
This commit is contained in:
parent
cad684e209
commit
3d88dd7979
4
app.py
4
app.py
@ -140,7 +140,7 @@ def admin_add():
|
|||||||
titles = AnimeTitle.query.all()
|
titles = AnimeTitle.query.all()
|
||||||
link = AnimeLink()
|
link = AnimeLink()
|
||||||
for attr in dir(link):
|
for attr in dir(link):
|
||||||
if not attr.startswith('_'):
|
if not attr.startswith('_') and getattr(link, attr) is None:
|
||||||
try:
|
try:
|
||||||
setattr(link, attr, '')
|
setattr(link, attr, '')
|
||||||
except:
|
except:
|
||||||
@ -154,7 +154,7 @@ def admin_add():
|
|||||||
def admin_save():
|
def admin_save():
|
||||||
form = EditForm(request.form)
|
form = EditForm(request.form)
|
||||||
if form.validate_on_submit():
|
if form.validate_on_submit():
|
||||||
folder = AnimeFolder.query.filter_by(id=form.folder)
|
folder = AnimeFolder.query.filter_by(id=form.folder).first()
|
||||||
title = AnimeTitle.query.filter_by(name=form.name).first()
|
title = AnimeTitle.query.filter_by(name=form.name).first()
|
||||||
title.folder = folder
|
title.folder = folder
|
||||||
title.name = form.name
|
title.name = form.name
|
||||||
|
@ -21,11 +21,23 @@
|
|||||||
{{ edit_form.name(value=link.title.name, list='animes', class='input', placeholder='Name') }}
|
{{ edit_form.name(value=link.title.name, list='animes', class='input', placeholder='Name') }}
|
||||||
<datalist id="animes">
|
<datalist id="animes">
|
||||||
{% for title in titles %}
|
{% for title in titles %}
|
||||||
<option {{ 'selected' if title.id == link.title.id }}>
|
<option {{ 'selected' if title.id == link.title.id }}
|
||||||
{{ title.name }}
|
data-folder-id="{{ title.folder.id }}" value="{{ title.name }}"
|
||||||
</option>
|
data-keyword="{{ title.keyword }}">
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</datalist>
|
</datalist>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
document.getElementById('name').oninput = function (choice) {
|
||||||
|
var datalist = document.getElementById('animes').childNodes;
|
||||||
|
datalist.forEach(function (option) {
|
||||||
|
if (option.value === choice.target.value) {
|
||||||
|
document.getElementById('folder').value = option.dataset.folderId;
|
||||||
|
document.getElementById('keyword').value = option.dataset.keyword;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
</script>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -62,9 +74,8 @@
|
|||||||
{{ edit_form.keyword(value=link.title.keyword, list='keywords', class='input', placeholder='Keyword') }}
|
{{ edit_form.keyword(value=link.title.keyword, list='keywords', class='input', placeholder='Keyword') }}
|
||||||
<datalist id="keywords">
|
<datalist id="keywords">
|
||||||
{% for title in titles %}
|
{% for title in titles %}
|
||||||
<option {{ 'selected' if title.keyword == link.title.keyword }}>
|
<option {{ 'selected' if title.keyword == link.title.keyword }}
|
||||||
{{ title.keyword }}
|
value="{{ title.keyword }}">
|
||||||
</option>
|
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</datalist>
|
</datalist>
|
||||||
</div>
|
</div>
|
||||||
|
Reference in New Issue
Block a user