def post(self, aid): aid = int(aid) try: ad = Ad.get(id = aid) except: self.flash("此广告不存在") self.redirect("/admin/ads") return url = self.get_argument("url", None) ad.url = url try: ad.validate() ad.save() if self.request.files: 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))
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
def get(self, aid): aid = int(aid) try: ad = Ad.get(id=aid) except: self.flash("此广告不存在") self.redirect("/admin/ads") return self.render('admin/editad.html', ad=ad)
def get(self, aid): aid = int(aid) try: ad = Ad.get(id = aid) except: self.flash("此广告不存在") self.redirect("/admin/ads") return self.render('admin/editad.html', ad = ad)
def get(self): ads = Ad.select().limit(6) newest = [] for shop in Shop.select(Shop.name, Shop.ename, Shop.cover, Shop.price).where((Shop.cid != 2) & (Shop.status != 9)).order_by(Shop.views.desc()).limit(6): shop.price = shop.price.split("~")[0] newest.append(shop) recomm = [] for shop in Shop.select(Shop.name, Shop.ename, Shop.cover, Shop.price).where(Shop.status == 1).limit(6): shop.price = shop.price.split("~")[0] recomm.append(shop) self.render("site/index.html", ads = ads, newest = newest, recomm = recomm)
def get(self): ads = Ad.select().limit(6) newest = [] for shop in Shop.select( Shop.name, Shop.ename, Shop.cover, Shop.price).where((Shop.cid != 2) & (Shop.status != 9)).order_by( Shop.views.desc()).limit(6): shop.price = shop.price.split("~")[0] newest.append(shop) recomm = [] for shop in Shop.select(Shop.name, Shop.ename, Shop.cover, Shop.price).where(Shop.status == 1).limit(6): shop.price = shop.price.split("~")[0] recomm.append(shop) self.render("site/index.html", ads=ads, newest=newest, recomm=recomm)
def get(self): ads = Ad.select().limit(6) newest = [] for shop in Shop.select(Shop.name, Shop.ename, Shop.cover, Shop.price).where((Shop.cid != 2) & (Shop.status != 9)).order_by(Shop.views.desc()).limit(6): shop.price = shop.price.split("~")[0] newest.append(shop) recomm = [] for shop in Shop.select(Shop.name, Shop.ename, Shop.cover, Shop.price).where(Shop.status == 1).limit(6): shop.price = shop.price.split("~")[0] recomm.append(shop) ccategory= None keyword = self.get_argument("keyword", None) page = int(self.get_argument("page", 1)) order = self.get_argument("order", None) pagesize = self.settings['admin_pagesize'] categorys = self.get_categorys() sq = Shop.select(Shop.name, Shop.ename, Shop.cover, Shop.price) total = sq.count() if ccategory: sq = sq.where((Shop.cid == ccategory.id) & (Shop.status != 9)) elif keyword: keyword = "%" + keyword + "%" sq = sq.where((Shop.name % keyword) & (Shop.status != 9)) else: sq = sq.where((Shop.cid != 2) & (Shop.status != 9)) if order: sq = sq.order_by(Shop.orders.desc()) else: sq = sq.order_by(Shop.views.desc()) shops = [] for shop in sq.paginate(page, pagesize): shop.price = shop.price.split("~")[0] shops.append(shop) self.render("responsive/index.html", ads = ads, newest = newest, recomm = recomm,ccategory = ccategory, categorys = categorys, shops = shops, total = total, page = page, pagesize = pagesize)
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))
def get(self): ads = [ad for ad in Ad.select()] self.render('admin/ad.html', ads=ads)
def get(self, aid): Ad.delete().where(Ad.id == aid).execute() self.flash(u"广告删除成功") self.redirect("/admin/ads")
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) }))
def get(self): ads = [ad for ad in Ad.select()] self.render('admin/ad.html', ads = ads)