Hello! Following this discussion: Adding new custom fields to user profile
I took the approach of implementing a plug-in to add custom fields. To simplify this example, currently I am trying to add an additional hardcoded field called “Country”:
class CustomProfileForm(IndicoForm):
"""Form for custom profile fields."""
country = StringField(
"Country", [Optional()], description="Your country of residence"
)
However, I am not sure where the best place to include this in the templates is. I don’t think there exists a template-hook as of right now that I can use ( correct me if I am wrong ). So what would be the best approach here? Is it:
1- I can see in indico/modules/users/client/js/PersonalDataForm.jsx that there is a rendering functions for plugin components:
{renderPluginComponents('user-personal-data-form-inputs', {
userValues,
syncedValues,
lockedFields,
lockedFieldMessage,
})}
I haven’t worked with .js before but I assume I have a way of sending the plugin components through user-personal-data-form-inputs entry point? If so, what’s the best way to do it via Indico API?
2- Create a template hook somewhere, contributing to core? I am not sure where though.
3- Override existing template with an HTML of my own? ( Dirtiest approach I assume )
Many thanks for the help!
For reference ( just in case it helps ): This is the current DB model I am using for this particular plugin:
from indico.core.db import db
from indico.modules.users.models.users import User
from indico.util.string import format_repr
class UserCustomProfile(db.Model):
"""Model for storing custom user profile fields."""
__tablename__ = "user_custom_profiles"
__table_args__ = (
db.UniqueConstraint("user_id"),
{"schema": "plugin_custom_profile_fields"},
)
id = db.Column(db.Integer, primary_key=True)
user_id = db.Column(
db.Integer, db.ForeignKey("users.users.id"), nullable=False, index=True
)
# Professional Information
country = db.Column(db.String, nullable=True) # Country of residence
# Relationships
user = db.relationship(
"User",
lazy=True,
backref=db.backref(
"custom_profile", lazy=True, uselist=False, cascade="all, delete-orphan"
),
)
def __repr__(self):
"""String representation."""
return format_repr(
self, "id", "user_id", _text=self.user.full_name if self.user else None
)
@classmethod
def get_for_user(cls, user):
"""Get custom profile for a user, creating if necessary."""
if isinstance(user, int):
user = User.get(user)
if not user:
return None
profile = cls.query.filter_by(user_id=user.id).first()
if not profile:
profile = cls(user=user)
return profile
