-
Notifications
You must be signed in to change notification settings - Fork 21
Member creation 3 of 3 ‐ Creating an account
Théophile MADET edited this page Jun 28, 2024
·
6 revisions
This third step is optional because not every member needs an account. Typically, investing members can't do much on Tapir except look at their information, so we usually don't create an account for them.
The button to create the account is on the member's page (ShareOwnerDetailView
) and links to the CreateUserFromShareOwnerView
.
This view is does not have a form class but instead has the form information built-in with the fields
class variable.
It's code is fairly short but quite a lot is actually happening. The interesting part is inside form_valid()
, which is called once the form has been confirmed valid, so that's when we know we can perform the relevant actions. Here are the steps:
- Link the ShareOwner to the TapirUser. We can already blank the info fields because their value has been copied in the tapir_user in
get_form_kwargs()
. TapirUser is already created because our view inherits fromCreateView
.
tapir_user = form.instance
share_owner = self.get_shareowner()
share_owner.user = tapir_user
share_owner.blank_info_fields()
share_owner.save()
- Callbacks are called, if any. Callbacks are like events that other apps can register to. They are an attempt to remove dependencies on the shift app inside other apps. You can see where the shift app registers a listener in
tapir.shifts.apps.ShiftConfig
for callback in on_welcome_session_attendance_update:
callback(share_owner)
- Any log that was previously linked to the
ShareOwner
gets linked to theTapirUser
instead.
LogEntry.objects.filter(share_owner=share_owner).update(
user=tapir_user, share_owner=None
)