From: Stephen Burrows Date: Thu, 12 May 2011 18:23:06 +0000 (-0400) Subject: Swapped references to specific AttributeMappers in for vague references to dictionary... X-Git-Tag: philo-0.9~12^2~15 X-Git-Url: http://git.ithinksw.org/philo.git/commitdiff_plain/8318347602085438ff700b9c1d6b83f351deccd7 Swapped references to specific AttributeMappers in for vague references to dictionary-like objects. Corrected links in a few places. Combined middleware docs with new node_view docs. --- diff --git a/docs/handling_requests.rst b/docs/handling_requests.rst new file mode 100644 index 0000000..940d541 --- /dev/null +++ b/docs/handling_requests.rst @@ -0,0 +1,10 @@ +Handling Requests +================= + +.. automodule:: philo.middleware + :members: + +.. automodule:: philo.views + + +.. autofunction:: node_view(request[, path=None, **kwargs]) diff --git a/docs/middleware.rst b/docs/middleware.rst deleted file mode 100644 index 4a5c05f..0000000 --- a/docs/middleware.rst +++ /dev/null @@ -1,5 +0,0 @@ -Middleware -========== - -.. automodule:: philo.middleware - :members: diff --git a/docs/models/entities.rst b/docs/models/entities.rst index 4127f56..c311d59 100644 --- a/docs/models/entities.rst +++ b/docs/models/entities.rst @@ -39,7 +39,7 @@ Entities .. autoclass:: Entity :members: - :exclude-members: attribute_set + :exclude-members: attribute_set, get_attribute_mapper .. autoclass:: TreeManager :members: @@ -47,7 +47,7 @@ Entities .. autoclass:: TreeEntity :show-inheritance: :members: - :exclude-members: attribute_set + :exclude-members: attribute_set, get_attribute_mapper .. attribute:: objects diff --git a/docs/models/miscellaneous.rst b/docs/models/miscellaneous.rst index ea13db2..80b654b 100644 --- a/docs/models/miscellaneous.rst +++ b/docs/models/miscellaneous.rst @@ -1,10 +1,8 @@ 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 diff --git a/docs/utilities.rst b/docs/utilities.rst index cb66b45..d1386b1 100644 --- a/docs/utilities.rst +++ b/docs/utilities.rst @@ -21,7 +21,7 @@ AttributeMappers :show-inheritance: LazyAttributeMappers -++++++++++++++++++++ +-------------------- .. autoclass:: LazyAttributeMapperMixin :members: diff --git a/philo/exceptions.py b/philo/exceptions.py index 9a8908e..9f908c0 100644 --- a/philo/exceptions.py +++ b/philo/exceptions.py @@ -6,15 +6,15 @@ MIDDLEWARE_NOT_CONFIGURED = ImproperlyConfigured("""Philo requires the RequestNo 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 diff --git a/philo/models/base.py b/philo/models/base.py index c361bdc..9533628 100644 --- a/philo/models/base.py +++ b/philo/models/base.py @@ -43,7 +43,7 @@ class Titled(models.Model): 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() @@ -310,7 +310,7 @@ class Entity(models.Model): 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:: @@ -492,7 +492,7 @@ class TreeEntity(Entity, TreeModel): 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:: diff --git a/philo/models/nodes.py b/philo/models/nodes.py index c29ac2a..f29545a 100644 --- a/philo/models/nodes.py +++ b/philo/models/nodes.py @@ -171,12 +171,12 @@ class View(Entity): """ 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): """ diff --git a/philo/utils/entities.py b/philo/utils/entities.py index f52620f..b911451 100644 --- a/philo/utils/entities.py +++ b/philo/utils/entities.py @@ -164,7 +164,12 @@ class LazyTreeAttributeMapper(LazyAttributeMapperMixin, TreeAttributeMapper): class PassthroughAttributeMapper(AttributeMapper): - """Given an iterable of :class:`Entities `, 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 `, 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) diff --git a/philo/views.py b/philo/views.py index 28740fd..d3054b9 100644 --- a/philo/views.py +++ b/philo/views.py @@ -8,6 +8,17 @@ from philo.exceptions import MIDDLEWARE_NOT_CONFIGURED @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