当前位置: 首页>>代码示例>>Python>>正文


Python User.saveDB方法代码示例

本文整理汇总了Python中user.User.saveDB方法的典型用法代码示例。如果您正苦于以下问题:Python User.saveDB方法的具体用法?Python User.saveDB怎么用?Python User.saveDB使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在user.User的用法示例。


在下文中一共展示了User.saveDB方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: suggestion

# 需要导入模块: from user import User [as 别名]
# 或者: from user.User import saveDB [as 别名]
def suggestion(request):
	if request.is_ajax() and request.method=='GET':
		try:
			user_id = request.GET['user_id']
		except KeyError:
			return HttpResponse(dumps({'status':'ERR', 'data':'No user id'}, cls=MyEncoder), mimetype='application/json')
		
		
		u=User(user_id)
		
		try:
			if re.search('[^a-zA-Z0-9_]',user_id):
				raise NotFound
			pin_list=u.getToRepin(10)
			u.saveDB()
		except NotFound:
			return HttpResponse(dumps({'status':'ERR', 'data':'Wrong name, nobody have this name on pinterest'}, cls=MyEncoder), mimetype='application/json')
		
		if not pin_list:
			print 'not_pinlist'
			pin_list=[Pin.modelToPin(p) for p in random.sample(PinModel.objects.all(),10)]
		res = {'status':'OK', 'data':{'pin_list':pin_list,'user':u}, }
		return HttpResponse(dumps(res, cls=MyEncoder), mimetype='application/json')
	else:
		FB_INFO['meta']=None
		return render_to_response('map/suggestion.html', {'fb_info':FB_INFO,})
开发者ID:cinequant,项目名称:pinalyzer,代码行数:28,代码来源:views.py

示例2: quizz

# 需要导入模块: from user import User [as 别名]
# 或者: from user.User import saveDB [as 别名]
def quizz(request):	
	if request.is_ajax() and request.method=='GET':
		try:
			user_id = request.GET['user_id']
		except KeyError:
			return HttpResponse(dumps({'status':'ERR', 'data':'No user id'}, cls=MyEncoder), mimetype='application/json')
		
		try:
			user_m=UserModel.objects.get(user_id=user_id)
		except UserModel.DoesNotExist:
			x=User(user_id)
			x.fetchUser()
			user_m=x.saveDB()
	
		user_m.quizzvotemodel_set.all().delete();
		ref_list=[[x.pin1,x.pin2,True] for x in list(MatchModel.objects.all()[:5])]
		s=random.sample(list(PinModel.objects.all()),10)
		rand_list=[[s[i],s[i+1],False] for i in range(0,len(s),2)]
		match_list=fun.shuffle(ref_list+rand_list);	
		res = {'status':'OK', 'data':{'match_list':match_list,}, }
		return HttpResponse(dumps(res, cls=MyEncoder), mimetype='application/json')
	else:
		try:
			user_id = request.GET['user_id']
		except KeyError:
			return render_to_response('map/quizzform.html', {'fb_info':FB_INFO})
		return render_to_response('map/quizz.html', {'fb_info':FB_INFO,'user_id':user_id})
开发者ID:cinequant,项目名称:pinalyzer,代码行数:29,代码来源:views.py

示例3: score_page

# 需要导入模块: from user import User [as 别名]
# 或者: from user.User import saveDB [as 别名]
def score_page(request):
	try:
		user_id = request.GET['user']
		user = UserModel.objects.get(user_id=user_id)
		d=datetime.datetime.now()
		if not user.latest_stat():
			u=User(user_id)
			u.fetchScoring()
			u.saveDB()
		print user.get_stat_history()
		FB_INFO['meta'] = {'type':'person',
						'title': user.name,
						'image':'http://'+request.get_host()+'/score_img?user_id='+user_id+'&date='+str(d.day)+'_'+str(d.month)+'_'+str(d.year),
						'description': user.name + '\'s pinterest score is '+str(round(user.latest_stat().score(),1))+' on pinalyzer.com',
						'url':request.build_absolute_uri(),
						}
	except (KeyError, UserModel.DoesNotExist):
		pass
	return render(request, 'map/score.html', {'fb_info':FB_INFO})
开发者ID:cinequant,项目名称:pinalyzer,代码行数:21,代码来源:views.py

示例4: get_score

# 需要导入模块: from user import User [as 别名]
# 或者: from user.User import saveDB [as 别名]
def get_score(request):
	if request.is_ajax() and request.method == 'POST':
		try:
			user_id = request.POST['user_id']
			
		except KeyError:
			return HttpResponse(dumps({'status':'ERR', 'data':'No user_id in post param'}, cls=MyEncoder), mimetype='application/json')
		
		if re.search('[^a-zA-Z0-9_]',user_id):
			return HttpResponse(dumps({'status':'ERR', 'data':'Wrong name, nobody have this name on pinterest'}, cls=MyEncoder), mimetype='application/json')
		
		try:
			user = UserModel.objects.get(user_id=user_id)
			d = datetime.datetime.now()
			stat = user.userstatmodel_set.get(date__year=d.year, date__month=d.month, date__day=d.day)
		except (UserModel.DoesNotExist,UserStatModel.DoesNotExist):
			u = User(user_id)
			try:
				u.fetchUser()
				u.fetchScoring()
				user = u.saveDB()
			except NotFound:
				return HttpResponse(dumps({'status':'ERR', 'data':'Wrong name, nobody have this name on pinterest'}, cls=MyEncoder), mimetype='application/json')

		info_open_graph = []
		try:
			fb_id = request.POST['fb_id']
			if fb_id == 'null':
				raise KeyError
			fb_u = SocialUserModel.objects.get_or_create(social_id=fb_id, net_name="facebook")[0]
			d=datetime.datetime.now()
			info_open_graph.append({'fb_id':fb_id, 'action':'rate', 'obj':'person', 'obj_url':'http://'+request.get_host()+'/score?user='+user.user_id+'&date='+str(d.day)+'_'+str(d.month)+'_'+str(d.year)})
		except KeyError:
			pass
		
		stat_hist=user.userstatmodel_set.all().order_by('date')
		
		
		followers_hist=[]
		following_hist=[]
		pin_hist=[]
		liked_hist=[]
		board_hist=[]
		score_hist=[]
		repin_hist=[]
		comment_hist=[]
		like_hist=[]

		for s in stat_hist:
			epoch=time.mktime(s.date.timetuple())*1000
			followers_hist.append([epoch, s.nb_followers])
			following_hist.append([epoch, s.nb_following])
			pin_hist.append([epoch, s.nb_pin])
			liked_hist.append([epoch, s.nb_liked])
			board_hist.append([epoch, s.nb_board])
			score_hist.append([epoch, s.score()])
			repin_hist.append([epoch, s.nb_repin])
			comment_hist.append([epoch, s.nb_comment])
			like_hist.append([epoch, s.nb_like])
			
		all_hist={'followers_hist':followers_hist,
					'following_hist':following_hist,
					'pin_hist':pin_hist,
					'liked_hist':liked_hist,
					'board_hist':board_hist,
					'score_hist':score_hist,
					'repin_hist':repin_hist,
					'comment_hist':comment_hist,
					'like_hist':like_hist,
		}
		res = {'status':'OK', 'data':{'user':user, 
									'all_hist':all_hist,
									'info_open_graph':info_open_graph }, }
		return HttpResponse(dumps(res, cls=MyEncoder), mimetype='application/json')
开发者ID:cinequant,项目名称:pinalyzer,代码行数:76,代码来源:views.py


注:本文中的user.User.saveDB方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。