Added structure for model documentation, as well as writing the documentation for...
[philo.git] / docs / models / nodes-and-views.rst
1 Nodes and Views: Building Website structure
2 ===========================================
3 .. currentmodule:: philo.models
4 .. class:: Node
5
6    .. attribute:: view
7
8       :class:`GenericForeignKey` to a non-abstract subclass of :class:`View`
9
10    .. attribute:: accepts_subpath
11
12       A property shortcut for :attr:`self.view.accepts_subpath <View.accepts_subpath>`
13
14    .. method:: render_to_response(request[, extra_context=None])
15
16       This is a shortcut method for :meth:`View.render_to_response`
17
18    .. method:: get_absolute_url()
19
20       As long as :mod:`philo.urls` is included somewhere in the urlpatterns, this will return the URL of this node. The returned value will always start and end with a slash.
21
22 .. class:: View
23
24    :class:`!View` is an abstract model that represents an item which can be "rendered", either in response to an :class:`HttpRequest` or as a standalone.
25
26    .. attribute:: accepts_subpath
27
28       Defines whether this View class can handle subpaths.
29
30    .. attribute:: nodes
31
32       A generic relation back to nodes.
33
34    .. method:: get_subpath(obj)
35
36       If the view :attr:`accepts subpaths <.accepts_subpath>`, try to find a reversal for the given object using ``self`` as the urlconf. This method calls :meth:`~.get_reverse_params` with ``obj`` as the argument to find out the reversing parameters for that object.
37
38    .. method:: get_reverse_params(obj)
39
40       This method should return a ``view_name``, ``args``, ``kwargs`` tuple suitable for reversing a url for the given ``obj`` using ``self`` as the urlconf.
41
42    .. method:: attributes_with_node(node)
43
44       Returns a :class:`QuerySetMapper` using the :class:`node <Node>`'s attributes as a passthrough.
45
46    .. method:: render_to_response(request[, extra_context=None])
47
48       Renders the :class:`View` as an :class:`HttpResponse`. This will raise :const:`philo.exceptions.MIDDLEWARE_NOT_CONFIGURED` if the `request` doesn't have an attached :class:`Node`. This can happen if :class:`philo.middleware.RequestNodeMiddleware` is not in :setting:`settings.MIDDLEWARE_CLASSES` or if it is not functioning correctly.
49
50       :meth:`!render_to_response` will send the :obj:`view_about_to_render <philo.signals.view_about_to_render>` signal, then call :meth:`actually_render_to_response`, and finally send the :obj:`view_finished_rendering <philo.signals.view_finished_rendering>` signal before returning the ``response``.
51
52    .. method:: actually_render_to_response(request[, extra_context=None])
53
54       Concrete subclasses must override this method to provide the business logic for turning a ``request`` and ``extra_context`` into an :class:`HttpResponse`.