mirror of
https://gitlab.ub.uni-bielefeld.de/sfb1288inf/nopaque.git
synced 2024-11-14 16:55:42 +00:00
Codestyle enhancements
This commit is contained in:
parent
1fd7a2e38c
commit
3d99b8770c
@ -69,8 +69,7 @@ def register():
|
||||
os.makedirs(user.path)
|
||||
except OSError:
|
||||
current_app.logger.error(
|
||||
'Make dir {} led to an OSError!'.format(user.path)
|
||||
)
|
||||
f'Make dir {user.path} led to an OSError!')
|
||||
db.session.delete(user)
|
||||
db.session.commit()
|
||||
abort(500)
|
||||
|
@ -82,7 +82,7 @@ def connect(auth):
|
||||
socketio.sleep(3)
|
||||
retry_counter -= 1
|
||||
db.session.refresh(corpus)
|
||||
cqi_client = cqi.CQiClient('cqpserver_{}'.format(corpus_id))
|
||||
cqi_client = cqi.CQiClient(f'cqpserver_{corpus_id}')
|
||||
session['d'] = {
|
||||
'corpus_id': corpus_id,
|
||||
'cqi_client': cqi_client,
|
||||
|
@ -33,8 +33,7 @@ def add_query_result():
|
||||
os.makedirs(os.path.dirname(query_result.path))
|
||||
except OSError:
|
||||
current_app.logger.error(
|
||||
'Make dir {} led to an OSError!'.format(query_result.path)
|
||||
)
|
||||
f'Make dir {query_result.path} led to an OSError!')
|
||||
db.session.rollback()
|
||||
flash('Internal Server Error', 'error')
|
||||
return make_response(
|
||||
@ -99,13 +98,15 @@ def inspect_query_result(query_result_id):
|
||||
)
|
||||
with open(query_result.path, 'r') as query_result_file:
|
||||
query_result_file_content = json.load(query_result_file)
|
||||
return render_template('corpora/query_results/inspect.html.j2',
|
||||
query_result=query_result,
|
||||
display_options_form=display_options_form,
|
||||
inspect_display_options_form=inspect_display_options_form, # noqa
|
||||
query_result_file_content=query_result_file_content,
|
||||
query_metadata=query_metadata,
|
||||
title='Inspect query result')
|
||||
return render_template(
|
||||
'corpora/query_results/inspect.html.j2',
|
||||
query_result=query_result,
|
||||
display_options_form=display_options_form,
|
||||
inspect_display_options_form=inspect_display_options_form, # noqa
|
||||
query_result_file_content=query_result_file_content,
|
||||
query_metadata=query_metadata,
|
||||
title='Inspect query result'
|
||||
)
|
||||
|
||||
|
||||
@bp.route('/result/<hashid:query_result_id>/delete')
|
||||
@ -116,7 +117,7 @@ def delete_query_result(query_result_id):
|
||||
if not (query_result.user == current_user
|
||||
or current_user.is_administrator()):
|
||||
abort(403)
|
||||
flash('Query result "{}" has been marked for deletion!'.format(query_result), 'result') # noqa
|
||||
flash(f'Query result "{query_result}" marked for deletion!', 'result')
|
||||
tasks.delete_query_result(query_result_id)
|
||||
return redirect(url_for('services.service', service="corpus_analysis"))
|
||||
|
||||
|
@ -37,7 +37,7 @@ def add_corpus():
|
||||
abort(500)
|
||||
else:
|
||||
db.session.commit()
|
||||
flash('Corpus "{}" added!'.format(corpus.title), 'corpus')
|
||||
flash(f'Corpus "{corpus.title}" added!', 'corpus')
|
||||
return redirect(url_for('.corpus', corpus_id=corpus.id))
|
||||
return render_template('corpora/add_corpus.html.j2', form=form,
|
||||
title='Add corpus')
|
||||
@ -102,7 +102,7 @@ def import_corpus():
|
||||
corpus.status = 'prepared'
|
||||
db.session.commit()
|
||||
os.remove(archive_file)
|
||||
flash('Corpus "{}" imported!'.format(corpus.title), 'corpus')
|
||||
flash(f'Corpus "{corpus.title}" imported!', 'corpus')
|
||||
return make_response(
|
||||
{'redirect_url': url_for('.corpus', corpus_id=corpus.id)}, 201)
|
||||
else:
|
||||
@ -158,7 +158,7 @@ def delete_corpus(corpus_id):
|
||||
corpus = Corpus.query.get_or_404(corpus_id)
|
||||
if not (corpus.user == current_user or current_user.is_administrator()):
|
||||
abort(403)
|
||||
flash('Corpus "{}" marked for deletion!'.format(corpus.title), 'corpus')
|
||||
flash(f'Corpus "{corpus.title}" marked for deletion!', 'corpus')
|
||||
tasks.delete_corpus(corpus_id)
|
||||
return redirect(url_for('main.dashboard'))
|
||||
|
||||
@ -194,7 +194,7 @@ def add_corpus_file(corpus_id):
|
||||
db.session.add(corpus_file)
|
||||
corpus.status = 'unprepared'
|
||||
db.session.commit()
|
||||
flash('Corpus file "{}" added!'.format(corpus_file.filename), 'corpus')
|
||||
flash(f'Corpus file "{corpus_file.filename}" added!', 'corpus')
|
||||
return make_response({'redirect_url': url_for('.corpus', corpus_id=corpus.id)}, 201) # noqa
|
||||
return render_template('corpora/add_corpus_file.html.j2', corpus=corpus,
|
||||
form=form, title='Add corpus file')
|
||||
@ -209,7 +209,8 @@ def delete_corpus_file(corpus_id, corpus_file_id):
|
||||
if not (corpus_file.corpus.user == current_user
|
||||
or current_user.is_administrator()):
|
||||
abort(403)
|
||||
flash('Corpus file "{}" marked for deletion!'.format(corpus_file.filename), 'corpus') # noqa
|
||||
flash(
|
||||
f'Corpus file "{corpus_file.filename}" marked for deletion!', 'corpus')
|
||||
tasks.delete_corpus_file(corpus_file_id)
|
||||
return redirect(url_for('.corpus', corpus_id=corpus_id))
|
||||
|
||||
@ -253,7 +254,7 @@ def corpus_file(corpus_id, corpus_file_id):
|
||||
corpus_file.title = form.title.data
|
||||
corpus.status = 'unprepared'
|
||||
db.session.commit()
|
||||
flash('Corpus file "{}" edited!'.format(corpus_file.filename), 'corpus') # noqa
|
||||
flash(f'Corpus file "{corpus_file.filename}" edited!', 'corpus')
|
||||
return redirect(url_for('.corpus', corpus_id=corpus_id))
|
||||
# If no form is submitted or valid, fill out fields with current values
|
||||
form.address.data = corpus_file.address
|
||||
@ -273,15 +274,15 @@ def corpus_file(corpus_id, corpus_file_id):
|
||||
title='Edit corpus file')
|
||||
|
||||
|
||||
@bp.route('/<hashid:corpus_id>/prepare')
|
||||
@bp.route('/<hashid:corpus_id>/build')
|
||||
@login_required
|
||||
def prepare_corpus(corpus_id):
|
||||
def build_corpus(corpus_id):
|
||||
corpus = Corpus.query.get_or_404(corpus_id)
|
||||
if not (corpus.user == current_user or current_user.is_administrator()):
|
||||
abort(403)
|
||||
if corpus.files.all():
|
||||
tasks.build_corpus(corpus_id)
|
||||
flash('Corpus "{}" has been marked to get build!'.format(corpus.title), 'corpus') # noqa
|
||||
flash(f'Corpus "{corpus.title}" marked for building!', 'corpus')
|
||||
else:
|
||||
flash('Can not build corpus "{}": No corpus file(s)!'.format(corpus.title), 'error') # noqa
|
||||
flash(f'Can\'t build corpus "{corpus.title}": No corpus file(s)!', 'error') # noqa
|
||||
return redirect(url_for('.corpus', corpus_id=corpus_id))
|
||||
|
@ -9,7 +9,7 @@ def build_corpus(corpus_id, *args, **kwargs):
|
||||
with app.app_context():
|
||||
corpus = Corpus.query.get(corpus_id)
|
||||
if corpus is None:
|
||||
raise Exception('Corpus {} not found'.format(corpus_id))
|
||||
raise Exception(f'Corpus {corpus_id} not found')
|
||||
corpus.build()
|
||||
db.session.commit()
|
||||
|
||||
@ -19,7 +19,7 @@ def delete_corpus(corpus_id, *args, **kwargs):
|
||||
with kwargs['app'].app_context():
|
||||
corpus = Corpus.query.get(corpus_id)
|
||||
if corpus is None:
|
||||
raise Exception('Corpus {} not found'.format(corpus_id))
|
||||
raise Exception(f'Corpus {corpus_id} not found')
|
||||
corpus.delete()
|
||||
db.session.commit()
|
||||
|
||||
@ -29,7 +29,7 @@ def delete_corpus_file(corpus_file_id, *args, **kwargs):
|
||||
with kwargs['app'].app_context():
|
||||
corpus_file = CorpusFile.query.get(corpus_file_id)
|
||||
if corpus_file is None:
|
||||
raise Exception('Corpus file {} not found'.format(corpus_file_id))
|
||||
raise Exception(f'Corpus file {corpus_file_id} not found')
|
||||
corpus_file.delete()
|
||||
db.session.commit()
|
||||
|
||||
@ -39,6 +39,6 @@ def delete_query_result(query_result_id, *args, **kwargs):
|
||||
with kwargs['app'].app_context():
|
||||
query_result = QueryResult.query.get(query_result_id)
|
||||
if query_result is None:
|
||||
raise Exception('QueryResult {} not found'.format(query_result_id))
|
||||
raise Exception(f'QueryResult {query_result_id} not found')
|
||||
query_result.delete()
|
||||
db.session.commit()
|
||||
|
@ -48,10 +48,10 @@ def download_job_input(job_id, job_input_id):
|
||||
def restart(job_id):
|
||||
job = Job.query.get_or_404(job_id)
|
||||
if job.status not in ['complete', 'failed']:
|
||||
flash('Can not restart job "{}": Status is not "complete/failed"'.format(job.title), 'error') # noqa
|
||||
flash(f'Can not restart job "{job.title}": Status is not "complete/failed"', 'error') # noqa
|
||||
else:
|
||||
tasks.restart_job(job_id)
|
||||
flash('Job "{}" has been marked to get restarted!'.format(job.title), 'job') # noqa
|
||||
flash(f'Job "{job.title}" marked to get restarted!', 'job')
|
||||
return redirect(url_for('.job', job_id=job_id))
|
||||
|
||||
|
||||
|
@ -8,7 +8,7 @@ def delete_job(job_id, *args, **kwargs):
|
||||
with kwargs['app'].app_context():
|
||||
job = Job.query.get(job_id)
|
||||
if job is None:
|
||||
raise Exception('Job {} not found'.format(job_id))
|
||||
raise Exception(f'Job {job_id} not found')
|
||||
job.delete()
|
||||
db.session.commit()
|
||||
|
||||
@ -18,7 +18,7 @@ def restart_job(job_id, *args, **kwargs):
|
||||
with kwargs['app'].app_context():
|
||||
job = Job.query.get(job_id)
|
||||
if job is None:
|
||||
raise Exception('Job {} not found'.format(job_id))
|
||||
raise Exception(f'Job {job_id} not found')
|
||||
try:
|
||||
job.restart()
|
||||
except Exception:
|
||||
|
@ -37,11 +37,11 @@ def service(service):
|
||||
return make_response(form.errors, 400)
|
||||
service_args = []
|
||||
if service == 'nlp':
|
||||
service_args.append('-l {}'.format(form.language.data))
|
||||
service_args.append(f'-l {form.language.data}')
|
||||
if form.check_encoding.data:
|
||||
service_args.append('--check-encoding')
|
||||
if service == 'ocr':
|
||||
service_args.append('-l {}'.format(form.language.data))
|
||||
service_args.append(f'-l {form.language.data}')
|
||||
if form.binarization.data:
|
||||
service_args.append('--binarize')
|
||||
job = Job(user=current_user,
|
||||
@ -55,9 +55,7 @@ def service(service):
|
||||
try:
|
||||
os.makedirs(job.path)
|
||||
except OSError:
|
||||
current_app.logger.error(
|
||||
'Make dir {} led to an OSError!'.format(job.path)
|
||||
)
|
||||
current_app.logger.error(f'Make dir {job.path} led to an OSError!')
|
||||
db.session.rollback()
|
||||
flash('Internal Server Error', 'error')
|
||||
return make_response(
|
||||
@ -71,8 +69,12 @@ def service(service):
|
||||
db.session.add(job_input)
|
||||
job.status = 'submitted'
|
||||
db.session.commit()
|
||||
flash('Job "{}" added'.format(job.title), 'job')
|
||||
flash(f'Job "{job.title}" added', 'job')
|
||||
return make_response(
|
||||
{'redirect_url': url_for('jobs.job', job_id=job.id)}, 201)
|
||||
return render_template('services/{}.html.j2'.format(service.replace('-', '_')),
|
||||
form=form, title=title, versions=versions)
|
||||
return render_template(
|
||||
f'services/{service.replace("-", "_")}.html.j2',
|
||||
form=form,
|
||||
title=title,
|
||||
versions=versions
|
||||
)
|
||||
|
@ -8,6 +8,6 @@ def delete_user(user_id, *args, **kwargs):
|
||||
with kwargs['app'].app_context():
|
||||
user = User.query.get(user_id)
|
||||
if user is None:
|
||||
raise Exception('User {} not found'.format(user_id))
|
||||
raise Exception(f'User {user_id} not found')
|
||||
user.delete()
|
||||
db.session.commit()
|
||||
|
@ -65,7 +65,7 @@
|
||||
</div>
|
||||
<div class="card-action right-align">
|
||||
<a class="analyse-corpus-trigger btn disabled waves-effect waves-light" href="{{ url_for('corpora.analyse_corpus', corpus_id=corpus.id) }}"><i class="material-icons left">search</i>Analyze</a>
|
||||
<a class="btn build-corpus-trigger disabled waves-effect waves-light" href="{{ url_for('corpora.prepare_corpus', corpus_id=corpus.id) }}"><i class="nopaque-icons left">K</i>Build</a>
|
||||
<a class="btn build-corpus-trigger disabled waves-effect waves-light" href="{{ url_for('corpora.build_corpus', corpus_id=corpus.id) }}"><i class="nopaque-icons left">K</i>Build</a>
|
||||
<a class="btn disabled export-corpus-trigger waves-effect waves-light"><i class="material-icons left">import_export</i>Export</a>
|
||||
<a class="btn modal-trigger red waves-effect waves-light" data-target="delete-corpus-modal"><i class="material-icons left">delete</i>Delete</a>
|
||||
</div>
|
||||
|
Loading…
Reference in New Issue
Block a user