<s> from datetime import timedelta <EOL> from django . core . cache import cache <EOL> from django . utils import translation , timezone <EOL> from django . conf import settings as global_settings <EOL> import pytz <EOL> from djangobb_forum import settings as forum_settings <EOL> class LastLoginMiddleware ( object ) : <EOL> def process_request ( self , request ) : <EOL> if request . user . is_authenticated ( ) : <EOL> cache . set ( '<STR_LIT>' % request . user . id , True , forum_settings . USER_ONLINE_TIMEOUT ) <EOL> class ForumMiddleware ( object ) : <EOL> def process_request ( self , request ) : <EOL> if request . user . is_authenticated ( ) : <EOL> profile = request . user . forum_profile <EOL> language = translation . get_language_from_request ( request ) <EOL> if not profile . language : <EOL> profile . language = language <EOL> profile . save ( ) <EOL> if profile . language and profile . language != language : <EOL> request . session [ '<STR_LIT>' ] = profile . language <EOL> translation . activate ( profile . language ) <EOL> request . LANGUAGE_CODE = translation . get_language ( ) <EOL> class UsersOnline ( object ) : <EOL> def process_request ( self , request ) : <EOL> now = timezone . now ( ) <EOL> delta = now - timedelta ( seconds = forum_settings . USER_ONLINE_TIMEOUT ) <EOL> users_online = cache . get ( '<STR_LIT>' , { } ) <EOL> guests_online = cache . get ( '<STR_LIT>' , { } ) <EOL> if request . user . is_authenticated ( ) : <EOL> users_online [ request . user . id ] = now <EOL> else : <EOL> guest_sid = request . COOKIES . get ( global_settings . SESSION_COOKIE_NAME , '<STR_LIT>' ) <EOL> guests_online [ guest_sid ] = now <EOL> for user_id in list ( users_online . keys ( ) ) : <EOL> if users_online [ user_id ] < delta : <EOL> del users_online [ user_id ] <EOL> for guest_id in list ( guests_online . keys ( ) ) : <EOL> if guests_online [ guest_id ] < delta : <EOL> del guests_online [ guest_id ] <EOL> cache . set ( '<STR_LIT>' , users_online , <NUM_LIT> * <NUM_LIT> * <NUM_LIT> ) <EOL> cache . set ( '<STR_LIT>' , guests_online , <NUM_LIT> * <NUM_LIT> * <NUM_LIT> ) <EOL> class TimezoneMiddleware ( object ) : <EOL> def process_request ( self , request ) : <EOL> if request . user . is_authenticated ( ) : <EOL> profile = request . user . forum_profile <EOL> try : <EOL> timezone . activate ( profile . time_zone ) <EOL> except pytz . UnknownTimeZoneError : <EOL> profile . time_zone = global_settings . TIME_ZONE <EOL> profile . save ( ) </s>
