feat: pluggable profile tabs
Added ProfileTab class to represent a profile tab and made the profile page render the tabs specified in the hook `profile_tabs`. This allows plugging in new tabs in the profile page without makeing any changes to the community module.
This commit is contained in:
38
community/community/profile_tab.py
Normal file
38
community/community/profile_tab.py
Normal file
@@ -0,0 +1,38 @@
|
||||
"""
|
||||
The profile_tab module provides a pluggable way to add tabs to user
|
||||
profiles.
|
||||
|
||||
This is achieved by specifying the profile_tabs in the hooks.
|
||||
|
||||
profile_tabs = [
|
||||
'myapp.myapp.profile_tabs.SketchesTab'
|
||||
]
|
||||
|
||||
When a profile page is rendered, these classes specified in the
|
||||
profile_hooks are instanciated with the user as argument and used to
|
||||
render the tabs.
|
||||
"""
|
||||
|
||||
class ProfileTab:
|
||||
"""Base class for profile tabs.
|
||||
|
||||
Every subclass of ProfileTab must implement two methods:
|
||||
- get_title()
|
||||
- render()
|
||||
"""
|
||||
def __init__(self, user):
|
||||
self.user = user
|
||||
|
||||
def get_title(self):
|
||||
"""Returns the title of the tab.
|
||||
|
||||
Every subclass must implement this.
|
||||
"""
|
||||
raise NotImplementedError()
|
||||
|
||||
def render(self):
|
||||
"""Renders the contents of the tab as HTML.
|
||||
|
||||
Every subclass must implement this.
|
||||
"""
|
||||
raise NotImplementedError()
|
||||
Reference in New Issue
Block a user