<s> from django . core . urlresolvers import NoReverseMatch , reverse <EOL> from livesettings import config_value <EOL> import logging <EOL> import re <EOL> log = logging . getLogger ( '<STR_LIT>' ) <EOL> try : <EOL> producturl = reverse ( '<STR_LIT>' , <EOL> kwargs = { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> producturl = "<STR_LIT>" + producturl . replace ( "<STR_LIT>" , r'<STR_LIT>' ) <EOL> log . debug ( '<STR_LIT>' , producturl ) <EOL> urlre = re . compile ( producturl ) <EOL> except NoReverseMatch : <EOL> log . debug ( "<STR_LIT>" ) <EOL> urlre = None <EOL> class RecentProductMiddleware ( object ) : <EOL> """<STR_LIT>""" <EOL> def process_response ( self , request , response ) : <EOL> if urlre is not None : <EOL> g = urlre . search ( request . path ) <EOL> if g and len ( g . groups ( ) ) > <NUM_LIT:0> and "<STR_LIT>" not in request . path : <EOL> recentmax = config_value ( '<STR_LIT>' , '<STR_LIT>' ) + <NUM_LIT:1> <EOL> slug = g . groups ( ) [ <NUM_LIT:0> ] <EOL> recent = request . session . get ( '<STR_LIT>' , [ ] ) <EOL> if slug not in recent : <EOL> recent . insert ( <NUM_LIT:0> , slug ) <EOL> if len ( recent ) > recentmax : <EOL> recent = recent [ : recentmax ] <EOL> log . debug ( '<STR_LIT>' , recent ) <EOL> request . session [ '<STR_LIT>' ] = recent <EOL> return response </s>
