<s> from django . contrib . messages import constants <EOL> from django . contrib . messages . storage import default_storage <EOL> from django . utils . functional import lazy , memoize <EOL> __all__ = ( <EOL> '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT:info>' , '<STR_LIT:success>' , '<STR_LIT>' , '<STR_LIT:error>' , <EOL> ) <EOL> class MessageFailure ( Exception ) : <EOL> pass <EOL> def add_message ( request , level , message , extra_tags = '<STR_LIT>' , fail_silently = False ) : <EOL> """<STR_LIT>""" <EOL> if hasattr ( request , '<STR_LIT>' ) : <EOL> return request . _messages . add ( level , message , extra_tags ) <EOL> if hasattr ( request , '<STR_LIT:user>' ) and request . user . is_authenticated ( ) : <EOL> return request . user . message_set . create ( message = message ) <EOL> if not fail_silently : <EOL> raise MessageFailure ( '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> def get_messages ( request ) : <EOL> """<STR_LIT>""" <EOL> if hasattr ( request , '<STR_LIT>' ) : <EOL> return request . _messages <EOL> def get_user ( ) : <EOL> if hasattr ( request , '<STR_LIT:user>' ) : <EOL> return request . user <EOL> else : <EOL> from django . contrib . auth . models import AnonymousUser <EOL> return AnonymousUser ( ) <EOL> return lazy ( memoize ( get_user ( ) . get_and_delete_messages , { } , <NUM_LIT:0> ) , list ) ( ) <EOL> def get_level ( request ) : <EOL> """<STR_LIT>""" <EOL> if hasattr ( request , '<STR_LIT>' ) : <EOL> storage = request . _messages <EOL> else : <EOL> storage = default_storage ( request ) <EOL> return storage . level <EOL> def set_level ( request , level ) : <EOL> """<STR_LIT>""" <EOL> if not hasattr ( request , '<STR_LIT>' ) : <EOL> return False <EOL> request . _messages . level = level <EOL> return True <EOL> def debug ( request , message , extra_tags = '<STR_LIT>' , fail_silently = False ) : <EOL> """<STR_LIT>""" <EOL> add_message ( request , constants . DEBUG , message , extra_tags = extra_tags , <EOL> fail_silently = fail_silently ) <EOL> def info ( request , message , extra_tags = '<STR_LIT>' , fail_silently = False ) : <EOL> """<STR_LIT>""" <EOL> add_message ( request , constants . INFO , message , extra_tags = extra_tags , <EOL> fail_silently = fail_silently ) <EOL> def success ( request , message , extra_tags = '<STR_LIT>' , fail_silently = False ) : <EOL> """<STR_LIT>""" <EOL> add_message ( request , constants . SUCCESS , message , extra_tags = extra_tags , <EOL> fail_silently = fail_silently ) <EOL> def warning ( request , message , extra_tags = '<STR_LIT>' , fail_silently = False ) : <EOL> """<STR_LIT>""" <EOL> add_message ( request , constants . WARNING , message , extra_tags = extra_tags , <EOL> fail_silently = fail_silently ) <EOL> def error ( request , message , extra_tags = '<STR_LIT>' , fail_silently = False ) : <EOL> """<STR_LIT>""" <EOL> add_message ( request , constants . ERROR , message , extra_tags = extra_tags , <EOL> fail_silently = fail_silently ) </s>
