<s> from django . contrib . messages . storage . session import SessionStorage <EOL> from offline_messages . utils import create_offline_message <EOL> from offline_messages . models import OfflineMessage <EOL> class OfflineStorageEngine ( SessionStorage ) : <EOL> """<STR_LIT>""" <EOL> def _get ( self , * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> messages = [ ] <EOL> if hasattr ( self . request , '<STR_LIT:user>' ) and self . request . user . is_authenticated ( ) : <EOL> offline_messages = OfflineMessage . objects . filter ( user = self . request . user , read = False ) <EOL> if offline_messages : <EOL> messages . extend ( offline_messages ) <EOL> offline_messages . update ( read = True ) <EOL> online_messages , all_retrieved = super ( OfflineStorageEngine , self ) . _get ( * args , ** kwargs ) <EOL> if online_messages : <EOL> messages . extend ( online_messages ) <EOL> return messages , True <EOL> def _store ( self , messages , * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> if hasattr ( self . request , '<STR_LIT:user>' ) and self . request . user . is_authenticated ( ) : <EOL> for msg in messages : <EOL> create_offline_message ( self . request . user , msg . message , msg . level ) <EOL> else : <EOL> messages = [ msg for msg in messages if not isinstance ( msg , OfflineMessage ) ] <EOL> return super ( OfflineStorageEngine , self ) . _store ( messages , * args , ** kwargs ) </s>
