def get(self): #Check user user=users.get_current_user() url_linktext,greeting,user_class=check.check_user(user,self.request.uri); #check user are shoping or not shop=self.request.get('shop'); #Only manager are allowed to access product part if(user_class != 'manager' and not shop): #render template_values = { 'greeting': greeting, 'user_class': user_class, 'url_linktext': url_linktext, 'detail' : "Limited Access!", } path = os.path.join(os.path.dirname(__file__), 'error.html') self.response.out.write(template.render(path, template_values)) return #Get var from request code=self.request.get('code'); #Query # if(tag): # query.filter("tag =", tag); # if(dhours and dminutes): # timeFilter=datetime.datetime.now()-datetime.timedelta(hours=int(dhours),minutes=int(dminutes) ); # query.filter("date >",timeFilter); # query.order("-date"); status="Quan Ly San Pham!"; #check empty string if(code): product=db.get(db.Key.from_path("Product",code)); else: product=None; #find product if product: status="Tim Thay!"; spec_choices_str=','.join(product.spec_choices); else: status="Ko tim thay!"; spec_choices_str=''; #render template_values = { 'greeting': greeting, 'user_class': user_class, 'url_linktext': url_linktext, 'status':status, 'product':product, 'spec_choices_str': spec_choices_str, 'category_list':config.category_list, } if shop: category_name=self.request.get('category'); #find information about category category_header=check.category_info_of(category_name); #clear status if there is product if product:template_values['status']=''; #find submenu of category sub_menu_header,sub_menu=check.sub_menu_of(category_name); if(sub_menu_header=="Thời Trang Nữ"): template_values.update({ 'current_page':'female', 'link_content_poster':'/images/beauty-care.jpg', }); elif(sub_menu_header=="Thời Trang Nam"): template_values.update({ 'current_page':'male', 'link_content_poster':'/images/beauty-care.jpg', }); else: template_values.update({ 'current_page':'other', 'link_content_poster':'/images/beauty-care.jpg', }); template_values.update({ 'category_header':category_header, 'sub_menu_header':sub_menu_header, 'sub_menu_list':sub_menu, }); path = os.path.join(os.path.dirname(__file__), 'shop_product.html') self.response.out.write(template.render(path, template_values)) else: path = os.path.join(os.path.dirname(__file__), 'product.html') self.response.out.write(template.render(path, template_values))
def get(self): #Check user user=users.get_current_user() url_linktext,greeting,user_class=check.check_user(user,self.request.uri); #check user are shoping or not shop=self.request.get('shop'); #check client requesting service client=self.request.get('client'); #check is this a qr-code print version qrcode_print=self.request.get('qrcode_print'); qrcode_size=self.request.get('qrcode_size'); #check access if(user_class != 'manager' and not shop and client!='mobile'): #render template_values = { 'greeting': greeting, 'user_class': user_class, 'url_linktext': url_linktext, 'detail' : "Limited Access!", } path = os.path.join(os.path.dirname(__file__), 'error.html') self.response.out.write(template.render(path, template_values)) return #Get var from request try: max=int(self.request.get('max')); except: max=200; try: page=int(self.request.get('page')); except: page=0; #Get sort and filter atribute sort_by=self.request.get('sort_by'); category_filter=self.request.get('category_filter'); spec_filter=self.request.get('spec_filter'); #Query query = db.Query(Product, keys_only=False); #filter if(category_filter):query.filter('category =', category_filter); if(spec_filter):query.filter('spec_choices =', spec_filter); #if(shop):query.filter('photo !=','');#filter so that only products with photo are show on website if(shop=='sale'):query.filter('on_sale >',0); #sort if(sort_by=='created'):query.order('-created'); elif(sort_by=='on_sale'):query.order('-on_sale'); if(max<20):max=20; if(page<0):page=0; #fetch all if client = mobile if(client=='mobile'):data=query.fetch(query.count(None)); else:data = query.fetch(max,page*max); status="Day la nhung san pham tu "+str(page*max)+" toi "+str(page*max+len(data)); if(len(data)==max):status+=" - Bam tiep de xem nhieu hon!"; #if(shop):status+=" - Products with no photo are hidden!"; #save var from request to pass to template request=custom(); request.max=max;request.page=page; request.category_filter=category_filter; request.spec_filter=spec_filter; request.sort_by=sort_by; request.qrcode_size=qrcode_size; request.shop=shop; #render template_values = { 'request':request, 'user_class':user_class, 'greeting': greeting, 'user_class': user_class, 'url_linktext': url_linktext, 'status':status, 'products':data, 'category_list':config.category_list, } if shop: if shop=='new': #Menu of Hang Moi Ve category_header=sub_menu_header="Hang Moi Ve"; sub_menu=[{ 'link':"/product/list/?shop=new&sort_by=created&category_filter="+config.category_list[iter], 'text':config.category_header[iter], }for iter in range(len(config.category_list))] template_values.update({ 'current_page':'new', 'link_content_poster':'/images/apparel.jpg', }); elif shop=='sale': #Menu of Hang Sale category_header=sub_menu_header="Hang SALE!!!"; sub_menu=[{ 'link':"/product/list/?shop=sale&sort_by=on_sale&category_filter="+config.category_list[iter], 'text':config.category_header[iter], }for iter in range(len(config.category_list))] template_values.update({ 'current_page':'sale', 'link_content_poster':'/images/beauty-care.jpg', }); else: # normal case #find information about category category_header=check.category_info_of(category_filter); #find submenu of category sub_menu_header,sub_menu=check.sub_menu_of(category_filter); if(sub_menu_header=="Thời Trang Nữ"): template_values.update({ 'current_page':'female', 'link_content_poster':'/images/beauty-care.jpg', }); elif(sub_menu_header=="Thời Trang Nam"): template_values.update({ 'current_page':'male', 'link_content_poster':'/images/beauty-care.jpg', }); else: template_values.update({ 'current_page':'other', 'link_content_poster':'/images/beauty-care.jpg', }); template_values.update({ 'category_header':category_header, 'sub_menu_header':sub_menu_header, 'sub_menu_list':sub_menu, }); path = os.path.join(os.path.dirname(__file__), 'shop_list_product.html') self.response.out.write(template.render(path, template_values)) elif qrcode_print: path = os.path.join(os.path.dirname(__file__), 'qr-code_list_product.html') self.response.out.write(template.render(path, template_values)) elif client=='mobile': path = os.path.join(os.path.dirname(__file__), 'list_product_service.xml') self.response.out.write(template.render(path, template_values)) else: path = os.path.join(os.path.dirname(__file__), 'list_product.html') self.response.out.write(template.render(path, template_values))