Commits

Andy Mikhailenko committed 7473e45

Remove unnecessary directory level in the package

Comments (0)

Files changed (16)

+Changelog before extracting into separate repository:
+
+changeset:   44:890ae3bd4d1b
+user:        Andy Mikhailenko <neithere@gmail.com>
+date:        Thu Oct 30 03:47:19 2008 +0500
+summary:     navigation app: Fix bug introduced in previous revision. (Middleware name must be the full string, not a substring: it is looked up in a list)
+
+changeset:   43:d4bef747556f
+user:        Andy Mikhailenko <neithere@gmail.com>
+date:        Tue Oct 28 11:46:49 2008 +0500
+summary:     navigation app: Insert dummy crumbs into the nav. path to avoid breaking design with orphans (of course, the links won't work anyway).
+
+changeset:   42:825754d5661d
+user:        Andy Mikhailenko <neithere@gmail.com>
+date:        Tue Oct 28 09:07:59 2008 +0500
+summary:     navigation app: Replace AssertionError with CannotResolveCrumb exception. This exception does not propagate to client code and, thus, does not break it.
+
+changeset:   9:af57055830ad
+user:        Andy Mikhailenko <neithere@gmail.com>
+date:        Mon Aug 04 03:12:21 2008 +0600
+summary:     Move navigation app settings into code itself to simplify things and avoid portability issues.
+
+changeset:   7:20692943e906
+user:        Andy Mikhailenko <neithere@gmail.com>
+date:        Sun Aug 03 19:19:00 2008 +0100
+summary:     Remove modules deprecated by the new navigation app
+
+changeset:   6:b366a406b9fc
+parent:      4:4e613e6cd0ca
+user:        Andy Mikhailenko <neithere@gmail.com>
+date:        Mon Aug 04 00:07:00 2008 +0600
+summary:     Add navigation app.
+		   GNU LESSER GENERAL PUBLIC LICENSE
+                       Version 3, 29 June 2007
+
+ Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+
+  This version of the GNU Lesser General Public License incorporates
+the terms and conditions of version 3 of the GNU General Public
+License, supplemented by the additional permissions listed below.
+
+  0. Additional Definitions. 
+
+  As used herein, "this License" refers to version 3 of the GNU Lesser
+General Public License, and the "GNU GPL" refers to version 3 of the GNU
+General Public License.
+
+  "The Library" refers to a covered work governed by this License,
+other than an Application or a Combined Work as defined below.
+
+  An "Application" is any work that makes use of an interface provided
+by the Library, but which is not otherwise based on the Library.
+Defining a subclass of a class defined by the Library is deemed a mode
+of using an interface provided by the Library.
+
+  A "Combined Work" is a work produced by combining or linking an
+Application with the Library.  The particular version of the Library
+with which the Combined Work was made is also called the "Linked
+Version".
+
+  The "Minimal Corresponding Source" for a Combined Work means the
+Corresponding Source for the Combined Work, excluding any source code
+for portions of the Combined Work that, considered in isolation, are
+based on the Application, and not on the Linked Version.
+
+  The "Corresponding Application Code" for a Combined Work means the
+object code and/or source code for the Application, including any data
+and utility programs needed for reproducing the Combined Work from the
+Application, but excluding the System Libraries of the Combined Work.
+
+  1. Exception to Section 3 of the GNU GPL.
+
+  You may convey a covered work under sections 3 and 4 of this License
+without being bound by section 3 of the GNU GPL.
+
+  2. Conveying Modified Versions.
+
+  If you modify a copy of the Library, and, in your modifications, a
+facility refers to a function or data to be supplied by an Application
+that uses the facility (other than as an argument passed when the
+facility is invoked), then you may convey a copy of the modified
+version:
+
+   a) under this License, provided that you make a good faith effort to
+   ensure that, in the event an Application does not supply the
+   function or data, the facility still operates, and performs
+   whatever part of its purpose remains meaningful, or
+
+   b) under the GNU GPL, with none of the additional permissions of
+   this License applicable to that copy.
+
+  3. Object Code Incorporating Material from Library Header Files.
+
+  The object code form of an Application may incorporate material from
+a header file that is part of the Library.  You may convey such object
+code under terms of your choice, provided that, if the incorporated
+material is not limited to numerical parameters, data structure
+layouts and accessors, or small macros, inline functions and templates
+(ten or fewer lines in length), you do both of the following:
+
+   a) Give prominent notice with each copy of the object code that the
+   Library is used in it and that the Library and its use are
+   covered by this License.
+
+   b) Accompany the object code with a copy of the GNU GPL and this license
+   document.
+
+  4. Combined Works.
+
+  You may convey a Combined Work under terms of your choice that,
+taken together, effectively do not restrict modification of the
+portions of the Library contained in the Combined Work and reverse
+engineering for debugging such modifications, if you also do each of
+the following:
+
+   a) Give prominent notice with each copy of the Combined Work that
+   the Library is used in it and that the Library and its use are
+   covered by this License.
+
+   b) Accompany the Combined Work with a copy of the GNU GPL and this license
+   document.
+
+   c) For a Combined Work that displays copyright notices during
+   execution, include the copyright notice for the Library among
+   these notices, as well as a reference directing the user to the
+   copies of the GNU GPL and this license document.
+
+   d) Do one of the following:
+
+       0) Convey the Minimal Corresponding Source under the terms of this
+       License, and the Corresponding Application Code in a form
+       suitable for, and under terms that permit, the user to
+       recombine or relink the Application with a modified version of
+       the Linked Version to produce a modified Combined Work, in the
+       manner specified by section 6 of the GNU GPL for conveying
+       Corresponding Source.
+
+       1) Use a suitable shared library mechanism for linking with the
+       Library.  A suitable mechanism is one that (a) uses at run time
+       a copy of the Library already present on the user's computer
+       system, and (b) will operate properly with a modified version
+       of the Library that is interface-compatible with the Linked
+       Version. 
+
+   e) Provide Installation Information, but only if you would otherwise
+   be required to provide such information under section 6 of the
+   GNU GPL, and only to the extent that such information is
+   necessary to install and execute a modified version of the
+   Combined Work produced by recombining or relinking the
+   Application with a modified version of the Linked Version. (If
+   you use option 4d0, the Installation Information must accompany
+   the Minimal Corresponding Source and Corresponding Application
+   Code. If you use option 4d1, you must provide the Installation
+   Information in the manner specified by section 6 of the GNU GPL
+   for conveying Corresponding Source.)
+
+  5. Combined Libraries.
+
+  You may place library facilities that are a work based on the
+Library side by side in a single library together with other library
+facilities that are not Applications and are not covered by this
+License, and convey such a combined library under terms of your
+choice, if you do both of the following:
+
+   a) Accompany the combined library with a copy of the same work based
+   on the Library, uncombined with any other library facilities,
+   conveyed under the terms of this License.
+
+   b) Give prominent notice with the combined library that part of it
+   is a work based on the Library, and explaining where to find the
+   accompanying uncombined form of the same work.
+
+  6. Revised Versions of the GNU Lesser General Public License.
+
+  The Free Software Foundation may publish revised and/or new versions
+of the GNU Lesser General Public License from time to time. Such new
+versions will be similar in spirit to the present version, but may
+differ in detail to address new problems or concerns.
+
+  Each version is given a distinguishing version number. If the
+Library as you received it specifies that a certain numbered version
+of the GNU Lesser General Public License "or any later version"
+applies to it, you have the option of following the terms and
+conditions either of that published version or of any later version
+published by the Free Software Foundation. If the Library as you
+received it does not specify a version number of the GNU Lesser
+General Public License, you may choose any version of the GNU Lesser
+General Public License ever published by the Free Software Foundation.
+
+  If the Library as you received it specifies that a proxy can decide
+whether future versions of the GNU Lesser General Public License shall
+apply, that proxy's public statement of acceptance of any version is
+permanent authorization for you to choose that version for the
+Library.
+Run ``setup.py install'' and configure your project settings.py.
+Django Navigation is a breadcrumbs navigation application for Django Web
+Framework. Initially written by Andy Mikhailenko in 2008.
+See the file AUTHORS for a complete authors list of this application.
+
+Please feel free to submit patches, report bugs or request features:
+
+    http://bitbucket.org/neithere/django-navigation/
+
+Django Navigation is free software; you can redistribute it and/or
+modify it under the terms of the GNU Lesser General Public License as
+published by the Free Software Foundation; either version 3 of the
+License, or (at your option) any later version.
+
+Django Navigation is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+Lesser General Public License for more details.
+
+You should have received a copy of the GNU Lesser General Public
+License along with this program; see the file COPYING.LESSER. If not,
+see <http://www.gnu.org/licenses/>.

django-navigation/CHANGELOG

-Changelog before extracting into separate repository:
-
-changeset:   44:890ae3bd4d1b
-user:        Andy Mikhailenko <neithere@gmail.com>
-date:        Thu Oct 30 03:47:19 2008 +0500
-summary:     navigation app: Fix bug introduced in previous revision. (Middleware name must be the full string, not a substring: it is looked up in a list)
-
-changeset:   43:d4bef747556f
-user:        Andy Mikhailenko <neithere@gmail.com>
-date:        Tue Oct 28 11:46:49 2008 +0500
-summary:     navigation app: Insert dummy crumbs into the nav. path to avoid breaking design with orphans (of course, the links won't work anyway).
-
-changeset:   42:825754d5661d
-user:        Andy Mikhailenko <neithere@gmail.com>
-date:        Tue Oct 28 09:07:59 2008 +0500
-summary:     navigation app: Replace AssertionError with CannotResolveCrumb exception. This exception does not propagate to client code and, thus, does not break it.
-
-changeset:   9:af57055830ad
-user:        Andy Mikhailenko <neithere@gmail.com>
-date:        Mon Aug 04 03:12:21 2008 +0600
-summary:     Move navigation app settings into code itself to simplify things and avoid portability issues.
-
-changeset:   7:20692943e906
-user:        Andy Mikhailenko <neithere@gmail.com>
-date:        Sun Aug 03 19:19:00 2008 +0100
-summary:     Remove modules deprecated by the new navigation app
-
-changeset:   6:b366a406b9fc
-parent:      4:4e613e6cd0ca
-user:        Andy Mikhailenko <neithere@gmail.com>
-date:        Mon Aug 04 00:07:00 2008 +0600
-summary:     Add navigation app.

django-navigation/COPYING.LESSER

-		   GNU LESSER GENERAL PUBLIC LICENSE
-                       Version 3, 29 June 2007
-
- Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
- Everyone is permitted to copy and distribute verbatim copies
- of this license document, but changing it is not allowed.
-
-
-  This version of the GNU Lesser General Public License incorporates
-the terms and conditions of version 3 of the GNU General Public
-License, supplemented by the additional permissions listed below.
-
-  0. Additional Definitions. 
-
-  As used herein, "this License" refers to version 3 of the GNU Lesser
-General Public License, and the "GNU GPL" refers to version 3 of the GNU
-General Public License.
-
-  "The Library" refers to a covered work governed by this License,
-other than an Application or a Combined Work as defined below.
-
-  An "Application" is any work that makes use of an interface provided
-by the Library, but which is not otherwise based on the Library.
-Defining a subclass of a class defined by the Library is deemed a mode
-of using an interface provided by the Library.
-
-  A "Combined Work" is a work produced by combining or linking an
-Application with the Library.  The particular version of the Library
-with which the Combined Work was made is also called the "Linked
-Version".
-
-  The "Minimal Corresponding Source" for a Combined Work means the
-Corresponding Source for the Combined Work, excluding any source code
-for portions of the Combined Work that, considered in isolation, are
-based on the Application, and not on the Linked Version.
-
-  The "Corresponding Application Code" for a Combined Work means the
-object code and/or source code for the Application, including any data
-and utility programs needed for reproducing the Combined Work from the
-Application, but excluding the System Libraries of the Combined Work.
-
-  1. Exception to Section 3 of the GNU GPL.
-
-  You may convey a covered work under sections 3 and 4 of this License
-without being bound by section 3 of the GNU GPL.
-
-  2. Conveying Modified Versions.
-
-  If you modify a copy of the Library, and, in your modifications, a
-facility refers to a function or data to be supplied by an Application
-that uses the facility (other than as an argument passed when the
-facility is invoked), then you may convey a copy of the modified
-version:
-
-   a) under this License, provided that you make a good faith effort to
-   ensure that, in the event an Application does not supply the
-   function or data, the facility still operates, and performs
-   whatever part of its purpose remains meaningful, or
-
-   b) under the GNU GPL, with none of the additional permissions of
-   this License applicable to that copy.
-
-  3. Object Code Incorporating Material from Library Header Files.
-
-  The object code form of an Application may incorporate material from
-a header file that is part of the Library.  You may convey such object
-code under terms of your choice, provided that, if the incorporated
-material is not limited to numerical parameters, data structure
-layouts and accessors, or small macros, inline functions and templates
-(ten or fewer lines in length), you do both of the following:
-
-   a) Give prominent notice with each copy of the object code that the
-   Library is used in it and that the Library and its use are
-   covered by this License.
-
-   b) Accompany the object code with a copy of the GNU GPL and this license
-   document.
-
-  4. Combined Works.
-
-  You may convey a Combined Work under terms of your choice that,
-taken together, effectively do not restrict modification of the
-portions of the Library contained in the Combined Work and reverse
-engineering for debugging such modifications, if you also do each of
-the following:
-
-   a) Give prominent notice with each copy of the Combined Work that
-   the Library is used in it and that the Library and its use are
-   covered by this License.
-
-   b) Accompany the Combined Work with a copy of the GNU GPL and this license
-   document.
-
-   c) For a Combined Work that displays copyright notices during
-   execution, include the copyright notice for the Library among
-   these notices, as well as a reference directing the user to the
-   copies of the GNU GPL and this license document.
-
-   d) Do one of the following:
-
-       0) Convey the Minimal Corresponding Source under the terms of this
-       License, and the Corresponding Application Code in a form
-       suitable for, and under terms that permit, the user to
-       recombine or relink the Application with a modified version of
-       the Linked Version to produce a modified Combined Work, in the
-       manner specified by section 6 of the GNU GPL for conveying
-       Corresponding Source.
-
-       1) Use a suitable shared library mechanism for linking with the
-       Library.  A suitable mechanism is one that (a) uses at run time
-       a copy of the Library already present on the user's computer
-       system, and (b) will operate properly with a modified version
-       of the Library that is interface-compatible with the Linked
-       Version. 
-
-   e) Provide Installation Information, but only if you would otherwise
-   be required to provide such information under section 6 of the
-   GNU GPL, and only to the extent that such information is
-   necessary to install and execute a modified version of the
-   Combined Work produced by recombining or relinking the
-   Application with a modified version of the Linked Version. (If
-   you use option 4d0, the Installation Information must accompany
-   the Minimal Corresponding Source and Corresponding Application
-   Code. If you use option 4d1, you must provide the Installation
-   Information in the manner specified by section 6 of the GNU GPL
-   for conveying Corresponding Source.)
-
-  5. Combined Libraries.
-
-  You may place library facilities that are a work based on the
-Library side by side in a single library together with other library
-facilities that are not Applications and are not covered by this
-License, and convey such a combined library under terms of your
-choice, if you do both of the following:
-
-   a) Accompany the combined library with a copy of the same work based
-   on the Library, uncombined with any other library facilities,
-   conveyed under the terms of this License.
-
-   b) Give prominent notice with the combined library that part of it
-   is a work based on the Library, and explaining where to find the
-   accompanying uncombined form of the same work.
-
-  6. Revised Versions of the GNU Lesser General Public License.
-
-  The Free Software Foundation may publish revised and/or new versions
-of the GNU Lesser General Public License from time to time. Such new
-versions will be similar in spirit to the present version, but may
-differ in detail to address new problems or concerns.
-
-  Each version is given a distinguishing version number. If the
-Library as you received it specifies that a certain numbered version
-of the GNU Lesser General Public License "or any later version"
-applies to it, you have the option of following the terms and
-conditions either of that published version or of any later version
-published by the Free Software Foundation. If the Library as you
-received it does not specify a version number of the GNU Lesser
-General Public License, you may choose any version of the GNU Lesser
-General Public License ever published by the Free Software Foundation.
-
-  If the Library as you received it specifies that a proxy can decide
-whether future versions of the GNU Lesser General Public License shall
-apply, that proxy's public statement of acceptance of any version is
-permanent authorization for you to choose that version for the
-Library.

django-navigation/INSTALL

-Run ``setup.py install'' and configure your project settings.py.

django-navigation/README

-Django Navigation is a breadcrumbs navigation application for Django Web
-Framework. Initially written by Andy Mikhailenko in 2008.
-See the file AUTHORS for a complete authors list of this application.
-
-Please feel free to submit patches, report bugs or request features:
-
-    http://bitbucket.org/neithere/django-navigation/
-
-Django Navigation is free software; you can redistribute it and/or
-modify it under the terms of the GNU Lesser General Public License as
-published by the Free Software Foundation; either version 3 of the
-License, or (at your option) any later version.
-
-Django Navigation is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-Lesser General Public License for more details.
-
-You should have received a copy of the GNU Lesser General Public
-License along with this program; see the file COPYING.LESSER. If not,
-see <http://www.gnu.org/licenses/>.

django-navigation/navigation/__init__.py

-# -*- coding: utf-8 -*-
-#
-#  Copyright (c) 2008 Andy Mikhailenko and contributors
-#
-#  Django Navigation is free software under terms of the GNU Lesser
-#  General Public License version 3 (LGPLv3) as published by the Free
-#  Software Foundation. See the file README for copying conditions.
-#
-
-" A breadcrumbs navigation application for Django framework. "
-
-VERSION = (0, 1, 'alpha')
-
-def get_version():
-    " Returns the version as a human-format string. "
-    v = '.'.join([str(i) for i in VERSION[:-1]])
-    return '%s-%s' % (v, VERSION[-1])
-
-__author__  = 'Andy Mikhailenko'
-__license__ = 'GNU Lesser General Public License (GPL), Version 3'
-__url__     = 'http://bitbucket.org/neithere/django-navigation/'
-__version__ = get_version()

django-navigation/navigation/templatetags/__init__.py

Empty file removed.

django-navigation/navigation/templatetags/navigation.py

-# -*- coding: utf-8 -*-
-
-""" Universal breadcrumbs navigation for Django.
-
-FlatPages trail by:
-jca <http://djangosnippets.org/snippets/519/>
-
-Original idea and implementation of universal breadcrumbs for custom views by:
-Thomas Guettler <http://groups.google.com/group/django-users/browse_thread/thread/f40f59e39cef59c4>
-
-Unified templated breadcrumbs for both FlatPages and custom views support by:
-Andy Mikhailenko <http://neithere.net>, <neithere@gmail.com>
-"""
-
-# Python
-from urlparse import urljoin
-
-# Django
-from django import template, http
-from django.conf import settings
-from django.core.urlresolvers import reverse, RegexURLResolver
-from django.utils.safestring import mark_safe
-from django.utils.html import conditional_escape
-from django.utils.http import urlquote
-from django.utils.translation import ugettext as _
-from django.template.loader import render_to_string
-
-# A list of site sections' URLs in desired order, i.e.:
-#   NAVIGATION_SECTIONS = ('/about/', '/news/')
-SECTIONS = getattr(settings, 'NAVIGATION_SECTIONS', ())
-
-# Check if FlatPages middleware is connected and, if yes, auto-enable them
-if 'django.contrib.flatpages.middleware.FlatpageFallbackMiddleware' in settings.MIDDLEWARE_CLASSES:
-	from django.contrib.flatpages.models import FlatPage
-	ENABLE_FLATPAGES = True
-else:
-	ENABLE_FLATPAGES = False
-
-register = template.Library()
-
-class Crumb:
-	""" A 'crumb' is just a navigation item """
-	def __init__(self, url, title, is_current=False, is_dummy=False):
-		self.url        = url
-		self.title      = title
-		self.is_current = is_current
-		self.is_dummy   = is_dummy
-	__unicode__ = lambda self: self.url
-
-@register.filter(name='get_navigation')
-def get_navigation(request):
-	# Prepare sections (horizontal cut, base level)
-	
-	sections = []
-	for section_url in SECTIONS:
-		crumb = find_crumb(section_url, request)
-		if crumb:
-			if section_url == '/':
-				if request.path == section_url:
-					crumb.is_current = True
-			else:
-				if request.path.startswith(section_url):
-					crumb.is_current = True
-			sections.append(crumb)
-
-	# Prepare trail (vertical cut, excluding base level)
-	
-	trail = []
-	url = request.path
-	while url:
-		if url == '/'  or  url in SECTIONS:
-			break
-		crumb = find_crumb(url, request)
-		if not crumb:
-			break
-		trail.append(crumb)
-
-		# go one level up
-		url = urljoin(url, '..')
-		
-	trail.reverse()
-
-	return mark_safe(render_to_string('navigation.html', dict(sections=sections,trail=trail)))
-
-	"""
-	# defined in settings, crumbified here
-	sections = (
-		Crumb('/about/', u'О нас'),
-		Crumb('/news/', u'Новости', is_current=True),
-		Crumb('/users/', u'Персоналии'),
-		)
-	# depends on current path; generated here
-	trail = (
-		Crumb('/news/2008/', '2008'),
-		Crumb('/foo/2008/08/', u'Август'),
-		Crumb('/foo/2008/08/my-cool-article/', u'Моя статья'),
-		)
-	return mark_safe(render_to_string('navigation.html', pluck_locals('sections', 'trail')))
-	#return mark_safe(unicode(' &rarr; '.join(breadcrumbs)))
-	"""
-
-class CannotResolveCrumb(Exception):
-	pass
-
-def find_crumb(url, request):
-	# by callback
-	try:
-		return find_crumb_by_callback(url, request)
-	except CannotResolveCrumb, e:
-		pass
-	# by flatpage
-	try:
-		return find_crumb_by_flatpage(url)
-	except CannotResolveCrumb, e:
-		pass
-	return Crumb(url, _('Undefined'), is_dummy=True)
-
-def find_crumb_by_callback(url, request):
-	""" Find a view function by urlconf; if the function has attribute 'navigation', use it. """
-	callback = None
-	urlconf  = getattr(request, "urlconf", settings.ROOT_URLCONF)
-	resolver = RegexURLResolver(r'^/', urlconf)
-	try:
-		# Search for explicitly declared URLs
-		callback, callback_args, callback_kwargs = resolver.resolve(url)
-		bc = getattr(callback, 'navigation', None)
-		if bc is None:
-			raise CannotResolveCrumb, 'Callback %s.%s function "navigation" does not exist.' % (callback.__module__, callback.__name__)
-		if isinstance(bc, basestring):
-			title = bc
-		else:
-			title = bc(request, *callback_args, **callback_kwargs)
-		return Crumb(url,title)
-	except http.Http404, e:
-		raise CannotResolveCrumb, e
-
-def find_crumb_by_flatpage(url):
-	if not ENABLE_FLATPAGES:
-		raise CannotResolveCrumb, 'FlatPages are disabled'
-	try:
-		title = FlatPage.objects.get(url=url).title
-		return Crumb(url,title)
-	except FlatPage.DoesNotExist:
-		raise CannotResolveCrumb

django-navigation/setup.py

-#!/usr/bin/env python
-# -*- coding: utf-8 -*-
-#
-#  Copyright (c) 2008 Andy Mikhailenko and contributors
-#
-#  This file is part of Django Navigation.
-#
-#  Django Navigation is free software under terms of the GNU Lesser
-#  General Public License version 3 (LGPLv3) as published by the Free
-#  Software Foundation. See the file README for copying conditions.
-#
-
-" Django Navigation setup "
-
-from distutils.core import setup
-from navigation import get_version
-
-setup(
-    name         = 'Django Navigation',
-    version      = get_version(),
-    description  = 'A breadcrumbs navigation application for Django framework.',
-    author       = 'Andy Mikhailenko',
-    author_email = 'andy@neithere.net',
-    url          = 'http://bitbucket.org/neithere/django-navigation/',
-    download_url = 'http://bitbucket.org/neithere/django-navigation/src/',
-    license      = 'GNU Lesser General Public License (LGPL), Version 3',
-    packages     = ['navigation'],
-)

navigation/__init__.py

+# -*- coding: utf-8 -*-
+#
+#  Copyright (c) 2008 Andy Mikhailenko and contributors
+#
+#  Django Navigation is free software under terms of the GNU Lesser
+#  General Public License version 3 (LGPLv3) as published by the Free
+#  Software Foundation. See the file README for copying conditions.
+#
+
+" A breadcrumbs navigation application for Django framework. "
+
+VERSION = (0, 1, 'alpha')
+
+def get_version():
+    " Returns the version as a human-format string. "
+    v = '.'.join([str(i) for i in VERSION[:-1]])
+    return '%s-%s' % (v, VERSION[-1])
+
+__author__  = 'Andy Mikhailenko'
+__license__ = 'GNU Lesser General Public License (GPL), Version 3'
+__url__     = 'http://bitbucket.org/neithere/django-navigation/'
+__version__ = get_version()

navigation/templatetags/__init__.py

Empty file added.

navigation/templatetags/navigation.py

+# -*- coding: utf-8 -*-
+
+""" Universal breadcrumbs navigation for Django.
+
+FlatPages trail by:
+jca <http://djangosnippets.org/snippets/519/>
+
+Original idea and implementation of universal breadcrumbs for custom views by:
+Thomas Guettler <http://groups.google.com/group/django-users/browse_thread/thread/f40f59e39cef59c4>
+
+Unified templated breadcrumbs for both FlatPages and custom views support by:
+Andy Mikhailenko <http://neithere.net>, <neithere@gmail.com>
+"""
+
+# Python
+from urlparse import urljoin
+
+# Django
+from django import template, http
+from django.conf import settings
+from django.core.urlresolvers import reverse, RegexURLResolver
+from django.utils.safestring import mark_safe
+from django.utils.html import conditional_escape
+from django.utils.http import urlquote
+from django.utils.translation import ugettext as _
+from django.template.loader import render_to_string
+
+# A list of site sections' URLs in desired order, i.e.:
+#   NAVIGATION_SECTIONS = ('/about/', '/news/')
+SECTIONS = getattr(settings, 'NAVIGATION_SECTIONS', ())
+
+# Check if FlatPages middleware is connected and, if yes, auto-enable them
+if 'django.contrib.flatpages.middleware.FlatpageFallbackMiddleware' in settings.MIDDLEWARE_CLASSES:
+	from django.contrib.flatpages.models import FlatPage
+	ENABLE_FLATPAGES = True
+else:
+	ENABLE_FLATPAGES = False
+
+register = template.Library()
+
+class Crumb:
+	""" A 'crumb' is just a navigation item """
+	def __init__(self, url, title, is_current=False, is_dummy=False):
+		self.url        = url
+		self.title      = title
+		self.is_current = is_current
+		self.is_dummy   = is_dummy
+	__unicode__ = lambda self: self.url
+
+@register.filter(name='get_navigation')
+def get_navigation(request):
+	# Prepare sections (horizontal cut, base level)
+	
+	sections = []
+	for section_url in SECTIONS:
+		crumb = find_crumb(section_url, request)
+		if crumb:
+			if section_url == '/':
+				if request.path == section_url:
+					crumb.is_current = True
+			else:
+				if request.path.startswith(section_url):
+					crumb.is_current = True
+			sections.append(crumb)
+
+	# Prepare trail (vertical cut, excluding base level)
+	
+	trail = []
+	url = request.path
+	while url:
+		if url == '/'  or  url in SECTIONS:
+			break
+		crumb = find_crumb(url, request)
+		if not crumb:
+			break
+		trail.append(crumb)
+
+		# go one level up
+		url = urljoin(url, '..')
+		
+	trail.reverse()
+
+	return mark_safe(render_to_string('navigation.html', dict(sections=sections,trail=trail)))
+
+	"""
+	# defined in settings, crumbified here
+	sections = (
+		Crumb('/about/', u'О нас'),
+		Crumb('/news/', u'Новости', is_current=True),
+		Crumb('/users/', u'Персоналии'),
+		)
+	# depends on current path; generated here
+	trail = (
+		Crumb('/news/2008/', '2008'),
+		Crumb('/foo/2008/08/', u'Август'),
+		Crumb('/foo/2008/08/my-cool-article/', u'Моя статья'),
+		)
+	return mark_safe(render_to_string('navigation.html', pluck_locals('sections', 'trail')))
+	#return mark_safe(unicode(' &rarr; '.join(breadcrumbs)))
+	"""
+
+class CannotResolveCrumb(Exception):
+	pass
+
+def find_crumb(url, request):
+	# by callback
+	try:
+		return find_crumb_by_callback(url, request)
+	except CannotResolveCrumb, e:
+		pass
+	# by flatpage
+	try:
+		return find_crumb_by_flatpage(url)
+	except CannotResolveCrumb, e:
+		pass
+	return Crumb(url, _('Undefined'), is_dummy=True)
+
+def find_crumb_by_callback(url, request):
+	""" Find a view function by urlconf; if the function has attribute 'navigation', use it. """
+	callback = None
+	urlconf  = getattr(request, "urlconf", settings.ROOT_URLCONF)
+	resolver = RegexURLResolver(r'^/', urlconf)
+	try:
+		# Search for explicitly declared URLs
+		callback, callback_args, callback_kwargs = resolver.resolve(url)
+		bc = getattr(callback, 'navigation', None)
+		if bc is None:
+			raise CannotResolveCrumb, 'Callback %s.%s function "navigation" does not exist.' % (callback.__module__, callback.__name__)
+		if isinstance(bc, basestring):
+			title = bc
+		else:
+			title = bc(request, *callback_args, **callback_kwargs)
+		return Crumb(url,title)
+	except http.Http404, e:
+		raise CannotResolveCrumb, e
+
+def find_crumb_by_flatpage(url):
+	if not ENABLE_FLATPAGES:
+		raise CannotResolveCrumb, 'FlatPages are disabled'
+	try:
+		title = FlatPage.objects.get(url=url).title
+		return Crumb(url,title)
+	except FlatPage.DoesNotExist:
+		raise CannotResolveCrumb
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+#
+#  Copyright (c) 2008 Andy Mikhailenko and contributors
+#
+#  This file is part of Django Navigation.
+#
+#  Django Navigation is free software under terms of the GNU Lesser
+#  General Public License version 3 (LGPLv3) as published by the Free
+#  Software Foundation. See the file README for copying conditions.
+#
+
+" Django Navigation setup "
+
+from distutils.core import setup
+from navigation import get_version
+
+setup(
+    name         = 'Django Navigation',
+    version      = get_version(),
+    description  = 'A breadcrumbs navigation application for Django framework.',
+    author       = 'Andy Mikhailenko',
+    author_email = 'andy@neithere.net',
+    url          = 'http://bitbucket.org/neithere/django-navigation/',
+    download_url = 'http://bitbucket.org/neithere/django-navigation/src/',
+    license      = 'GNU Lesser General Public License (LGPL), Version 3',
+    packages     = ['navigation'],
+)