You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Adding hooksets is a pattern we've been using in various apps to provide extensibility into our apps so that a site developer can customize behavior by just implementing methods.
As an example, take a look at hooks.py in django-user-accounts. It's just an object with methods defined. There is a bit of infrastructure like the HookProxy and the configure_hookset method in conf.py but once you have it hooked up, you are just porting existing functionality in the app into these methods that gives the user an opportunity to override at the site level.
Hooksets we should provide:
share_with_options(user, folder) - takes the current user, and the folder object and returns a list of users that user can share the folder with. it currently defaults to User.objects.all() in the folder_share view.
folder_shared_message(request, user, folder) - currently there is no messages.success message for successful share. there should be but it should be sent within this default hookset method.
folder_unshared_message(request, user, folder) - port the messages.success message currently being sent when a user is removed from a folder share to this default hookset method
document_deleted_message(request, document)
folder_created_message(request, folder)
document_created_message(request, document)
can_share_folder(user, folder) - the current default implementation is on Folder object as can_share(user) method. move this logic into the hookset method and just call the hookset method from within this model method (e.g. return hookset.can_share_folder(user, folder=self))
storage_color(user_storage) - replace internals of UserStorage.color property with this hookset method so that these ranges and labels can be overridden at site level.
All this should leave you with a hookset with the following signature:
Adding hooksets is a pattern we've been using in various apps to provide extensibility into our apps so that a site developer can customize behavior by just implementing methods.
As an example, take a look at
hooks.py
indjango-user-accounts
. It's just an object with methods defined. There is a bit of infrastructure like theHookProxy
and theconfigure_hookset
method inconf.py
but once you have it hooked up, you are just porting existing functionality in the app into these methods that gives the user an opportunity to override at the site level.Hooksets we should provide:
share_with_options(user, folder)
- takes the current user, and the folder object and returns a list of users thatuser
can share thefolder
with. it currently defaults toUser.objects.all()
in thefolder_share
view.folder_shared_message(request, user, folder)
- currently there is nomessages.success
message for successful share. there should be but it should be sent within this default hookset method.folder_unshared_message(request, user, folder)
- port themessages.success
message currently being sent when a user is removed from a folder share to this default hookset methoddocument_deleted_message(request, document)
folder_created_message(request, folder)
document_created_message(request, document)
can_share_folder(user, folder)
- the current default implementation is onFolder
object ascan_share(user)
method. move this logic into the hookset method and just call the hookset method from within this model method (e.g.return hookset.can_share_folder(user, folder=self)
)storage_color(user_storage)
- replace internals ofUserStorage.color
property with this hookset method so that these ranges and labels can be overridden at site level.All this should leave you with a hookset with the following signature:
The text was updated successfully, but these errors were encountered: