wuttafarm.web.views.farmos.users¶
View for farmOS Users
- class wuttafarm.web.views.farmos.users.UserView(request, context=None)[source]¶
Master view for Farm Animals
- configure_form(form)[source]¶
Configure the given model form, as needed.
This is called by
make_model_form()- for multiple CRUD views (create, view, edit, delete, possibly others).The default logic here does just one thing: when “editing” (i.e. in
edit()view) then all fields which are part of themodel_keywill be marked viaset_readonly()so the user cannot change primary key values for a record.Subclass may override as needed. The
formparam will already be “complete” and ready to use as-is, but this method can further modify it based on request details etc.
- 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.
- get_instance_title(user)[source]¶
Return the human-friendly “title” for the instance, to be used in the page title when viewing etc.
Default logic returns the value from
str(instance); subclass may override if needed.
- get_xref_buttons(user)[source]¶
Should return a list of “cross-reference” buttons to be shown when viewing the given object.
Default logic always returns empty list; subclass can override as needed.
If applicable, this method should do its own permission checks and only include the buttons current user should be allowed to see/use.
See also
make_button()- example:def get_xref_buttons(self, product): buttons = [] if self.request.has_perm('external_products.view'): url = self.request.route_url('external_products.view', id=product.external_id) buttons.append(self.make_button("View External", url=url)) return buttons