Op 7 nov. 2012, om 17:49 heeft Aaron Merriam het volgende geschreven: > I wanted to post and modified version of a gist posted earlier in this thread. > > https://gist.github.com/4032482 > > I originally implemented the original structure of having an `init` hook > which was called between setting request, args, and kwargs, but i quickly > found that I had a few situations where I needed to fully hijack the response > rather than just checking a permission or throwing an exception. > > I'm curious what others think of this.
I really like the idea of this implementation. I do like to see some examples associated with this feature, and I think that would be valuable for everyone :) I still think such init() or initial() feature would be beneficial for CBV's, and actually reduce complexity (cc Russell here) but the examples make the difference here :) For example, how would this be written without a init method? class PhotoListView(TabbedListView): """ Contents of an photo album; a list of photo's. """ model = Photo template_name = "photoalbum_album.html" permission_class = permissions.PhotoAlbumViewPermission def init(self): super(PhotoListView, self).init() # runs permission checks self.photoalbum = get_object_or_404(PhotoAlbum, pk=self.kwargs['pk']) # parent object that filters the list def get_queryset(self): return super(PhotoListView, self).get_queryset().in_album(self.photoalbum) def get_context_data(self, **kwargs): context = super(PhotoListView, self).get_context_data(**kwargs) context['photoalbum'] = self.photoalbum context['can_delete'] = self.is_authorized_for(PhotoDeleteView) return context Off course you can, but I'd like to initiate that challenge to get a good view of the complexity trade-offs here. Greetings, Diederik -- You received this message because you are subscribed to the Google Groups "Django developers" group. To post to this group, send email to django-developers@googlegroups.com. To unsubscribe from this group, send email to django-developers+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-developers?hl=en.