def ico_pos_new(id, pos=None): if pos == ico_pos.get(id): return f = ico.get(id) if not f: return pic = picopen(fs_get_jpg(PIC_FULL_SIZE, f)) if not pic: return pic_id = pic_new(CID_ICO96, id) if pos: pos_tuple = pos.split('_') if len(pos_tuple) == 3: x, y, size = map(int, pos_tuple) if size: pic = pic_square(pic, size, top_left=(x, y), size=size) pic = pic_square(pic, 96, size=96) fs_set_jpg('96', pic_id, pic) ico_pos.set(id, pos or '') ico96.set(id, pic_id) from model.feed_po import mc_feed_user_dict mc_feed_user_dict.delete(id)
def ico_pos_new(id, pos=None): if pos == ico_pos.get(id): return f = ico.get(id) if not f: return pic = picopen(fs_get_jpg(PIC_FULL_SIZE, f)) if not pic: return pic_id = pic_new(CID_ICO96, id) if pos: pos_tuple = pos.split("_") if len(pos_tuple) == 3: x, y, size = map(int, pos_tuple) if size: pic = pic_square(pic, size, top_left=(x, y), size=size) pic = pic_square(pic, 96, size=96) fs_set_jpg("96", pic_id, pic) ico_pos.set(id, pos or "") ico96.set(id, pic_id) from model.feed_po import mc_feed_user_dict mc_feed_user_dict.delete(id)
def save_pic(pic, pic_url, event): pic = picopen(pic) if not pic: return else: pic_id = po_event_pic_new(event.zsite_id, pic) event.pic_id = pic_id event.save()
def post(self): errtip = Errtip() current_user = self.current_user current_user_id = current_user.id name = self.get_argument('name', None) motto = self.get_argument('motto', None) pid = self.get_arguments('pid', None) address = self.get_arguments('address', None) phone = self.get_argument('phone', None) pid_add = zip(pid, address) zsite = self.zsite if not name: errtip.name = '请输入名称' else: zsite.name = name zsite.save() if not motto: errtip.motto = '请编写签名' files = self.request.files pic_id = None if 'pic' in files: pic = files['pic'][0]['body'] pic = picopen(pic) if pic: pic_id = site_ico_new(current_user_id, pic) else: errtip.pic = '图片格式有误' else: pic_id = self.get_argument('pic_id', None) if not pic_id: errtip.pic = '请上传图片' if not errtip: current_user_id = self.current_user_id com_id = self.zsite_id zsite_com_new(com_id, phone=phone) site_ico_bind(current_user_id, pic_id, com_id) motto_set(com_id, motto) if pid_add: for pa in pid_add: zsite_com_place_new(com_id, int(pa[0]), pa[1]) else: pid_add = self.get_argument('pid_add', None) return self.redirect('/') return self.render( errtip=errtip, name=name, motto=motto, #txt=txt, phone=phone, pic_id=pic_id, pid_add=pid_add)
def _img(self): files = self.request.files img = files.get('photo') if img: img = img[0]['body'] if not len(img) > 1024*1024*12: img = picopen(img) if not img: return return img
def _upload_pic(files, current_user): error_pic = None if "pic" in files: pic = files["pic"][0]["body"] pic = picopen(pic) if pic: user_ico_new(current_user, pic) error_pic = False else: error_pic = "图片格式有误" return error_pic
def _upload_pic(files, current_user_id): error_pic = None if 'pic' in files: pic = files['pic'][0]['body'] pic = picopen(pic) if pic: ico_new(current_user_id, pic) error_pic = False else: error_pic = '图片格式有误' return error_pic
def _upload_pic(files, current_user): error_pic = None if 'pic' in files: pic = files['pic'][0]['body'] pic = picopen(pic) if pic: user_ico_new(current_user, pic) error_pic = False else: error_pic = '图片格式有误' return error_pic
def _product_save(self, product): current_user_id = self.current_user_id if not zsite_member_can_admin(self.zsite_id, current_user_id): return position = int(self.get_argument('position', 0)) origin = self.get_argument('origin', None) plan = self.get_argument('plan', None) similar_product_name = self.get_arguments('similar_product_name', None) similar_product_url = self.get_arguments('similar_product_url', None) same = self.get_argument('same', None) different = self.get_argument('different', None) advantage = self.get_argument('advantage', None) _product = self.get_argument('product', None) market = self.get_argument('market', None) product_similar = zip(similar_product_name, similar_product_url) _pro = [] if product_similar: for _name, _url in product_similar: if _name or _url: if _url: if not (_url.startswith('http://') or _url.startswith('https://')): _url = 'http://%s' % _url if not _name: _pro.append([urlparse(_url).netloc or _url, _url]) else: _pro.append([_name, _url]) product_similar = _pro pic_id = None files = self.request.files if product: if 'pic' in files: pic = files['pic'][0]['body'] pic = picopen(pic) if pic: pic_id = product_pic_new(self.zsite_id, product.id, pic) _info = JsDict(json.loads(product.txt or '{}')) _info.pic_id = pic_id _info.product_similar = product_similar _info.origin = origin _info.plan = plan _info.same = same _info.different = different _info.advantage = advantage _info.product = _product _info.market = market product.txt_set(json.dumps(dict(iter(_info)))) product.save()
def _product_save(self, product): current_user_id = self.current_user_id if not zsite_member_can_admin(self.zsite_id, current_user_id): return position = int(self.get_argument('position', 0)) origin = self.get_argument('origin', None) plan = self.get_argument('plan', None) similar_product_name = self.get_arguments('similar_product_name', None) similar_product_url = self.get_arguments('similar_product_url', None) same = self.get_argument('same', None) different = self.get_argument('different', None) advantage = self.get_argument('advantage', None) _product = self.get_argument('product', None) market = self.get_argument('market', None) product_similar = zip(similar_product_name, similar_product_url) _pro = [] if product_similar: for _name, _url in product_similar: if _name or _url: if _url: if not (_url.startswith('http://') or _url.startswith('https://')): _url = 'http://%s'%_url if not _name: _pro.append([urlparse(_url).netloc or _url, _url]) else: _pro.append([_name, _url]) product_similar = _pro pic_id = None files = self.request.files if product: if 'pic' in files: pic = files['pic'][0]['body'] pic = picopen(pic) if pic: pic_id = product_pic_new(self.zsite_id, product.id, pic) _info = JsDict(json.loads(product.txt or '{}')) _info.pic_id = pic_id _info.product_similar = product_similar _info.origin = origin _info.plan = plan _info.same = same _info.different = different _info.advantage = advantage _info.product = _product _info.market = market product.txt_set(json.dumps(dict(iter(_info)))) product.save()
def _bio_save(self, edit=None): hope = self.get_argument('hope', '', False).rstrip() money = self.get_argument('money', '', False).rstrip() culture = self.get_argument('culture', '', False).rstrip() team = self.get_argument('team', '', False).rstrip() video = self.get_argument('video', '') com_id = self.zsite.id files = self.request.files cover_id = None if 'cover' in files: cover = files['cover'][0]['body'] if cover: cover = picopen(cover) if cover: cover_id = com_pic_new(com_id, cover) for pic in files.get('pic', ()): if pic['body']: pic = picopen(pic['body']) if pic: com_pic_new(com_id, pic) if video: video_id = gid() video, video_site = video_filter(video) video_new(video_id, video) else: video_id = 0 video_site = None ppt = files.get('ppt') if ppt: ppt = ppt[0]['body'] ppt_new(com_id, ppt) zsite_com_new(com_id, hope, money, culture, team, cover_id, video_site, video_id)
def fetch_pic(url, referer=None): if url in exist: return exist[url] headers = {} if referer: headers['Referer'] = referer request = urllib2.Request(url, None, headers) raw = urlfetch(request) img = picopen(raw) exist[url] = img return img
def make_site(name, link, motto, img_src, site_num, current_user_id=10017321): f = urllib.urlopen(img_src).read() if f: pic = picopen(f) if pic: pic_id = site_ico_new(10017321, pic) site = site_new(name, current_user_id, 40) site_id = site.id site_ico_bind(current_user_id, pic_id, site_id) zsite_link = ZsiteLink.get_or_create(zsite_id=site_id, cid=2) zsite_link.link = link zsite_link.name = '豆瓣小站' zsite_link.save() mc_flush(site_id) motto_set(site_id, motto) rss_new(site_id, 'http://rss-tidy.42qu.com/douban/site/%s'%site_num, name, link, auto=1) print site_id
def make_site(name, link, motto, img_src, site_num, current_user_id=10017321): f = urllib.urlopen(img_src).read() if f: pic = picopen(f) if pic: pic_id = site_ico_new(10017321, pic) site = site_new(name, current_user_id, 40) site_id = site.id site_ico_bind(current_user_id, pic_id, site_id) zsite_link = ZsiteLink.get_or_create(zsite_id=site_id, cid=2) zsite_link.link = link zsite_link.name = '豆瓣小站' zsite_link.save() mc_flush(site_id) motto_set(site_id, motto) rss_new(site_id, 'http://rss-tidy.42qu.com/douban/site/%s' % site_num, name, link, auto=1) print site_id
def _post(self, id): user_id = self.current_user_id files = self.request.files img = files.get('img') if img: img = img[0]['body'] else: return 0 if len(img) > 1024 * 1024 * 12: return 2 img = picopen(img) if not img: return 10 if id: po = Po.mc_get(id) if not po or po.user_id != user_id or (po.cid == CID_WORD and po.rid == 0): return 0 if po.cid == CID_WORD: answer_word2note(po) if not pic_can_add(user_id, id): return 16 pic = po_pic_new(user_id, id, img) if not pic: return 14 r = { 'status': 0, 'src': fs_url_jpg(219, pic.id), 'seqid': pic.seq, } return r
def _post(self, id): user_id = self.current_user_id files = self.request.files img = files.get('img') if img: img = img[0]['body'] else: return 0 if len(img) > 1024*1024*12: return 2 img = picopen(img) if not img: return 10 if id: po = Po.mc_get(id) if not po or po.user_id != user_id or (po.cid == CID_WORD and po.rid == 0): return 0 if po.cid == CID_WORD: answer_word2note(po) if not pic_can_add(user_id, id): return 16 pic = po_pic_new(user_id, id, img) if not pic: return 14 r = { 'status': 0, 'src': fs_url_jpg(219, pic.id), 'seqid': pic.seq, } return r
def post(self): errtip = Errtip() current_user = self.current_user current_user_id = current_user.id name = self.get_argument('name', None) motto = self.get_argument('motto', None) url = self.get_argument('url', None) pid = self.get_arguments('pid', None) address = self.get_arguments('address', None) phone = self.get_argument('phone', None) pid_add = zip(pid, address) if not name: errtip.name = '请输入名称' if not motto: errtip.motto = '请编写签名' if url: errtip.url = url_valid(url) files = self.request.files pic_id = None if 'pic' in files: pic = files['pic'][0]['body'] pic = picopen(pic) if pic: pic_id = site_ico_new(current_user_id, pic) else: errtip.pic = '图片格式有误' else: pic_id = self.get_argument('pic_id', None) if not pic_id: errtip.pic = '请上传图片' if not errtip: com = com_new(name, current_user_id ) com_id = com.id zsite_com_new(com_id, phone=phone) site_ico_bind(current_user_id, pic_id, com_id) motto_set(com_id, motto) zsite_member_new(com_id, current_user_id, state=ZSITE_MEMBER_STATE_ACTIVE) if pid_add: for pa in pid_add: zsite_com_place_new(com_id, int(pa[0]), pa[1]) else: pid_add = self.get_argument('pid_add', None) if url: url_new(com_id, url) return self.redirect('%s/product/new'%com.link) return self.render( errtip=errtip, name=name, motto=motto, url=url, #txt=txt, phone=phone, pic_id=pic_id, pid_add=pid_add )
def po_event_edit_post(self, id, event, can_change, event_new): user_id = self.current_user_id if event: user_id = event.zsite_id errtip = Errtip() phone = self.get_argument('phone', '') address = self.get_argument('address', None) limit_up = self.get_argument('limit_up', '42') limit_down = self.get_argument('limit_down', '0') transport = self.get_argument('transport', '') price = self.get_argument('price', '0') pid = self.get_argument('pid', '1') event_cid = self.get_argument('event_cid', '') #print event_cid, "!!!!!!!!!!!" begin_time = self.get_argument('begin_time', '') end_time = self.get_argument('end_time', '') begin_time = self.get_argument('begin_time', '') begin_time_hour = self.get_argument('begin_time_hour', '0') begin_time_minute = self.get_argument('begin_time_minute', '0') end_time_hour = self.get_argument('end_time_hour', '0') end_time_minute = self.get_argument('end_time_minute', '0') if not can_change: city_pid = end = begin = None else: begin_time_hour = int(begin_time_hour) begin_time_minute = int(begin_time_minute) end_time_hour = int(end_time_hour) end_time_minute = int(end_time_minute) if begin_time_hour > 23 or begin_time_hour < 0: begin_time_hour = 10 if end_time_hour > 23 or end_time_hour < 0: end_time_hour = 11 if begin_time_minute > 59 or begin_time_minute < 0: begin_time_minute = 0 if end_time_minute > 59 or end_time_minute < 0: end_time_minute = 30 if begin_time: begin_time = int(begin_time) if end_time: end_time = int(end_time) if begin_time > end_time: end_time, begin_time = begin_time, end_time if begin_time < today_ymd_int(): errtip.begin_time = '这个时间 , 属于过去' begin = ymd2minute(begin_time)+begin_time_hour*60+begin_time_minute end = ymd2minute(end_time)+end_time_hour*60+end_time_minute if not event_cid.isdigit(): errtip.event_cid = '请选择类型' else: event_cid = int(event_cid) if event_cid not in EVENT_CID: errtip.event_cid = '请选择类型' if not pid.isdigit(): errtip.pid = '请选择地址' else: pid = int(pid) city_pid = pid_city(pid) if not city_pid: errtip.pid = '请选择地址' if price: try: price = float(price) except: errtip.price = '请输入有效的金额' if price < 0: errtip.price = '金额必须大于零' else: price = 0 if not limit_down.isdigit(): limit_down = 0 else: limit_down = int(limit_down) if not limit_up.isdigit(): limit_up = 42 else: limit_up = int(limit_up) if limit_down > limit_up: limit_up, limit_down = limit_down, limit_up if limit_down < 0: errtip.limit_down = '人数不能为负数' if not address: errtip.address = '请输入详细地址' if not phone: errtip.phone = '请输入联系电话' pic_id = None files = self.request.files if 'pic' in files: pic = files['pic'][0]['body'] pic = picopen(pic) if not pic: errtip.pic = '图片格式有误' else: pic_id = po_event_pic_new(user_id, pic) if not pic_id: pic_id = self.get_argument('pic_id', None) if pic_id: o = Pic.get(pic_id) if not (o and o.cid == CID_EVENT): pic_id = None if not pic_id: errtip.pic = '请上传图片' if errtip: self.render( event=event, errtip=errtip, address=address, pic_id=pic_id, limit_up=limit_up, limit_down=limit_down, transport=transport, price=price, phone=phone, pid=pid, event_cid=event_cid, begin_time=begin_time if can_change else 0, end_time=end_time if can_change else 0, begin_time_hour=begin_time_hour, begin_time_minute=begin_time_minute, end_time_hour=end_time_hour, end_time_minute=end_time_minute, ) return else: event = event_new( user_id, event_cid, city_pid, pid, address, transport, begin, end, int(100*price), limit_up, limit_down, phone, pic_id, id ) return event
def post(self): errtip = Errtip() current_user = self.current_user current_user_id = current_user.id name = self.get_argument('name', None) motto = self.get_argument('motto', None) pid = self.get_arguments('pid', None) address = self.get_arguments('address', None) phone = self.get_argument('phone', None) pid_add = zip(pid, address) zsite = self.zsite if not name: errtip.name = '请输入名称' else: zsite.name = name zsite.save() if not motto: errtip.motto = '请编写签名' files = self.request.files pic_id = None if 'pic' in files: pic = files['pic'][0]['body'] pic = picopen(pic) if pic: pic_id = site_ico_new(current_user_id, pic) else: errtip.pic = '图片格式有误' else: pic_id = self.get_argument('pic_id', None) if not pic_id: errtip.pic = '请上传图片' if not errtip: current_user_id = self.current_user_id com_id = self.zsite_id zsite_com_new(com_id, phone=phone) site_ico_bind(current_user_id, pic_id, com_id) motto_set(com_id, motto) if pid_add: for pa in pid_add: zsite_com_place_new(com_id, int(pa[0]), pa[1]) else: pid_add = self.get_argument('pid_add', None) return self.redirect('/') return self.render( errtip=errtip, name=name, motto=motto, #txt=txt, phone=phone, pic_id=pic_id, pid_add=pid_add )
def _site_save(self): arguments = self.request.arguments current_user = self.current_user current_user_id = current_user.id link_cid = [] link_kv = [] errtip = Errtip() name = self.get_argument('name', None) motto = self.get_argument('motto', None) url = self.get_argument('url', None) txt = self.get_argument('txt', None) for cid, link in zip(arguments.get('cid', []), arguments.get('link', [])): cid = int(cid) link_name = SITE_LINK_ZSITE_DICT[cid] link_cid.append( (cid, link_name, linkify(link, cid)) ) for id, key, value in zip( arguments.get('id', []), arguments.get('key', []), arguments.get('value', []) ): id = int(id) link = linkify(value) link_kv.append( (id, key.strip() or urlparse(link).netloc, link) ) files = self.request.files pic_id = None if 'pic' in files: pic = files['pic'][0]['body'] pic = picopen(pic) if pic: pic_id = site_ico_new(current_user_id, pic) else: errtip.pic = '图片格式有误' else: pic_id = self.get_argument('pic_id', None) if not pic_id: errtip.pic = '请上传图片' if not name: errtip.name = '请输入名称' if not motto: errtip.motto = '请编写签名' if url: errtip.url = url_valid(url) if errtip: for cid, link_name in SITE_LINK_NAME: if cid not in set(i[0] for i in link_cid): link_cid.append( ( cid, link_name, '' ) ) return errtip, link_cid, link_kv, name, motto, url, txt, pic_id