diff --git a/app/profile/routes.py b/app/profile/routes.py index 74d742be..4702dcb7 100644 --- a/app/profile/routes.py +++ b/app/profile/routes.py @@ -10,7 +10,7 @@ from flask import ( from flask_login import current_user, login_required import os from app import db -from app.models import Avatar +from app.models import Avatar, User from . import bp from .forms import ( EditProfileSettingsForm @@ -22,14 +22,15 @@ def before_request(): pass -@bp.route('') -def profile(): +@bp.route('/') +def profile(user_id): + user = User.query.get_or_404(user_id) return render_template('profile/profile_page.html.j2', - user=current_user) + user=user) -@bp.route('/avatars/') -def avatar_download(avatar_id): - avatar_file = Avatar.query.get_or_404(avatar_id) +@bp.route('//avatars/') +def avatar_download(user_id, avatar_id): + avatar_file = Avatar.query.filter_by(user_id = user_id, id = avatar_id).first_or_404() if not (avatar_file and avatar_file.filename): abort(404) return send_from_directory( @@ -40,8 +41,9 @@ def avatar_download(avatar_id): mimetype=avatar_file.mimetype ) -@bp.route('/edit-profile', methods=['GET', 'POST']) -def edit_profile(): +@bp.route('//edit-profile', methods=['GET', 'POST']) +def edit_profile(user_id): + user = User.query.get_or_404(user_id) edit_profile_settings_form = EditProfileSettingsForm( current_user, data=current_user.to_json_serializeable(), @@ -63,7 +65,8 @@ def edit_profile(): db.session.commit() message = Markup(f'Profile settings updated') flash(message, 'success') - return redirect(url_for('.profile')) + return redirect(url_for('.profile', user_id=user.id)) return render_template('profile/edit_profile.html.j2', edit_profile_settings_form=edit_profile_settings_form, + user=user, title='Edit Profile') diff --git a/app/static/js/RessourceLists/PublicCorporaList.js b/app/static/js/RessourceLists/PublicCorporaList.js new file mode 100644 index 00000000..2171396e --- /dev/null +++ b/app/static/js/RessourceLists/PublicCorporaList.js @@ -0,0 +1,70 @@ +class PublicCorporaList extends RessourceList { + static instances = []; + + static getInstance(elem) { + return PublicCorporaList.instances.find((instance) => { + return instance.listjs.list === elem; + }); + } + + static autoInit() { + for (let publicCorporaListElement of document.querySelectorAll('.public-corpora-list:not(.no-autoinit)')) { + new PublicCorporaList(publicCorporaListElement); + } + } + + static options = { + initialHtmlGenerator: (id) => { + return ` +
+ search + + +
+ + + + + + + + + + +
TitleDescription
+
    + `.trim(); + }, + item: ` + + book + + + + `.trim(), + ressourceMapper: (corpus) => { + return { + 'id': corpus.id, + 'creation-date': corpus.creation_date, + 'description': corpus.description, + 'title': corpus.title + }; + }, + sortArgs: ['creation-date', {order: 'desc'}], + valueNames: [ + {data: ['id']}, + {data: ['creation-date']}, + 'description', + 'title' + ] + }; + + constructor(listElement, options = {}) { + super(listElement, {...PublicCorporaList.options, ...options}); + PublicCorporaList.instances.push(this); + } + + init(user) { + this._init(user.corpora.is_public); + } +} diff --git a/app/static/js/RessourceLists/RessourceList.js b/app/static/js/RessourceLists/RessourceList.js index 871a1e2f..5af7a231 100644 --- a/app/static/js/RessourceLists/RessourceList.js +++ b/app/static/js/RessourceLists/RessourceList.js @@ -10,6 +10,7 @@ class RessourceList { JobList.autoInit(); JobInputList.autoInit(); JobResultList.autoInit(); + PublicCorporaList.autoInit(); SpaCyNLPPipelineModelList.autoInit(); TesseractOCRPipelineModelList.autoInit(); UserList.autoInit(); diff --git a/app/templates/_scripts.html.j2 b/app/templates/_scripts.html.j2 index 7cc8a8f8..8ff90c33 100644 --- a/app/templates/_scripts.html.j2 +++ b/app/templates/_scripts.html.j2 @@ -24,6 +24,7 @@ 'js/RessourceLists/JobList.js', 'js/RessourceLists/JobInputList.js', 'js/RessourceLists/JobResultList.js', + 'js/RessourceLists/PublicCorporaList.js', 'js/RessourceLists/SpacyNLPPipelineModelList.js', 'js/RessourceLists/TesseractOCRPipelineModelList.js', 'js/RessourceLists/UserList.js' diff --git a/app/templates/_sidenav.html.j2 b/app/templates/_sidenav.html.j2 index f87f701e..cd86fe6c 100644 --- a/app/templates/_sidenav.html.j2 +++ b/app/templates/_sidenav.html.j2 @@ -4,7 +4,7 @@
    diff --git a/app/templates/profile/edit_profile.html.j2 b/app/templates/profile/edit_profile.html.j2 index e1a49ef4..1f4bd0e7 100644 --- a/app/templates/profile/edit_profile.html.j2 +++ b/app/templates/profile/edit_profile.html.j2 @@ -14,16 +14,24 @@
    {{ edit_profile_settings_form.hidden_tag() }}
    -
    -
    - {% if current_user.avatar %} - user-image - {% else %} - user-image - {% endif %} - {{wtf.render_field(edit_profile_settings_form.avatar, accept='image/jpeg, image/png, image/gif', class='file-path validate')}} +
    +
    +
    +
    + {% if current_user.avatar %} + user-image + {% else %} + user-image + {% endif %} +
    +
    +
    +
    +
    + {{wtf.render_field(edit_profile_settings_form.avatar, accept='image/jpeg, image/png, image/gif', placeholder="Choose an image file")}} +
    +
    -
    {{ wtf.render_field(edit_profile_settings_form.username, material_icon='person') }} {{ wtf.render_field(edit_profile_settings_form.email, material_icon='email') }} diff --git a/app/templates/profile/profile_page.html.j2 b/app/templates/profile/profile_page.html.j2 index 2845aedd..dbcd78ca 100644 --- a/app/templates/profile/profile_page.html.j2 +++ b/app/templates/profile/profile_page.html.j2 @@ -11,7 +11,7 @@
    {% if user.avatar %} - user-image + user-image {% else %} user-image {% endif %} @@ -67,12 +67,31 @@

    Member since: {{ user.member_since.strftime('%Y-%m-%d') }}


    - Edit profile + {% if current_user.is_authenticated and current_user.id == user.id %} + Edit profile + {% endif %}
    +
    +
    +
    +
    +

    Groups

    +
    +
    +
    +
    +
    +
    +

    Public corpora

    +
    +
    +
    +
    +
    {% endblock page_content %}