def get_hot_tags(request): if request.method == 'GET': res = {} token = request.GET.get('token', None) db = MongoConn.find_one('token_ttl', {'token': token}) if not db: tmp = {} tmp['errcode'] = UNLOGIN return HttpResponse( json_util.dumps(tmp, ensure_ascii=False), content_type='application/x-www-form-urlencoded;charset=utf-8') effect_tags = MongoConn.find('effect_tags', None).sort('use_count', DESCENDING).limit(10) summary_tags = MongoConn.find('summary_tags', None).sort('use_count', DESCENDING).limit(10) res['effect_tags'] = [] res['summary_tags'] = [] for tag in effect_tags: res['effect_tags'].append(tag.get('_id', None)) for tag in summary_tags: res['summary_tags'].append(tag.get('_id', None)) res['errcode'] = OK return HttpResponse( json_util.dumps(res, ensure_ascii=False), content_type='application/x-www-form-urlencoded;charset=utf-8')
def get_banner(request): if request.method == 'GET': res = [] items = MongoConn.find('banner', None) for item in items: tmp = {} tmp['id'] = item['_id'] tmp['image'] = item['image'] tmp['url'] = item['url'] res.append(tmp) logging.info(tmp) return HttpResponse( json_util.dumps(res, ensure_ascii=False), content_type='application/x-www-form-urlencoded;charset=utf-8')
def upload_skin_record(request): if request.method == 'POST': res = {} req = json.loads(request.body) logging.info(req) token = req.get('token', None) product_record_id = req.get('product_record_id', None) skin_images = req.get('skin_images', None) summary_tags = req.get('summary_tags', None) if not token or not product_record_id or not skin_images or len( skin_images) < 1 or len(skin_images) > 2: res['errcode'] = PARAMERR return HttpResponse( json_util.dumps(res, ensure_ascii=False), content_type='application/x-www-form-urlencoded;charset=utf-8') db = MongoConn.find_one('token_ttl', {'token': token}) if not db: res['errcode'] = UNLOGIN return HttpResponse( json_util.dumps(res, ensure_ascii=False), content_type='application/x-www-form-urlencoded;charset=utf-8') openid = db.get('openid') update_tags_frequency(None, summary_tags) # today = datetime.datetime.now().strftime("%Y%m%d") # if not check_publish_limit(openid, product_record_id): # res['errcode'] = PUBLISHLIMIT # return HttpResponse(json_util.dumps(res,ensure_ascii=False),content_type='application/x-www-form-urlencoded;charset=utf-8') skin_record = {} skin_record['pics'] = skin_images skin_record['tags'] = summary_tags # skin_record['create_time'] = today skin_record['create_time'] = datetime.datetime.utcnow() skin_record_id = MongoConn.insert('skin_record', skin_record) db_product_record = MongoConn.find_one( 'product_record', {'_id': ObjectId(product_record_id)}) db_skin_record_list = db_product_record.get('skin_record', None) if db_skin_record_list: db_skin_record_list.append(str(skin_record_id)) MongoConn.save('product_record', db_product_record) else: res['errcode'] = PARAMERR return HttpResponse( json_util.dumps(res, ensure_ascii=False), content_type='application/x-www-form-urlencoded;charset=utf-8') db_product_record['update_time'] = datetime.datetime.utcnow() MongoConn.save('product_record', db_product_record) update_publish_limit(openid, product_record_id, skin_record_id) days = MongoConn.find('record_limit', { 'open_id': openid }).distinct('date') days_num = len(days) # days_num = MongoConn.distinct('record_limit', 'date', {'open_id' : openid}) logging.info(days_num) user_record = {} user_record['_id'] = openid user_record['product_record_num'] = 1 user_record['record_days_num'] = days_num user_record['record_pic_num'] = len(skin_images) user_record['product_record'] = [] user_record['product_record'].append(str(product_record_id)) user_record['last_record_time'] = datetime.datetime.utcnow() db_record = MongoConn.find_one('user_record', {'_id': openid}) if not db_record: MongoConn.insert('user_record', user_record) else: # days_num = MongoConn.find_one('record_limit', {'openid':openid, 'product_record_id':product_record_id, 'date':date}) db_record['record_days_num'] = days_num db_record['record_pic_num'] += len(skin_images) db_record['last_record_time'] = datetime.datetime.utcnow() MongoConn.save('user_record', db_record) res['errcode'] = OK return HttpResponse( json_util.dumps(res, ensure_ascii=False), content_type='application/x-www-form-urlencoded;charset=utf-8')
def upload_product_record(request): if request.method == 'POST': res = {} # logging.info(request.POST) # token = request.POST.get('token') # product_name = request.POST.get('product_name', None) # product_image = request.POST.get('product_image', None) # product_tags = request.POST.get('product_tags', None) # skin_images = request.POST.get('skin_images', None) # summary_tags = request.POST.get('summary_tags', None) req = json.loads(request.body) logging.info(req) token = req.get('token', None) product_name = req.get('product_name', None) product_image = req.get('product_image', None) product_tags = req.get('product_tags', None) skin_images = req.get('skin_images', None) summary_tags = req.get('summary_tags', None) if not product_name or not product_image or not skin_images or len( skin_images) < 1 or len(skin_images) > 2: res['errcode'] = PARAMERR return HttpResponse( json_util.dumps(res, ensure_ascii=False), content_type='application/x-www-form-urlencoded;charset=utf-8') db = MongoConn.find_one('token_ttl', {'token': token}) if not db: res['errcode'] = UNLOGIN return HttpResponse( json_util.dumps(res, ensure_ascii=False), content_type='application/x-www-form-urlencoded;charset=utf-8') openid = db.get('openid') update_tags_frequency(product_tags, summary_tags) # today = datetime.datetime.now().strftime("%Y%m%d") skin_record = {} skin_record['pics'] = skin_images skin_record['tags'] = summary_tags # skin_record['create_time'] = today skin_record['create_time'] = datetime.datetime.utcnow() skin_record_id = MongoConn.insert('skin_record', skin_record) # tmp_time = MongoConn.find_one('skin_record', {'_id' : ObjectId(skin_record_id)}).get('create_time') + datetime.timedelta(hours = 8) # res['time'] = time.mktime(tmp_time.timetuple()) product_record = {} product_record['name'] = product_name product_record['image'] = product_image product_record['tags'] = product_tags product_record['skin_record'] = [] product_record['skin_record'].append(str(skin_record_id)) product_record['create_time'] = datetime.datetime.utcnow() product_record['update_time'] = datetime.datetime.utcnow() product_record_id = MongoConn.insert('product_record', product_record) update_publish_limit(openid, product_record_id, skin_record_id) # record_limit = {} # record_limit['open_id'] = openid # record_limit['product_record_id'] = str(product_record_id) # record_limit['skin_record_id'] = str(skin_record_id) # record_limit['date'] = today # MongoConn.insert('record_limit', record_limit) days = MongoConn.find('record_limit', { 'open_id': openid }).distinct('date') days_num = len(days) # days_num = MongoConn.distinct('record_limit', 'date', {'open_id' : openid}) logging.info(days_num) user_record = {} user_record['_id'] = openid user_record['product_record_num'] = 1 user_record['record_days_num'] = days_num user_record['record_pic_num'] = len(skin_images) user_record['product_record'] = [] user_record['product_record'].append(str(product_record_id)) user_record['last_record_time'] = datetime.datetime.utcnow() db_record = MongoConn.find_one('user_record', {'_id': openid}) if not db_record: MongoConn.insert('user_record', user_record) else: db_record['product_record_num'] += 1 # days_num = MongoConn.find_one('record_limit', {'openid':openid, 'product_record_id':product_record_id, 'date':date}) db_record['record_days_num'] = days_num db_record['record_pic_num'] += len(skin_images) db_record['product_record'].append(str(product_record_id)) db_record['last_record_time'] = datetime.datetime.utcnow() MongoConn.save('user_record', db_record) res['product_record_id'] = str(product_record_id) res['errcode'] = OK return HttpResponse( json_util.dumps(res, ensure_ascii=False), content_type='application/x-www-form-urlencoded;charset=utf-8')