<s> def index ( ) : <EOL> redirect ( URL ( c = '<STR_LIT:default>' , f = '<STR_LIT:index>' ) ) <EOL> def show_products ( ) : <EOL> if request . vars . category : <EOL> product_list = db ( db . product . default_category == request . vars . category ) . select ( limitby = ( <NUM_LIT:0> , <NUM_LIT:20> ) , <EOL> orderby = db . product . name ) <EOL> else : <EOL> product_list = db ( db . product ) . select ( limitby = ( <NUM_LIT:0> , <NUM_LIT:20> ) , orderby = ~ db . product . name ) <EOL> return locals ( ) <EOL> def product ( ) : <EOL> if not request . args : redirect ( URL ( c = '<STR_LIT:default>' , f = '<STR_LIT:index>' ) ) <EOL> try : <EOL> int ( request . args ( <NUM_LIT:0> ) ) <EOL> except ValueError : <EOL> raise HTTP ( <NUM_LIT> , '<STR_LIT>' ) <EOL> product = db ( db . product . id == int ( request . args ( <NUM_LIT:0> ) ) ) . select ( ) . first ( ) <EOL> specification = db ( db . specification . product == product . id ) . select ( ) . first ( ) <EOL> reviews = db ( db . review . product == product . id ) . select ( ) <EOL> form = SQLFORM . factory ( <EOL> Field ( '<STR_LIT>' , '<STR_LIT>' , default = <NUM_LIT:1> ) , <EOL> _class = "<STR_LIT>" <EOL> ) <EOL> if form . accepts ( request . vars , session ) : <EOL> quantity = int ( form . vars . quantity ) <EOL> if quantity > product . quantity or quantity <= <NUM_LIT:0> : <EOL> response . flash = T ( '<STR_LIT>' ) <EOL> else : <EOL> for prod in session . cart : <EOL> if prod [ <NUM_LIT:0> ] == product . id : <EOL> prod [ <NUM_LIT:1> ] += quantity <EOL> break <EOL> else : <EOL> session . cart . append ( [ product . id , quantity ] ) <EOL> break <EOL> else : <EOL> session . cart . append ( [ product . id , quantity ] ) <EOL> redirect ( URL ( c = '<STR_LIT:default>' , f = '<STR_LIT>' ) ) <EOL> return dict ( product = product , specification = specification , reviews = reviews , form = form ) <EOL> @ cache . action ( ) <EOL> def download ( ) : <EOL> """<STR_LIT>""" <EOL> return response . download ( request , db ) </s>
