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()
|
||||
link = AnimeLink()
|
||||
for attr in dir(link):
|
||||
if not attr.startswith('_'):
|
||||
if not attr.startswith('_') and getattr(link, attr) is None:
|
||||
try:
|
||||
setattr(link, attr, '')
|
||||
except:
|
||||
@ -154,7 +154,7 @@ def admin_add():
|
||||
def admin_save():
|
||||
form = EditForm(request.form)
|
||||
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.folder = folder
|
||||
title.name = form.name
|
||||
|
@ -21,11 +21,23 @@
|
||||
{{ edit_form.name(value=link.title.name, list='animes', class='input', placeholder='Name') }}
|
||||
<datalist id="animes">
|
||||
{% for title in titles %}
|
||||
<option {{ 'selected' if title.id == link.title.id }}>
|
||||
{{ title.name }}
|
||||
</option>
|
||||
<option {{ 'selected' if title.id == link.title.id }}
|
||||
data-folder-id="{{ title.folder.id }}" value="{{ title.name }}"
|
||||
data-keyword="{{ title.keyword }}">
|
||||
{% endfor %}
|
||||
</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>
|
||||
@ -62,9 +74,8 @@
|
||||
{{ edit_form.keyword(value=link.title.keyword, list='keywords', class='input', placeholder='Keyword') }}
|
||||
<datalist id="keywords">
|
||||
{% for title in titles %}
|
||||
<option {{ 'selected' if title.keyword == link.title.keyword }}>
|
||||
{{ title.keyword }}
|
||||
</option>
|
||||
<option {{ 'selected' if title.keyword == link.title.keyword }}
|
||||
value="{{ title.keyword }}">
|
||||
{% endfor %}
|
||||
</datalist>
|
||||
</div>
|
||||
|
Reference in New Issue
Block a user