コード例 #1
0
	def get(self):
		user=users.get_current_user()
		url_linktext,greeting,user_class=check.check_user(user,self.request.uri);
		#go back to home if no user
		if not user:self.redirect('/');
		else:	
			#find customer of user
			try:
				customer=db.get(db.Key.from_path('Customer',user.email()));
			except:
				customer=None;
			
			#find order
			info_table=[];
			total=0;
			
			if customer:
				status="Đây là tài khoản Khách Hàng của bạn!";
				#get all orders of customer
				order_query = db.GqlQuery("SELECT * FROM Order Where customer=:1 ORDER BY created DESC",customer.code);
				data = [order for order in order_query];
				
				#calculate money of orders
				for	order in data:
					row=custom();
					row.code=order.code;
					row.created=order.created;
					row.modified=order.modified;
					row.confirm=order.confirm;
					row.sum_money=sum([order.list_price[j]*order.list_quantity[j]for j in range(len(order.list_price))]);
					row.sum_quantity=sum(order.list_quantity);
					row.note= order.note;
					total+=row.sum_money;
					info_table+=[row];
					
			else: 
				status="Bạn chưa có tài khoản Khách Hàng! Mua bất kì 1 sản phẩm nào sẽ có ngay!";
			
			#render
			template_values = {
				'greeting': greeting,
				'user_class': user_class,
				'url_linktext': url_linktext,
				'user':user,
				'status':status,
				'customer':customer,
				'orders':info_table,
				'total':total,
			}

			path = os.path.join(os.path.dirname(__file__), 'user_info.html')
			self.response.out.write(template.render(path, template_values))
コード例 #2
0
    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")

        if user_class not in ["manager", "employee"] 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
        code = self.request.get("code")

        info_table = []
        total = 0
        customer = None

        if shop and not code:  # show order saveed on cookie
            cookies = self.request.cookies
            for key in cookies:
                cookies[key] = urllib2.unquote(cookies[key].encode("utf-8"))
            if cookies.has_key("cart_item"):
                list_item = cookies["cart_item"].split(",")
                list_chosen = cookies["cart_chosen"].split(",")
                list_quantity = cookies["cart_quantity"].split(",")
            else:
                list_item = list_chosen = list_quantity = []

            if user:
                customer = db.get(db.Key.from_path("Customer", user.email()))
            for i in range(10):
                if i >= len(list_item):
                    break
                # find product by code in list_item
                photo = ""
                row_status = ""
                item = None
                if list_item[i]:
                    item = db.get(db.Key.from_path("Product", list_item[i]))
                    if item:
                        row_status = "Sản Phẩm có trong CSDL"
                        if item.on_sale:
                            row_status += " với " + str(item.on_sale) + "% sale off"
                        photo = item.photo
                    else:
                        continue
                else:
                    continue

                row = trow()
                row.index = i
                row.photo = photo

                row.spec_choices = []
                # current choice
                row.chosen = list_chosen[i]
                # other available choice
                if item:
                    row.spec_choices = item.spec_choices

                row.item = list_item[i]

                # price = item.sell_price*(1-item.on_sale% or customer.private_sale%)
                sale_off = 0
                if customer:
                    sale_off = customer.private_sale
                if item.on_sale:
                    sale_off = item.on_sale
                if sale_off > 100:
                    sale_off = 100
                row.price = item.sell_price * (1 - float(sale_off) / 100)

                row.quantity = list_quantity[i]

                row.money = row.price * int(row.quantity)
                total += row.money

                row.status = row_status

                info_table += [row]

                ####################################################################################
        status = "Quản Lý Đơn Hàng!"
        list_price = []
        # check empty string
        try:
            order = db.get(db.Key.from_path("Order", int(code)))
        except:
            order = None

            # find order
        if order:
            status = "Tìm Thấy!"
            if order.customer:
                customer = db.get(db.Key.from_path("Customer", order.customer))
                # get list_price from list_item
            for i in range(10):
                # find product by code in list_item
                photo = ""
                row_status = ""
                item = None
                if order.list_item[i]:
                    item = db.get(db.Key.from_path("Product", order.list_item[i]))
                    if item:
                        row_status = "Sản Phẩm có trong CSDL"
                        if item.on_sale:
                            row_status += " với " + str(item.on_sale) + "% sale off"
                        photo = item.photo
                    else:
                        row_status = "Ko tìm thấy!"
                else:
                    row_status = "x"

                row = trow()
                row.index = i
                row.photo = photo

                row.spec_choices = []
                # current choice
                row.chosen = order.list_chosen[i]
                # other available choice
                if item:
                    row.spec_choices = item.spec_choices

                row.item = order.list_item[i]
                row.price = order.list_price[i]
                row.quantity = order.list_quantity[i]
                try:
                    row.money = row.price * row.quantity
                    total += row.money
                except:
                    row.money = "?"
                row.status = row_status

                info_table += [row]

                # status+=" item="+str(len(info_table));
        elif not shop:
            status = "Ko tìm thấy!"
            for i in range(10):
                row = trow()
                row.index = i
                row.price = "x"
                row.quantity = 0
                row.status = "x"
                info_table += [row]

        if not code:
            status = "Quản Lý Đơn Hàng!"
        if self.request.get("status"):
            status = self.request.get("status")

        # fix date.created to GMT+7 for bill print
        if order:
            date_plus7 = order.created + datetime.timedelta(hours=7)
        else:
            date_plus7 = datetime.datetime.now() + datetime.timedelta(hours=7)
        # render
        template_values = {
            "greeting": greeting,
            "user_class": user_class,
            "url_linktext": url_linktext,
            "user": user,
            "status": status,
            "order": order,
            "customer": customer,
            "info_table": info_table,
            "total": total,
            "date_plus7": date_plus7,
        }

        if self.request.get("version") == "print":
            path = os.path.join(os.path.dirname(__file__), "bill.html")
            self.response.out.write(template.render(path, template_values))
            return
        if shop:
            path = os.path.join(os.path.dirname(__file__), "shop_order.html")
            self.response.out.write(template.render(path, template_values))
            return
        path = os.path.join(os.path.dirname(__file__), "order.html")
        self.response.out.write(template.render(path, template_values))
コード例 #3
0
    def get(self):
        # Check user
        user = users.get_current_user()
        url_linktext, greeting, user_class = check.check_user(user, self.request.uri)

        if user_class not in ["manager", "employee"]:
            # 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 = 50
        try:
            page = int(self.request.get("page"))
        except:
            page = 0

            # Get sort and filter atribute
        confirm_filter = self.request.get("confirm_filter")
        customer_filter = self.request.get("customer_filter")
        item_filter = self.request.get("item_filter")
        spec_filter = self.request.get("spec_filter")
        show_hidden = self.request.get("show_hidden")

        # Query
        query = db.Query(Order, keys_only=False)

        # filter
        if confirm_filter == "True":
            query.filter("confirm =", True)
        elif confirm_filter == "False":
            query.filter("confirm =", False)

        if customer_filter:
            query.filter("customer =", customer_filter)
        if item_filter:
            query.filter("list_item =", item_filter)
        if spec_filter:
            query.filter("list_chosen =", spec_filter)
        # default: not show hidden order
        if not show_hidden:
            query.filter("hidden =", False)

        # sort
        query.order("-created")

        if max < 20:
            max = 20
        if page < 0:
            page = 0

        data = query.fetch(max, page * max)

        status = "Đây là những đơn hàng từ " + str(page * max) + " tới " + str(page * max + len(data))
        if len(data) == max:
            status += " - Bấm nextpage để xem nhiều hơn!"

        # init table
        table = []
        i = 0
        for order in data:
            # init row
            row = trow()
            row.index = i
            i += 1
            # save data to row
            row.code = order.code
            row.created = order.created
            row.modified = order.modified
            row.confirm = order.confirm
            row.customer = order.customer
            row.note = order.note
            # calculate sum of quantity and money
            row.sum_quantity = sum(order.list_quantity)
            row.sum_money = sum([order.list_price[i] * order.list_quantity[i] for i in range(len(order.list_price))])

            table += [row]

            # save var from request to pass to template
        request = custom()
        request.max = max
        request.page = page
        request.confirm_filter = confirm_filter
        request.customer_filter = customer_filter
        request.spec_filter = spec_filter
        request.item_filter = item_filter
        request.show_hidden = show_hidden

        # render
        template_values = {
            "greeting": greeting,
            "user_class": user_class,
            "url_linktext": url_linktext,
            "status": status,
            "orders": table,
            "request": request,
        }
        path = os.path.join(os.path.dirname(__file__), "list_order.html")
        self.response.out.write(template.render(path, template_values))
コード例 #4
0
    def post(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")

        if user_class not in ["manager", "employee"] 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 and pass to data model object
        code = self.request.get("code")

        # shoping user cant mofify order
        if shop and code:
            # 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

            # Query
        # 		query = db.Query(Product, keys_only=False);
        # 		query.filter("code =", code);
        # 		data = query.fetch(1);
        try:
            order = db.get(db.Key.from_path("Order", int(code)))
        except:
            order = None

        status = ""
        if order:
            status = "Sửa thông tin thành công!"
        else:
            status = "Tạo Đơn Hàng thành công!"
            order = Order()
            order.created = datetime.datetime.now()
            order.who_created = user
            # save order to get auto generated code
            order.put()
            order.code = str(order.key().id())

        order.modified = datetime.datetime.now()
        order.who_modified = user
        # get customer of order
        try:
            customer = db.get(db.Key.from_path("Customer", order.customer))
        except:
            customer = None

        # freely to change if confirm is false
        if not order.confirm:
            try:
                order.confirm = bool(self.request.get("confirm"))
            except:
                pass
                # get list_item and list_quantity, list_chosen (and make changes to database if confirm = true
            for i in range(15):
                # save last item code
                prev_item_code = order.list_item[i]
                # get new item code
                order.list_item[i] = self.request.get("item" + str(i))
                try:
                    order.list_price[i] = float(self.request.get("price" + str(i)))
                except:
                    pass
                # get price if item code change
                try:
                    item = db.get(db.Key.from_path("Product", order.list_item[i]))
                except:
                    item = None

                    # clear price when no product code
                if not item:
                    order.list_price[i] = 0.0
                    # update quantity and spec chosen
                try:
                    order.list_quantity[i] = int(self.request.get("quantity" + str(i)))
                except:
                    order.list_quantity[i] = 0
                order.list_chosen[i] = self.request.get("chosen" + str(i))

                # clear spec_chosen when phoduct code change (except for the case shop , client mobile) or product code = ''
                if not shop and client != "mobile" and prev_item_code != order.list_item[i] or order.list_item[i] == "":
                    order.list_chosen[i] = ""

                # only update price when product code changes
                if item and prev_item_code != order.list_item[i]:
                    # price = item.sell_price*(1-item.on_sale% or customer.private_sale%)
                    sale_off = 0
                    if customer:
                        sale_off = customer.private_sale
                    if item.on_sale:
                        sale_off = item.on_sale
                    if sale_off > 100:
                        sale_off = 100
                    order.list_price[i] = item.sell_price * (1 - float(sale_off) / 100)

                    # also make quantity = 1 if quantity=0
                    if not order.list_quantity[i]:
                        order.list_quantity[i] = 1

                    # check for remove quantity and spec_choice from database when confirm change from false to true. If cant remove, confirm order = false.
                if item and order.confirm:
                    if (item.quantity < order.list_quantity[i]) or (
                        item.spec_choices and order.list_chosen[i] not in item.spec_choices
                    ):
                        status = "Đơn hàng này ko xác nhận được! Kiểm tra lại các thông tin sản phẩm!"
                        order.confirm = False
                        # get var from request
            try:
                order.hidden = bool(self.request.get("hidden"))
            except:
                order.hidden = False

                # actually remove quantity and spec_choice from database
            if order.confirm:
                for i in range(15):
                    try:
                        item = db.get(db.Key.from_path("Product", order.list_item[i]))
                    except:
                        continue
                    if not item:
                        continue
                    # save root_price at the time product being sold
                    order.list_root_price[i] = item.root_price
                    # change and save item
                    item.quantity -= order.list_quantity[i]
                    for iter0 in range(order.list_quantity[i]):
                        try:
                            item.spec_choices.remove(order.list_chosen[i])
                        except:
                            pass
                    item.put()
                    # make hidden = False ( confirmed order cant be hidden)
                order.hidden = False

                # get var from request
            order.customer = self.request.get("customer")
            try:
                order.note = db.Text(self.request.get("note"))
            except:
                order.note = ""

                # order is confirmed, cant change but only unconfirmed.
        if order.confirm:
            try:
                order.confirm = bool(self.request.get("confirm"))
            except:
                pass
            if order.confirm:
                status = "Đơn hàng này đã được xác nhận! Thông tin sẽ ko thể thay đổi cho tới khi hủy xác nhận!"
            else:  # unconfirming order
                # undo the changes from database and get list_item and list_quantity, list_chosen
                for i in range(15):
                    # save last item code
                    prev_item_code = order.list_item[i]
                    # get new item code
                    order.list_item[i] = self.request.get("item" + str(i))
                    try:
                        item = db.get(db.Key.from_path("Product", order.list_item[i]))
                    except:
                        item = None
                        # undo the changes from database when confirm change from true to false.
                        # find prev item
                    if prev_item_code == order.list_item[i]:
                        prev_item = item
                    elif prev_item_code:
                        prev_item = db.get(db.Key.from_path("Product", prev_item_code))
                    if prev_item:
                        # undo changes and save
                        prev_item.quantity += order.list_quantity[i]
                        for iter0 in range(order.list_quantity[i]):
                            prev_item.spec_choices += [order.list_chosen[i]]
                        prev_item.put()

                        # Get price
                    try:
                        order.list_price[i] = float(self.request.get("price" + str(i)))
                    except:
                        pass
                    # only update price when product code changes
                    if item and prev_item_code != order.list_item[i]:
                        # price = item.sell_price*(1-item.on_sale% or customer.private_sale%)
                        sale_off = 0
                        if customer:
                            sale_off = customer.private_sale
                        if item.on_sale:
                            sale_off = item.on_sale
                        if sale_off > 100:
                            sale_off = 100
                        order.list_price[i] = item.sell_price * (1 - float(sale_off) / 100)

                        # update quantity and spec chosen
                    try:
                        order.list_quantity[i] = int(self.request.get("quantity" + str(i)))
                    except:
                        order.list_quantity[i] = 0
                    order.list_chosen[i] = self.request.get("chosen" + str(i))

                order.customer = self.request.get("customer")
                try:
                    order.note = db.Text(self.request.get("note"))
                except:
                    order.note = ""
                try:
                    order.hidden = bool(self.request.get("hidden"))
                except:
                    order.hidden = False

        order.put()  # save data model object to data base
        # create account at first time user send an order
        if shop and order.customer and not customer:
            customer = Customer(key_name=order.customer)
            customer.created = datetime.datetime.now()
            customer.who_created = user
            customer.code = order.customer
            customer.email = db.Email(order.customer)
            customer.modified = datetime.datetime.now()
            customer.who_modified = user

            m = re.search(r"Ten KH:\s*(.+)", self.request.get("note"))
            if m:
                customer.name = m.group(1)

            m = re.search(r"Dia Chi:\s*(.+)\nSo DT:", self.request.get("note"), re.DOTALL)
            if m:
                customer.address = db.Text(m.group(1))

            m = re.search(r"So DT:\s*(.+)", self.request.get("note"))
            if m:
                customer.phone = m.group(1)

            m = re.search(r"Ngay Sinh Nhat:\s*(\d+)\s*/\s*(\d+)\s*", self.request.get("note"))
            if m:
                customer.birth_day = int(m.group(1))
                customer.birth_month = int(m.group(2))

            customer.put()

            # response and redirect
        self.response.out.write(status)
        if shop:
            if user:
                self.redirect("/user/?" + urllib.urlencode({"code": order.code, "status": status}))
            else:
                self.redirect("/")
        else:
            self.redirect("/order/?" + urllib.urlencode({"code": order.code, "status": status, "client": client}))
コード例 #5
0
	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))
コード例 #6
0
	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))
コード例 #7
0
	def post(self):
		#Check user
		user=users.get_current_user()
		url_linktext,greeting,user_class=check.check_user(user,self.request.uri);
		template_values = {
			'greeting': greeting,
			'user_class': user_class,
			'url_linktext': url_linktext,
		}
		if(user_class != 'manager'):
			#render
			template_values.update({
			'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 and pass to data model object
		code=self.request.get('code');
		action=self.request.get('action');

		#Query
#		query = db.Query(Product, keys_only=False);
#		query.filter("code =", code);
#		data = query.fetch(1);
		product=db.get(db.Key.from_path("Product",code));
		status="";
		if product:
			status="Sua thong tin thanh cong!";
			
			if(action and action!='modify'):
				#render
				template_values.update({
				'detail' : "Thao tac sai! (San pham "+code+" da co trogn CSDL)",
				});
				path = os.path.join(os.path.dirname(__file__), 'error.html')
				self.response.out.write(template.render(path, template_values))
				return
		else:
			status="Create Product Success!";
			
			if(action and action!='create'):
				#render
				template_values.update({
				'detail' : "Thao tac sai! (San pham "+code+" chua co trong CSDL)",
				});
				path = os.path.join(os.path.dirname(__file__), 'error.html')
				self.response.out.write(template.render(path, template_values))
				return
				
			product = Product(key_name=code);
			product.created = datetime.datetime.now();
			product.who_created=user;
			product.code = code;

		product.modified = datetime.datetime.now();
		product.who_modified = user;
		product.category = self.request.get('category');
		try:
			product.on_sale = int( self.request.get('on_sale') );
		except:
			product.on_sale = 0;

		#product.size = self.request.get('size');
		#product.color= self.request.get('color');
		#get list spec_choices from request by split ,
		if(self.request.get('spec_choices_str')):product.spec_choices=self.request.get('spec_choices_str').split(',');

		product.quantity = int( self.request.get('quantity') );
		product.root_price = float( self.request.get('root_price') );
		product.sell_price = float( self.request.get('sell_price') );
		product.description = self.request.get('description');
		product.detail =  db.Text( self.request.get('detail') );
		product.photo = self.request.get('photo');
		product.note = self.request.get('note');
		product.put() #save data model object to data base

		#render
		template_values.update({
			'status':status,
			'product':product,
			'spec_choices_str':  ','.join(product.spec_choices),
			'category_list':config.category_list,
		});

		path = os.path.join(os.path.dirname(__file__), 'product.html')
		self.response.out.write(template.render(path, template_values))