python - Partially overriding view config inherit from parent class in Pyramid -


i using class based views cut down amount of repeating oneself in similar view methods. pyramid @view_config allows little boilerplate. example when have same view context changes:

class baseedit(formview):      @view_config(context=resource, name="edit", renderer="crud/edit.html", permission='edit')     def edit(self):         pass  class useredit(baseedit):      @view_config(context=userresource, name="edit", renderer="crud/edit.html", permission='edit')     def edit(self):         pass                      

however, possible reduce boilerplate further? e.g. don't want re-declare template file, because doesn't change. want change @view_config parameters. there way this:

class baseedit(formview):      @view_config(context=resource, name="edit", renderer="crud/edit.html", permission='edit')     def edit(self):         pass  class useredit(baseedit):      @view_override(context=userresource)     def edit(self):         pass         

any other suggested patterns make can vary parameters, namely context, generic views?

the following does not work:

@view_defaults(context=userresource, template="foobar.html") class useredit(baseedit):     pass 

in case still uses orignal @view_config , ignores overridden template.

or:

@view_defaults(context=userresource) class useredit(baseedit):      def edit(self):         # never called         return "xx" 

as current state of art not cut it, went ahead , created little helper function , package @view_overrides:


Comments

Popular posts from this blog

python - TypeError: start must be a integer -

c# - DevExpress RepositoryItemComboBox BackColor property ignored -

django - Creating multiple model instances in DRF3 -