Fix crash on no database

This commit is contained in:
Michel Roux 2019-12-13 19:21:08 +01:00
parent 896927e156
commit 1d06a9507c
2 changed files with 5 additions and 4 deletions

6
app.py
View File

@ -126,15 +126,17 @@ def admin_delete():
def admin_edit(link_id): def admin_edit(link_id):
link = AnimeLink.query.filter_by(id=link_id).first() link = AnimeLink.query.filter_by(id=link_id).first()
titles = AnimeTitle.query.all() titles = AnimeTitle.query.all()
edit_form = EditForm()
edit_form.folder.choices = [(query.id, query.name) for query in AnimeFolder.query.all()]
return render_template('admin/edit.html', search_form=SearchForm(), link=link, titles=titles, edit_form=EditForm()) return render_template('admin/edit.html', search_form=SearchForm(), link=link, titles=titles, edit_form=edit_form)
@app.route('/admin/add') @app.route('/admin/add')
@auth.login_required @auth.login_required
def admin_add(): def admin_add():
edit_form = EditForm() edit_form = EditForm()
edit_form.folder.choices = [(0, '')] + edit_form.folder.choices edit_form.folder.choices = [(0, '')] + [(query.id, query.name) for query in AnimeFolder.query.all()]
titles = AnimeTitle.query.all() titles = AnimeTitle.query.all()
link = AnimeLink() link = AnimeLink()
for attr in dir(link): for attr in dir(link):

View File

@ -42,8 +42,7 @@ class DeleteForm(FlaskForm):
class EditForm(FlaskForm): class EditForm(FlaskForm):
id = HiddenField('id') id = HiddenField('id')
folder = SelectField('folder', validators=[DataRequired()], folder = SelectField('folder', validators=[DataRequired()], coerce=int)
choices=[(query.id, query.name) for query in AnimeFolder.query.all()], coerce=int)
name = StringField('name', validators=[DataRequired()]) name = StringField('name', validators=[DataRequired()])
link = URLField('link', validators=[DataRequired()]) link = URLField('link', validators=[DataRequired()])
season = StringField('season', validators=[DataRequired()]) season = StringField('season', validators=[DataRequired()])