<s> """<STR_LIT>""" <EOL> from __future__ import ( absolute_import , division , <EOL> print_function , unicode_literals ) <EOL> from django . shortcuts import render <EOL> from django . http import HttpResponseForbidden , HttpResponseNotFound <EOL> from django . core . exceptions import MultipleObjectsReturned <EOL> from django . views . generic import TemplateView <EOL> from . models import Product , Category <EOL> def product_list_view ( request , cat_id ) : <EOL> if request . is_authenticated ( ) : <EOL> ctx = { '<STR_LIT>' : Product . objects . all ( ) , <EOL> '<STR_LIT>' : cat_id } <EOL> return render ( request , '<STR_LIT>' , context = ctx ) <EOL> else : <EOL> return HttpResponseForbidden ( ) <EOL> def product_detail_view ( request , slug ) : <EOL> if request . is_authenticated : <EOL> try : <EOL> product = Product . objects . get ( slug = slug ) <EOL> except MultipleObjectsReturned : <EOL> return HttpResponseNotFound ( ) <EOL> return render ( <EOL> request , '<STR_LIT>' , context = { '<STR_LIT>' : product } ) <EOL> else : <EOL> return HttpResponseForbidden ( ) <EOL> def category_detail_view ( request , ** kwargs ) : <EOL> try : <EOL> category = Category . objects . get ( pk = kwargs [ '<STR_LIT>' ] ) <EOL> except Category . DoesNotExist : <EOL> return HttpResponseNotFound ( ) <EOL> return render ( <EOL> request , '<STR_LIT>' , context = { '<STR_LIT>' : category } ) <EOL> class IndexView ( TemplateView ) : <EOL> def get_context_data ( self , ** kwargs ) : <EOL> ctx = super ( IndexView , self ) . get_context_data ( ** kwargs ) <EOL> ctx [ '<STR_LIT>' ] = Category . objects . get ( pk = kwargs [ '<STR_LIT>' ] ) <EOL> self . _manager = Category . objects <EOL> return ctx </s>
