def get(self, order_id): user = users.get_current_user() offer = Offer(name="", description="", products=[], user=Account.get_or_create(user.user_id(), user.nickname())) offer.put() self.redirect("/order/" + order_id + "/offer/" + str(offer.key.id()))
def post(self, order_id, offer_id): name = self.request.get("name") desc = self.request.get("description") offer = Offer.get_by_id(int(offer_id)) offer.name = name offer.description = desc offer.put() trade = Trade(order=int(order_id), offer=int(offer_id)) trade.put() self.redirect("/order/" + order_id + "/view")
def get(self, order_id, offer_id): template = JINJA_ENVIRONMENT.get_template('offer_add.html') offer = Offer.get_by_id(int(offer_id)) order = Order.get_by_id(int(order_id)) template_var = { "products": offer.products, "offer": offer, "order_id": order_id, "order": order, "users": users, } self.response.write(template.render(template_var))
def post(self, order_id, offer_id): name = self.request.get("name") desc = self.request.get("description") category = Category.get_by_id(int(self.request.get("category"))) # status = self.request.get("status") brand = Brand.get_by_id(int(self.request.get("brand"))) img = self.request.get("photo", None) # product = Product(name=name, description=desc, category=category, brand=brand) product = Product(name=name, description=desc, category=category, brand=brand, img=db.Blob(img)) # product = Product(name=name, description=desc, category=category, brand=brand, img=img) # product.put() offer = Offer.get_by_id(int(offer_id)) offer.products.append(product) offer.put() self.redirect("/order/" + order_id + "/offer/" + str(offer.key.id()))
def get(self, order_id, offer_id): template = JINJA_ENVIRONMENT.get_template('offer_view.html') user = users.get_current_user() if user: Account.get_or_create(user.user_id(), user.nickname()) auth_link = users.create_logout_url(self.request.url) else: auth_link = users.create_login_url(self.request.url) offer = Offer.get_by_id(int(offer_id)) order = Order.get_by_id(int(order_id)) template_var = { "categories": Category.query().order(Category.name).fetch(), "offer": offer, "products": offer.products, "users": users, "auth_link": auth_link, "order": order, } self.response.write(template.render(template_var))
def post(self, order_id, offer_id): trade_list = Trade.query(Trade.order == int(order_id)).fetch() for t in trade_list: if t.offer == int(offer_id): t.status = Trade.STATUS_ACCEPT order = Order.get_by_id(int(order_id)) order.status = Order.STATUS_INVALID order.put() mail.send_mail(sender="*****@*****.**", to=users.User(_user_id=order.user.id).email(), subject="test", body="test") offer = Offer.get_by_id(int(offer_id)) mail.send_mail(sender="*****@*****.**", to=users.User(_user_id=offer.user.id).email(), subject="test", body="test") else: t.status = Trade.STATUS_REJECT t.put() self.redirect("/")
def get(self, order_id, offer_id, product_num): offer = Offer.get_by_id(int(offer_id)) product = offer.products[int(product_num)] if product.img: self.response.headers['Content-Type'] = 'image/png' self.response.out.write(product.img)
def get_trade_offer(cls, order_id): trades = cls.query(cls.order == order_id, cls.status == 3).fetch() offers = [] for trade in trades: offers.append(Offer.get_by_id(trade.offer)) return offers