diff --git a/app/__init__.py b/app/__init__.py index 4c2ef68e..318502f4 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -91,6 +91,7 @@ def create_app(config: Config = Config) -> Flask: app.register_blueprint(services_blueprint, url_prefix='/services') from .users import bp as users_blueprint + default_breadcrumb_root(users_blueprint, '.users') app.register_blueprint(users_blueprint, url_prefix='/users') return app diff --git a/app/contributions/spacy_nlp_pipeline_models/utils.py b/app/contributions/spacy_nlp_pipeline_models/utils.py index 204bc56d..e73bbfd6 100644 --- a/app/contributions/spacy_nlp_pipeline_models/utils.py +++ b/app/contributions/spacy_nlp_pipeline_models/utils.py @@ -4,7 +4,7 @@ from app.models import SpaCyNLPPipelineModel def spacy_nlp_pipeline_model_dlc(): snpm_id = request.view_args['spacy_nlp_pipeline_model_id'] - snpm = SpaCyNLPPipelineModel.query.get(snpm_id) + snpm = SpaCyNLPPipelineModel.query.get_or_404(snpm_id) return [ { 'text': f'{snpm.title} {snpm.version}', diff --git a/app/contributions/tesseract_ocr_pipeline_models/utils.py b/app/contributions/tesseract_ocr_pipeline_models/utils.py index d957f271..d0fcd758 100644 --- a/app/contributions/tesseract_ocr_pipeline_models/utils.py +++ b/app/contributions/tesseract_ocr_pipeline_models/utils.py @@ -4,7 +4,7 @@ from app.models import TesseractOCRPipelineModel def tesseract_ocr_pipeline_model_dlc(): topm_id = request.view_args['tesseract_ocr_pipeline_model_id'] - topm = TesseractOCRPipelineModel.query.get(topm_id) + topm = TesseractOCRPipelineModel.query.get_or_404(topm_id) return [ { 'text': f'{topm.title} {topm.version}', diff --git a/app/corpora/utils.py b/app/corpora/utils.py index fd0e1c2a..f5319dce 100644 --- a/app/corpora/utils.py +++ b/app/corpora/utils.py @@ -8,7 +8,7 @@ def corpus_endpoint_arguments_constructor(): def corpus_dynamic_list_constructor(): corpus_id = request.view_args['corpus_id'] - corpus = Corpus.query.get(corpus_id) + corpus = Corpus.query.get_or_404(corpus_id) return [ { 'text': f'book{corpus.title}', diff --git a/app/jobs/routes.py b/app/jobs/routes.py index 0479cc5d..2533e010 100644 --- a/app/jobs/routes.py +++ b/app/jobs/routes.py @@ -21,7 +21,7 @@ def corpora(): @bp.route('/') -@register_breadcrumb(bp, '.job', '', dynamic_list_constructor=job_dlc) +@register_breadcrumb(bp, '.entity', '', dynamic_list_constructor=job_dlc) @login_required def job(job_id): job = Job.query.get_or_404(job_id) diff --git a/app/jobs/utils.py b/app/jobs/utils.py index 8417af04..554db354 100644 --- a/app/jobs/utils.py +++ b/app/jobs/utils.py @@ -4,7 +4,7 @@ from app.models import Job def job_dynamic_list_constructor(): job_id = request.view_args['job_id'] - job = Job.query.get(job_id) + job = Job.query.get_or_404(job_id) return [ { 'text': f'{job.title}', diff --git a/app/templates/main/social_area.html.j2 b/app/templates/main/social_area.html.j2 index 8aaeecfa..fc101aad 100644 --- a/app/templates/main/social_area.html.j2 +++ b/app/templates/main/social_area.html.j2 @@ -36,7 +36,7 @@
-

Other Users

+

Other Users

Find other users and see what corpora they have made public.

diff --git a/app/users/routes.py b/app/users/routes.py index 82d37247..cd3f2ba4 100644 --- a/app/users/routes.py +++ b/app/users/routes.py @@ -1,16 +1,13 @@ -from datetime import datetime from flask import ( abort, - current_app, flash, - Markup, redirect, render_template, send_from_directory, url_for ) +from flask_breadcrumbs import register_breadcrumb from flask_login import current_user, login_required -from threading import Thread import os from app import db from app.models import Avatar, Corpus, ProfilePrivacySettings, User @@ -22,13 +19,21 @@ from .forms import ( EditProfileSettingsForm, EditPublicProfileInformationForm ) +from .utils import ( + user_endpoint_arguments_constructor as user_eac, + user_dynamic_list_constructor as user_dlc +) -@bp.before_request + +@bp.route('') +@register_breadcrumb(bp, '.', 'Users') @login_required -def before_request(): - pass +def users(): + return redirect(url_for('main.social_area', _anchor='users')) + @bp.route('/') +@register_breadcrumb(bp, '.entity', '', dynamic_list_constructor=user_dlc) @login_required def user(user_id): user = User.query.get_or_404(user_id) @@ -50,12 +55,13 @@ def user(user_id): member_since=member_since, own_public_corpora=own_public_corpora, user=user.to_json_serializeable(), - user_id=user_id + user_id=user_id, + title=user.username ) - @bp.route('//avatar') +@login_required def profile_avatar(user_id): user = User.query.get_or_404(user_id) if user.avatar is None: @@ -72,6 +78,8 @@ def profile_avatar(user_id): @bp.route('//edit', methods=['GET', 'POST']) +@register_breadcrumb(bp, '.entity.edit', 'Edit', endpoint_arguments_constructor=user_eac) +@login_required def edit_profile(user_id): user = User.query.get_or_404(user_id) if not (user == current_user or current_user.is_administrator()): diff --git a/app/users/utils.py b/app/users/utils.py new file mode 100644 index 00000000..e352fe5c --- /dev/null +++ b/app/users/utils.py @@ -0,0 +1,17 @@ +from flask import request, url_for +from app.models import User + + +def user_endpoint_arguments_constructor(): + return {'user_id': request.view_args['user_id']} + + +def user_dynamic_list_constructor(): + user_id = request.view_args['user_id'] + user = User.query.get_or_404(user_id) + return [ + { + 'text': user.username, + 'url': url_for('.user', user_id=user_id) + } + ]