wuttaweb.views.base
¶
Base Logic for Views
- class wuttaweb.views.base.View(request, context=None)[source]¶
Base class for all class-based views.
Instances of this class (or rather, a subclass) are created by Pyramid when processing a request. They will have the following attributes:
- app¶
Reference to the app handler.
- config¶
Reference to the app config object.
- file_response(path, attachment=True, filename=None)[source]¶
Returns a generic file response for the given path.
- Parameters:
path – Path to a file on local disk; must be accessible by the web app.
attachment –
Whether the file should come down as an “attachment” instead of main payload.
The attachment behavior is the default here, and will cause the user to be prompted for where to save the file.
Set
attachment=False
in order to cause the browser to render the file as if it were the page being navigated to.filename – Optional filename to use for attachment behavior. This will be the “suggested filename” when user is prompted to save the download. If not specified, the filename is derived from
path
.
- Returns:
A
FileResponse
object with file content.
- forbidden()[source]¶
Convenience method, to raise a HTTP 403 Forbidden exception:
raise self.forbidden()
- json_response(context)[source]¶
Returns a JSON response with the given context data.
- Parameters:
context – Context data to be rendered as JSON.
- Returns:
A response with JSON content type.
- make_form(**kwargs)[source]¶
Make and return a new
Form
instance, per the givenkwargs
.This is the “base” factory which merely invokes the constructor.
- make_grid(**kwargs)[source]¶
Make and return a new
Grid
instance, per the givenkwargs
.This is the “base” factory which merely invokes the constructor.
- make_grid_action(key, **kwargs)[source]¶
Make and return a new
GridAction
instance, per the givenkey
andkwargs
.This is the “base” factory which merely invokes the constructor.
- notfound()[source]¶
Convenience method, to raise a HTTP 404 Not Found exception:
raise self.notfound()
- redirect(url, **kwargs)[source]¶
Convenience method to return a HTTP 302 response.
Note that this technically returns an “exception” - so in your code, you can either return that error, or raise it:
return self.redirect('/') # ..or raise self.redirect('/')
Which you should do will depend on context, but raising the error is always “safe” since Pyramid will handle that correctly no matter what.