<s> from django import template <EOL> from django . core . urlresolvers import Resolver404 , resolve <EOL> from django . utils import six <EOL> from django . utils . six . moves . urllib import parse <EOL> from django . utils . translation import ugettext_lazy as _ <EOL> from oscar . apps . customer import history <EOL> from oscar . core . loading import get_model <EOL> Site = get_model ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> register = template . Library ( ) <EOL> @ register . inclusion_tag ( '<STR_LIT>' , <EOL> takes_context = True ) <EOL> def recently_viewed_products ( context , current_product = None ) : <EOL> """<STR_LIT>""" <EOL> request = context [ '<STR_LIT>' ] <EOL> products = history . get ( request ) <EOL> if current_product : <EOL> products = [ p for p in products if p != current_product ] <EOL> return { '<STR_LIT>' : products , <EOL> '<STR_LIT>' : request } <EOL> @ register . assignment_tag ( takes_context = True ) <EOL> def get_back_button ( context ) : <EOL> """<STR_LIT>""" <EOL> request = context . get ( '<STR_LIT>' , None ) <EOL> if not request : <EOL> raise Exception ( '<STR_LIT>' ) <EOL> referrer = request . META . get ( '<STR_LIT>' , None ) <EOL> if not referrer : <EOL> return None <EOL> try : <EOL> url = parse . urlparse ( referrer ) <EOL> except ( ValueError , TypeError ) : <EOL> return None <EOL> if request . get_host ( ) != url . netloc : <EOL> try : <EOL> Site . objects . get ( domain = url . netloc ) <EOL> except Site . DoesNotExist : <EOL> return None <EOL> try : <EOL> match = resolve ( url . path ) <EOL> except Resolver404 : <EOL> return None <EOL> titles = { <EOL> '<STR_LIT>' : _ ( '<STR_LIT>' ) , <EOL> } <EOL> title = titles . get ( match . view_name , None ) <EOL> if title is None : <EOL> return None <EOL> return { '<STR_LIT:url>' : referrer , '<STR_LIT:title>' : six . text_type ( title ) , '<STR_LIT>' : match } </s>
