From 6f3ea8b4b23d5ab8859479ad59baeb242d9420fd Mon Sep 17 00:00:00 2001 From: Fatimah Zulfiqar Date: Wed, 18 Dec 2024 17:05:56 +0100 Subject: [PATCH] forms: added custom user profile form --- invenio.cfg | 3 +++ site/zenodo_rdm/forms/__init__.py | 9 +++++++ site/zenodo_rdm/forms/profile_form.py | 35 +++++++++++++++++++++++++++ 3 files changed, 47 insertions(+) create mode 100644 site/zenodo_rdm/forms/__init__.py create mode 100644 site/zenodo_rdm/forms/profile_form.py diff --git a/invenio.cfg b/invenio.cfg index 7604e975..b1440865 100644 --- a/invenio.cfg +++ b/invenio.cfg @@ -73,6 +73,7 @@ from zenodo_rdm.files import storage_factory from zenodo_rdm.github.schemas import CitationMetadataSchema from zenodo_rdm.legacy.resources import record_serializers from zenodo_rdm.metrics.config import METRICS_CACHE_UPDATE_INTERVAL +from zenodo_rdm.forms import ZenodoProfileForm from zenodo_rdm.moderation.errors import UserBlockedException from zenodo_rdm.moderation.handlers import CommunityModerationHandler, RecordModerationHandler from zenodo_rdm.openaire.records.components import OpenAIREComponent @@ -735,6 +736,8 @@ USERPROFILES_READ_ONLY = ( False # allow users to change profile info (name, email, etc...) ) +USERPROFILES_FORM_CLASS = ZenodoProfileForm + THEME_SHOW_FRONTPAGE_INTRO_SECTION = False APP_RDM_RECORD_LANDING_PAGE_TEMPLATE = "zenodo_rdm/records/detail.html" diff --git a/site/zenodo_rdm/forms/__init__.py b/site/zenodo_rdm/forms/__init__.py new file mode 100644 index 00000000..056759ca --- /dev/null +++ b/site/zenodo_rdm/forms/__init__.py @@ -0,0 +1,9 @@ +# -*- coding: utf-8 -*- +# +# Copyright (C) 2023 CERN. +# +# Zenodo-RDM is free software; you can redistribute it and/or modify +# it under the terms of the MIT License; see LICENSE file for more details. +"""Forms module.""" + +from .profile_form import ZenodoProfileForm diff --git a/site/zenodo_rdm/forms/profile_form.py b/site/zenodo_rdm/forms/profile_form.py new file mode 100644 index 00000000..e6c3cbc0 --- /dev/null +++ b/site/zenodo_rdm/forms/profile_form.py @@ -0,0 +1,35 @@ +# -*- coding: utf-8 -*- +# +# Copyright (C) 2024 CERN. +# +# ZenodoRDM is free software; you can redistribute it and/or modify it +# under the terms of the MIT License; see LICENSE file for more details. + +"""Form for user profiles.""" + +from invenio_i18n import lazy_gettext as _ +from invenio_userprofiles.forms import ProfileForm, strip_filter +from wtforms import StringField, validators +from wtforms.validators import DataRequired, EqualTo, Length + + +class ZenodoProfileForm(ProfileForm): + """Form for editing user profile with stricter validation.""" + + full_name = StringField( + _("Full name"), + validators=[ + Length(max=255), + DataRequired(message=_("Full name not provided.")), + ], + filters=[strip_filter], + ) + + affiliations = StringField( + _("Affiliations"), + validators=[ + Length(max=255), + DataRequired(message=_("Affiliation not provided.")), + ], + filters=[strip_filter], + )