<s> from django . conf import settings <EOL> from django . core . exceptions import ImproperlyConfigured <EOL> from django . contrib . auth . models import User <EOL> from microblogging . models import Tweet <EOL> from blog . models import Post <EOL> _inbox_count_sources = None <EOL> def inbox_count_sources ( ) : <EOL> global _inbox_count_sources <EOL> if _inbox_count_sources is None : <EOL> sources = [ ] <EOL> for path in settings . COMBINED_INBOX_COUNT_SOURCES : <EOL> i = path . rfind ( '<STR_LIT:.>' ) <EOL> module , attr = path [ : i ] , path [ i + <NUM_LIT:1> : ] <EOL> try : <EOL> mod = __import__ ( module , { } , { } , [ attr ] ) <EOL> except ImportError , e : <EOL> raise ImproperlyConfigured ( '<STR_LIT>' % ( module , e ) ) <EOL> try : <EOL> func = getattr ( mod , attr ) <EOL> except AttributeError : <EOL> raise ImproperlyConfigured ( '<STR_LIT>' % ( module , attr ) ) <EOL> sources . append ( func ) <EOL> _inbox_count_sources = tuple ( sources ) <EOL> return _inbox_count_sources <EOL> def combined_inbox_count ( request ) : <EOL> """<STR_LIT>""" <EOL> count = <NUM_LIT:0> <EOL> for func in inbox_count_sources ( ) : <EOL> counts = func ( request ) <EOL> if counts : <EOL> for value in counts . itervalues ( ) : <EOL> try : <EOL> count = count + int ( value ) <EOL> except ( TypeError , ValueError ) : <EOL> pass <EOL> return { <EOL> "<STR_LIT>" : count , <EOL> } <EOL> def footer ( request ) : <EOL> return { <EOL> "<STR_LIT>" : Tweet . objects . all ( ) . order_by ( "<STR_LIT>" ) [ : <NUM_LIT:5> ] , <EOL> "<STR_LIT>" : User . objects . all ( ) . order_by ( "<STR_LIT>" ) [ : <NUM_LIT:9> ] , <EOL> "<STR_LIT>" : Post . objects . filter ( status = <NUM_LIT:2> ) . order_by ( "<STR_LIT>" ) [ : <NUM_LIT:5> ] , <EOL> } </s>
