context = super(PluggableDetailView, self).get_context_data(**kwargs)
for plugin in self.__class__.__bases__:
if hasattr(plugin, 'get_extra_context') and callable(plugin.get_extra_context):
context.update(plugin.get_extra_context(self, **kwargs))
return context
def post(self, *args, **kwargs):
for plugin in self.__class__.__bases__:
if hasattr(plugin, 'handle_post_request') and callable(plugin.handle_post_request):
plugin.handle_post_request(self, *args, **kwargs)
now I can add plug-ins and add two methods
get_extra_context shall return a dict of extra context data merged together with the default context.
handle_post_request shall extract the plug-in specific post data and update the database or whatever else it must do.
The DetailView of the main app then inherits from PluggableDetailView, additional plug-ins can be mixed in, but no extra code has to be written to extend the context or to handle post requests.
class MainAppDetailView(PluggableDetailView, PluginAMixin, PluginBMixin):
pass
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/r_ZDUciOi6IJ.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
0 comments:
Post a Comment