Skip to content

Commit

Permalink
[#3237] more views and logic layer discussion
Browse files Browse the repository at this point in the history
  • Loading branch information
wardi committed Sep 9, 2016
1 parent 130ab3e commit 29be748
Showing 1 changed file with 30 additions and 8 deletions.
38 changes: 30 additions & 8 deletions doc/contributing/architecture.rst
Expand Up @@ -27,21 +27,29 @@ Default routes are defined in ``ckan.config.routing`` and extended with the
Views
-----

Views process requests and build a response by rendering Jinja2 templates.
Views process requests by reading and updating data with action
function and return a response by rendering Jinja2 templates.
CKAN views are defined in ``ckan.controllers`` and templates in
``ckan.templates``.

Plugins define new views by adding or updating routes. See
:doc:`../theming/index` for adding templates from a plugin, and
:ref:`custom template helper functions`
Views and templates may use ``logic.check_access`` or
:func:`ckan.lib.helpers.check_access` to hide links or render
helpful errors but action functions, not views, are responsible for
actually enforcing permissions checking.

Plugins define new views by adding or updating routes. For adding
templates or helper functions from a plugin see
:doc:`../theming/index` and
:ref:`custom template helper functions`.


Template helper functions
#########################

Template helpers are used for code that is reused frequently or too
complicated to be included in the templates themselves. Template helpers
should never perform expensive queries or update data.
Template helper functions are used for code that is reused frequently or
code that is too complicated to be included in the templates themselves.

Template helpers should never perform expensive queries or update data.

``ckan.lib.helpers`` contains helper functions that can be used from
``ckan.controllers`` or from templates. When developing for ckan core, only use
Expand All @@ -56,6 +64,7 @@ to get, create, update or delete an object from CKAN's model it should do so by
calling a function from the ``ckan.logic.action`` package, and *not* by
accessing ``ckan.model`` directly.


Use ``get_action()``
####################

Expand All @@ -69,7 +78,7 @@ Instead of ::

ckan.logic.action.get.group_activity_list(...)

Views and templates may check authorization to avoid rendering
Views and templates may check authorization to avoid rendering

Don't pass ORM objects to templates
###################################
Expand All @@ -87,6 +96,19 @@ errors that cause 500 Server Errors and can be difficult to debug.
Logic
-----

Logic includes action functions, auth functions, background tasks
and business logic.

Action functions have a uniform interface accepting a dictionary of simple
strings lists, dictionaries or files (wrapped in a ``cgi.FieldStorage``
objects). They return simple dictionaries or raise one of a small number of
exceptions including ``ckan.logic.NotAuthorized``, ``ckan.logic.NotFound``
and ``ckan.logic.ValidationError``.

Plugins override action functions with the
:class:`ckan.plugins.interfaces.IActions` interface and auth functions
with the :class:`ckan.plugins.interfaces.IAuthFunctions` interface.


Action functions are exposed in the API
#######################################
Expand Down

0 comments on commit 29be748

Please sign in to comment.