from django.conf import settings
from django.core.exceptions import ImproperlyConfigured
from django.contrib.auth.models import User

from tribes.models import Tribe
from bookmarks.models import Bookmark
from blog.models import Post

_inbox_count_sources = None

def inbox_count_sources():
    global _inbox_count_sources
    if _inbox_count_sources is None:
        sources = []
        for path in settings.COMBINED_INBOX_COUNT_SOURCES:
            i = path.rfind('.')
            module, attr = path[:i], path[i+1:]
            try:
                mod = __import__(module, {}, {}, [attr])
            except ImportError, e:
                raise ImproperlyConfigured('Error importing request processor module %s: "%s"' % (module, e))
            try:
                func = getattr(mod, attr)
            except AttributeError:
                raise ImproperlyConfigured('Module "%s" does not define a "%s" callable request processor' % (module, attr))
            sources.append(func)
        _inbox_count_sources = tuple(sources)
    return _inbox_count_sources

def combined_inbox_count(request):
    """
    A context processor that uses other context processors defined in
    setting.COMBINED_INBOX_COUNT_SOURCES to return the combined number from
    arbitrary counter sources.
    """
    count = 0
    for func in inbox_count_sources():
        counts = func(request)
        if counts:
            for value in counts.itervalues():
                try:
                    count = count + int(value)
                except (TypeError, ValueError):
                    pass
    return {'combined_inbox_count': count,}

def footer(request):
    return {
        'latest_tribes': Tribe.objects.all().order_by('-created')[:5],
        'latest_users': User.objects.all().order_by('-date_joined')[:9],
        'latest_bookmarks': Bookmark.objects.all().order_by('-added')[:5],
        'latest_blogs': Post.objects.filter(status=2).order_by('-publish')[:5],
    }

@@ -127,16 +127,17 @@
 t User%0A%0A
+#
 from tri
@@ -160,16 +160,17 @@
 t Tribe%0A
+#
 from boo
@@ -199,16 +199,17 @@
 ookmark%0A
+#
 from blo
@@ -1628,16 +1628,17 @@
 ount,%7D%0A%0A
+#
 def foot
@@ -1646,24 +1646,25 @@
 r(request):%0A
+#
     return %7B
@@ -1664,16 +1664,17 @@
 eturn %7B%0A
+#
         
@@ -1728,32 +1728,33 @@
 -created')%5B:5%5D,%0A
+#
         'latest_
@@ -1810,16 +1810,17 @@
 ')%5B:9%5D,%0A
+#
         
@@ -1882,24 +1882,25 @@
 dded')%5B:5%5D,%0A
+#
         'lat
@@ -1967,14 +1967,15 @@
 ')%5B:5%5D,%0A
+#
     %7D%0A

remove unused code