Author: leidel
Date: Sun Sep 28 14:58:44 2008
New Revision: 979
Added:
trunk/local_apps/core/utils.py
Modified:
trunk/local_apps/core/context_processors.py
trunk/pinax/settings.py
trunk/pinax/templates/site_base.html
Log:
Added context_processor to the Pinax core app that takes a list of other
context processors (defined in settings.COMBINED_INBOX_COUNT_SOURCES) to
compute a combined inbox count
Modified: trunk/local_apps/core/context_processors.py
==============================================================================
--- trunk/local_apps/core/context_processors.py (original)
+++ trunk/local_apps/core/context_processors.py Sun Sep 28 14:58:44 2008
@@ -4,7 +4,7 @@
from django.contrib.auth.models import User
from bookmarks.models import Bookmark
from blog.models import Post
-
+from core.utils import inbox_count_sources
def contact_email(request):
return {'contact_email': getattr(settings, 'CONTACT_EMAIL', '')}
@@ -13,7 +13,7 @@
return {'site_name': getattr(settings, 'SITE_NAME', '')}
def footer(request):
- return {
+ return {
'latest_tweets': Tweet.objects.all().order_by('-sent')[:5],
'latest_tribes': Tribe.objects.all().order_by('-created')[:5],
'latest_users': User.objects.all().order_by('-date_joined')[:9],
@@ -21,3 +21,19 @@
'latest_blogs':
Post.objects.filter(status=2).order_by('-publish')[:5],
}
+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,}
Added: trunk/local_apps/core/utils.py
==============================================================================
--- (empty file)
+++ trunk/local_apps/core/utils.py Sun Sep 28 14:58:44 2008
@@ -0,0 +1,22 @@
+from django.conf import settings
+
+_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
Modified: trunk/pinax/settings.py
==============================================================================
--- trunk/pinax/settings.py (original)
+++ trunk/pinax/settings.py Sun Sep 28 14:58:44 2008
@@ -97,6 +97,13 @@
"core.context_processors.site_name",
"messages.context_processors.inbox",
"friends_app.context_processors.invitations",
+ "core.context_processors.combined_inbox_count",
+)
+
+COMBINED_INBOX_COUNT_SOURCES = (
+ "messages.context_processors.inbox",
+ "friends_app.context_processors.invitations",
+ "notification.context_processors.notification",
)
INSTALLED_APPS = (
Modified: trunk/pinax/templates/site_base.html
==============================================================================
--- trunk/pinax/templates/site_base.html (original)
+++ trunk/pinax/templates/site_base.html Sun Sep 28 14:58:44 2008
@@ -49,7 +49,7 @@
<td class="tab rtab_tweets"><div><a href="{% url
tweets_you_follow %}">{% trans "Tweets" %}</a></div></td>
<td class="tab rtab_bookmarks"><div><a href="{% url
bookmarks.views.bookmarks %}">{% trans "Bookmarks" %}</a></div></td>
<td class="tab rtab_swaps"><div><a href="{% url
swaps.views.offers %}">{% trans "Swaps" %}</a></div></td>
- <td class="tab rtab_inbox"><div><a href="{% url
messages_inbox %}">{% trans "Inbox" %} ({% if messages_inbox_count %}{{
messages_inbox_count }}{% else %}0{% endif %}{% if
notice_unseen_count %}+{{ notice_unseen_count }}{% endif %})</a></div></td>
+ <td class="tab rtab_inbox"><div><a href="{% url
messages_inbox %}">{% trans "Inbox" %} ({{ combined_inbox_count
}})</a></div></td>
</tr>
</table>
{% endif %}
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"pinax-updates" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/pinax-updates?hl=en
-~----------~----~----~----~------~----~------~--~---