def new(self, request): cart = models.Cart(creation_date=datetime.datetime.now()) cart.save() request.session[CART_ID] = cart.id return cart
def new(self): cart = models.Cart(creation_date=datetime.datetime.now()) cart.save() return cart
def new(self, request, user=None): cart = models.Cart(creation_date=timezone.now(), user=user) cart.save() request.session[CART_ID] = cart.id return cart
def get_cart(self): utf8_parser = etree.HTMLParser(encoding='utf-8') tree = etree.fromstring(self.br.response().read().decode('utf-8'), parser=utf8_parser) node = tree.xpath('//*[@id="sc_menuhub"]') if node: m = re.search("\((\d+) articles", node[0].text) na = 0 if m: na = int(m.group(1)) if na == 0: return models.Cart() link = self.br.find_link(url="/?mainPage=showShoppingCart") self.br.follow_link(link) tree = etree.fromstring(self.br.response().read().decode('utf-8'), parser=utf8_parser) # create cart c = models.Cart(tree.xpath('//*[@id="sc_hashCode"]/@value')[0]) # ships for shipnode in tree.xpath('//div[@class="sc_ShipTable"]'): # id shipid = int(shipnode.xpath('div/@id')[0].split('_')[-1]) # hash bhash = shipnode.xpath('.//button/@onclick')[0] m = re.search("jcp\('([^']+)'", bhash) if m: bhash = m.group(1) # sumary sumarynode = shipnode.xpath('.//table[@class="nestedContent"]')[2] # read seller node = sumarynode.xpath( './/a[contains(@href, "showSellerChart")]')[1] seller = models.Seller(id=node.attrib['href'], name=node.text) # ship s = models.Ship(shipid, bhash, c, seller) # shipping node = sumarynode.xpath('tr[6]/td[2]/text()')[0] m = re.search("([\d,]+) ", node) if m: s.shipping = float(m.group(1).replace(',', '.')) # shipping method node = None for tr in sumarynode.xpath('tr'): td = tr.xpath('td/text()')[0] if td.find('Shipping Method') != -1: node = tr if node is not None: m = re.search("\(([\w\s]+)\)", etree.tostring(node)) if m: s.shipping_method = m.group(1) # items for item in shipnode.xpath( './/form[contains(@name, "itemViewForm")]/table/tbody/tr'): idcard = item.xpath('td[2]/a/@href')[0] namecard = item.xpath('td[2]/a/text()')[0] pricecard = item.xpath('td[9]/text()')[0] m = re.search("([\d,]+) ", pricecard) if m: pricecard = float(m.group(1).replace(',', '.')) langcard = item.xpath('td[5]/a/span/@onmouseover')[0] m = re.search("\('([\w\s]+)'\)", langcard) if m: langcard = m.group(1) expansion = item.xpath('td[3]/span/@onmouseover')[0] m = re.search("\('([\w\s]+)'\)", expansion) if m: expansion = m.group(1) condition = item.xpath('td[6]/a/img/@onmouseover')[0] m = re.search("\('([\w\s]+)'\)", condition) if m: condition = m.group(1) quantity = int(item.xpath('td[2]/text()')[0][0:-2]) card = models.Card(idcard, namecard) cardarticle = models.CardArticle(card, pricecard, langcard, expansion, condition, quantity) s.articles.append(cardarticle) c.ships.append(s) return c
def new(self, request): cart = models.Cart(creation_date=datetime.datetime.now()) cart.save() request.session[CART_ID] = cart.id # @@ send signal with cart id and request for further actions return cart