コード例 #1
0
    def post(self):
        title = self.request.get('title')
        blurb = self.request.get('blurb')
        phone = self.request.get('phone')
        image = self.request.get('image')
        email = self.request.get('email')
        price = self.request.get('price')

        image_thumb = images.resize(image, 100, 100)
        image_medium = images.resize(image, 480, 480)
        image_small = images.resize(image, 200, 200)
        billboards = self.request.get('selected_billboards')
        billboards = [db.Key(key) for key in billboards.split(' ')]

        ad = Ad(title=title)
        ad.ip = self.request.remote_addr
        ad.sold = False
        ad.blurb = blurb
        ad.image = db.Blob(image)
        ad.image_thumb = db.Blob(image_thumb)
        ad.image_medium = db.Blob(image_medium)
        ad.image_small = db.Blob(image_small)
        ad.phone = db.PhoneNumber(phone)
        ad.email = db.Email(email)
        ad.price2 = int(price)
        ad.billboards = billboards
        ad.put()

        ad.password = hashlib.md5(SALT + ad.ip + str(ad.key())).hexdigest()
        ad.save()

        for billboard in db.get(billboards):
            billboard.ads.append(ad.key())
            billboard.put()

        path = os.path.join(os.path.dirname(__file__), 'success.html')
        self.response.out.write(
            template.render(
                path, {
                    'ad':
                    ad,
                    'secret_link':
                    'http://%s/ads/%s/edit?password=%s' %
                    (self.request.host, ad.key(), ad.password)
                }))
コード例 #2
0
 def parse_search_results(self):
     results = self.body.xpath(
         ".//div[contains(@class, 'offer_list_item')]")
     for item in results:
         print(etree.tostring(item))
         item_id = item.attrib["data-id"]
         pic = item.xpath(".//a[contains(@href, '" + item_id + "')]")
         if len(pic) == 0:
             continue
         item_url = self.url + pic[0].attrib["href"]
         item_online = item.xpath(
             ".//span[contains(text(), 'Online:')]")[0].text
         last_update = self.__get_last_update(item_online)
         assert last_update is not None, "Cant parse timestamp '%s'" % item_online
         ad = Ad(item_id, item_url)
         # Here we suppose that this ad was just created
         ad.created = last_update
         ad.last_update = last_update
         yield ad
コード例 #3
0
ファイル: admin.py プロジェクト: zouchao2010/cakeshop
    def post(self):
        url = self.get_argument("url", None)

        if self.request.files:
            ad = Ad()
            ad.url = url

            try:
                ad.validate()
                ad.save()

                filename = str(ad.id) + ".jpg"
                with open('upload/ad/' + filename, "wb") as f:
                    f.write(self.request.files["file"][0]["body"])

                self.flash(u"广告添加成功")
                self.redirect("/admin/ads")
                return
            except Exception, ex:
                self.flash(str(ex))