wuttafarm.web.views.farmos.structure_types¶
View for farmOS structure types
- class wuttafarm.web.views.farmos.structure_types.StructureTypeView(request, context=None)[source]¶
Master view for Structure Types in farmOS.
- configure_grid(grid)[source]¶
Configure the grid for the
index()view.This is called by
make_model_grid().There is minimal default logic here; subclass should override as needed. The
gridparam will already be “complete” and ready to use as-is, but this method can further modify it based on request details etc.
- get_grid_data(columns=None, session=None)[source]¶
Returns the grid data for the
index()view.This is called by
make_model_grid(); in the resultingGridinstance, this becomesdata.Default logic will call
get_query()and if successful, return the list fromquery.all(). Otherwise returns an empty list. Subclass should override as needed.
- get_instance()[source]¶
This should return the appropriate model instance, based on the
matchdictof model keys.Normally this is called with no arguments, in which case the
pyramid:pyramid.request.Request.matchdictis used, and will return the “current” model instance based on the request (route/params).If a
matchdictis provided then that is used instead, to obtain the model keys. In the simple/common example of a “native” model in WuttaWeb, this would look like:keys = {'uuid': '38905440630d11ef9228743af49773a4'} obj = self.get_instance(matchdict=keys)
Although some models may have different, possibly composite key names to use instead. The specific keys this logic is expecting are the same as returned by
get_model_key().If this method is unable to locate the instance, it should raise a 404 error, i.e.
notfound().Default implementation of this method should work okay for views which define a
model_class. For other views however it will raiseNotImplementedError, so subclass may need to define.Warning
If you are defining this method for a subclass, please note this point regarding the 404 “not found” logic.
It is not enough to simply return this 404 response, you must explicitly raise the error. For instance:
def get_instance(self, **kwargs): # ..try to locate instance.. obj = self.locate_instance_somehow() if not obj: # NB. THIS MAY NOT WORK AS EXPECTED #return self.notfound() # nb. should always do this in get_instance() raise self.notfound()
This lets calling code not have to worry about whether or not this method might return
None. It can safely assume it will get back a model instance, or else a 404 will kick in and control flow goes elsewhere.