bottle-cork
bottle-cork copied to clipboard
Best way to add more user fields to user profile?
I can see user profile fields are created in:
register()
- https://github.com/FedericoCeratto/bottle-cork/blob/master/cork/cork.py#L387
and then passed through to pending_registrations
collection and then users
collection on validate_registration()
.
What is the best way to add more user fields without hacking bottle-cork
files?
Possibly (with pymongo
):
-
Add fields to
pending_registrations
collection afterregister()
, by assigningpost_get('email_address')
to variableemail_addr
and matching it in thepending_registrations
collection and adding new fields withdb.pending_registrations.update({"email_addr": email_addr},{"$set": {"new_key1":[],"new_key_2":"hello"}})
. (I tried this, it works). -
But then I need to ensure that the fields are added to
users
collection atvalidate_registration()
, but these fields are "hard-coded" here:
# the user data is moved from pending_registrations to _users
self._store.users[username] = {
'role': data['role'],
'hash': data['hash'],
'email_addr': data['email_addr'],
'desc': data['desc'],
'creation_date': data['creation_date'],
'last_login': str(datetime.utcnow())
}
https://github.com/FedericoCeratto/bottle-cork/blob/master/cork/cork.py#L467
I ended up just having to hardcode changes in cork.py
at validate_registration()
.
Just thinking out loud, I wonder if it is possible to iterate over data
, get its key names and dynamically create the required key values to be added to users
collection (so the custom fields are added as well). And perhaps pop off the unnecessary fields - pending registration number etc. Might have a look at doing that when I have a moment.