--- /dev/null
+Handling Requests
+=================
+
+.. automodule:: philo.middleware
+ :members:
+
+.. automodule:: philo.views
+
+
+.. autofunction:: node_view(request[, path=None, **kwargs])
+++ /dev/null
-Middleware
-==========
-
-.. automodule:: philo.middleware
- :members:
.. autoclass:: Entity
:members:
- :exclude-members: attribute_set
+ :exclude-members: attribute_set, get_attribute_mapper
.. autoclass:: TreeManager
:members:
.. autoclass:: TreeEntity
:show-inheritance:
:members:
- :exclude-members: attribute_set
+ :exclude-members: attribute_set, get_attribute_mapper
.. attribute:: objects
Miscellaneous Models
=============================
-.. currentmodule:: philo.models.nodes
.. autoclass:: philo.models.nodes.TargetURLModel
:members:
:exclude-members: get_target_url
-.. currentmodule:: philo.models.base
.. autoclass:: philo.models.base.Tag
:members:
\ No newline at end of file
:show-inheritance:
LazyAttributeMappers
-++++++++++++++++++++
+--------------------
.. autoclass:: LazyAttributeMapperMixin
:members:
class ViewDoesNotProvideSubpaths(Exception):
- """Raised by :meth:`View.reverse` when the View does not provide subpaths (the default)."""
+ """Raised by :meth:`.View.reverse` when the :class:`.View` does not provide subpaths (the default)."""
silent_variable_failure = True
class ViewCanNotProvideSubpath(Exception):
- """Raised by :meth:`View.reverse` when the :class:`View` can not provide a subpath for the supplied arguments."""
+ """Raised by :meth:`.View.reverse` when the :class:`.View` can not provide a subpath for the supplied arguments."""
silent_variable_failure = True
class AncestorDoesNotExist(Exception):
- """Raised by :meth:`TreeModel.get_path` if the root instance is not an ancestor of the current instance."""
+ """Raised by :meth:`.TreeEntity.get_path` if the root instance is not an ancestor of the current instance."""
pass
\ No newline at end of file
abstract = True
-#: An instance of :class:`ContentTypeRegistryLimiter` which is used to track the content types which can be related to by :class:`ForeignKeyValue`\ s and :class:`ManyToManyValue`\ s.
+#: An instance of :class:`.ContentTypeRegistryLimiter` which is used to track the content types which can be related to by :class:`ForeignKeyValue`\ s and :class:`ManyToManyValue`\ s.
value_content_type_limiter = ContentTypeRegistryLimiter()
def get_attribute_mapper(self, mapper=AttributeMapper):
"""
- Returns a dictionary-like object which can be used to retrieve related :class:`Attribute`\ s' values directly.
+ Returns an :class:`.AttributeMapper` which can be used to retrieve related :class:`Attribute`\ s' values directly.
Example::
def get_attribute_mapper(self, mapper=None):
"""
- Returns a dictionary-like object which can be used to retrieve related :class:`Attribute`\ s' values directly. If an attribute with a given key is not related to the :class:`Entity`, then the object will check the parent's attributes.
+ Returns a :class:`.TreeAttributeMapper` or :class:`.AttributeMapper` which can be used to retrieve related :class:`Attribute`\ s' values directly. If an :class:`Attribute` with a given key is not related to the :class:`Entity`, then the mapper will check the parent's attributes.
Example::
"""
raise NotImplementedError("View subclasses must implement get_reverse_params to support subpaths.")
- def attributes_with_node(self, node):
+ def attributes_with_node(self, node, mapper=LazyPassthroughAttributeMapper):
"""
- Returns a dictionary-like object which can be used to directly retrieve the values of :class:`Attribute`\ s related to the :class:`View`, falling back on similar object which retrieves the values of the passed-in node and its ancestors.
+ Returns a :class:`LazyPassthroughAttributeMapper` which can be used to directly retrieve the values of :class:`Attribute`\ s related to the :class:`View`, falling back on the :class:`Attribute`\ s of the passed-in :class:`Node` and its ancestors.
"""
- return LazyPassthroughAttributeMapper((self, node))
+ return mapper((self, node))
def render_to_response(self, request, extra_context=None):
"""
class PassthroughAttributeMapper(AttributeMapper):
- """Given an iterable of :class:`Entities <philo.models.base.Entity>`, this mapper will fetch an :class:`AttributeMapper` for each one. Lookups will return the value from the first :class:`AttributeMapper` which has an entry for a given key."""
+ """
+ Given an iterable of :class:`Entities <philo.models.base.Entity>`, this mapper will fetch an :class:`AttributeMapper` for each one. Lookups will return the value from the first :class:`AttributeMapper` which has an entry for a given key. Assignments will be made to the first :class:`.Entity` in the iterable.
+
+ :param entities: An iterable of :class:`.Entity` subclass instances.
+
+ """
def __init__(self, entities):
self._attributes = [e.attributes for e in entities]
super(PassthroughAttributeMapper, self).__init__(self._attributes[0].entity)
@vary_on_headers('Accept')
def node_view(request, path=None, **kwargs):
+ """
+ :func:`node_view` handles incoming requests by checking to make sure that:
+
+ - the request has an attached :class:`.Node`.
+ - the attached :class:`~philo.models.nodes.Node` handles any remaining path beyond its location.
+
+ If these conditions are not met, then :func:`node_view` will either raise :exc:`Http404` or, if it seems like the address was mistyped (for example missing a trailing slash), return an :class:`HttpResponseRedirect` to the correct address.
+
+ Otherwise, :func:`node_view` will call the :class:`.Node`'s :meth:`~.Node.render_to_response` method, passing ``kwargs`` in as the ``extra_context``.
+
+ """
if "philo.middleware.RequestNodeMiddleware" not in settings.MIDDLEWARE_CLASSES:
raise MIDDLEWARE_NOT_CONFIGURED