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


Python History.save方法代码示例

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


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

示例1: upload

# 需要导入模块: from models import History [as 别名]
# 或者: from models.History import save [as 别名]
def upload(request):
    if request.method == 'POST':
        form = SelfieForm(request.POST, request.FILES)
        if form.is_valid():
            instance = Selfie(photo=request.FILES['photo'])
            instance.user = request.user
            instance.info = form.cleaned_data["info"]
            instance.save()

            hist = History(selfie=instance, date=instance.pub_date, matches=0, score=1500)
            hist.save()

            img = Image.open(instance.photo.file)
            x1 = float(request.POST["x1"])
            x2 = float(request.POST["x2"])
            y1 = float(request.POST["y1"])
            y2 = float(request.POST["y2"])
            img.crop((x1, y1, x2, y2)).resize((640, 640)).save(instance.photo.file.file.name)

            print "new salfie: ", instance, "; anlisys result: ", instance.analyze()
            return HttpResponseRedirect(reverse('selfzone.panel:index'))
        return render(request, 'selfzone/uploadForm.html', {'form': form})
    else:
        form = SelfieForm()
        return render(request, 'selfzone/uploadForm.html', {'form': form})
开发者ID:cecco4,项目名称:selfzone_proj,代码行数:27,代码来源:views.py

示例2: garage_opened

# 需要导入模块: from models import History [as 别名]
# 或者: from models.History import save [as 别名]
def garage_opened(all_sensors, all_rules):
    garage = True
    for sensor in all_sensors:
        if sensor.name == 'Garage':
            sensor.open = True
            sensor.save()

    for rule in all_rules:
        if rule.rule_id == 1 and rule.is_enabled:
            msg = 'You left a window open! Close it to avoid a security risk before leaving.'
            Push.message(msg, channels=["Notifications"])
            history_item = History(Text=msg)
            history_item.save()
            message = sendgrid.Mail(to='[email protected]', subject='Allstate Hub Notification', html='', text=msg, from_email='[email protected]')
            status, mersg = sg.send(message)
        elif rule.rule_id == 3 and rule.is_enabled:
            # napi = nest.Nest(username, password)
            # for device in napi.devices:
            #     prev_nest_mode_garage = device.mode
            #     device.mode = 'off'
            print 'Nest mode set to off and previous state stored.'
        elif rule.rule_id == 4 and rule.is_enabled:
            msg = 'Make sure the alarm system is enabled!'
            Push.message(msg, channels=["Notifications"])
            history_item = History(Text=msg)
            history_item.save()
            message = sendgrid.Mail(to='[email protected]', subject='Allstate Hub Notification', html='', text=msg, from_email='[email protected]')
            status, mersg = sg.send(message)
开发者ID:mathur,项目名称:allstate_hub,代码行数:30,代码来源:app.py

示例3: addToHistory

# 需要导入模块: from models import History [as 别名]
# 或者: from models.History import save [as 别名]
    def addToHistory(self, song_instance, user_list):
        history_instance = History(
            Song=song_instance
        )
        history_instance.save()

        if user_list is not None and user_list.count() > 0:
            for user_instance in user_list.all():
                history_instance.User.add(user_instance)
开发者ID:rejahrehim,项目名称:jukebox,代码行数:11,代码来源:api.py

示例4: confirm_order

# 需要导入模块: from models import History [as 别名]
# 或者: from models.History import save [as 别名]
def confirm_order(request):
    cart=get_cart(request)
    history = History(id_user=request.user) 
    history.save() 
    for product in cart.id_products.all():
        product.quantity = product.quantity - 1
        history.id_product.add(product)
        product.save()
    history.save()
    cart.delete()    
    return redirect('home')
开发者ID:awpcourse,项目名称:onlineshop,代码行数:13,代码来源:views.py

示例5: move

# 需要导入模块: from models import History [as 别名]
# 或者: from models.History import save [as 别名]
def move():
    p_entry = History.query.descending('mongo_id').first()
    n_entry = History()
    n_entry = p_entry
    print p_entry.next_location.geocode[0]
    print p_entry.next_location.geocode[1]
    print p_entry.suggested_location.geocode[0]
    print p_entry.suggested_location.geocode[1],
    print p_entry.suggested_location.geocode[0] == p_entry.next_location.geocode[0]
    #if the bot is not moving
    
   
    if p_entry.status is False:
    	print "Fitz Owen is not moving, and.."
    	#if the bot has got a new suggestion, then move move move yo
    	if p_entry.next_location.geocode != p_entry.suggested_location.geocode:
    		print "there is a suggested destination :" + p_entry.suggested_location.name
    		n_entry.status = True
    		n_entry.previous_location = p_entry.next_location
    		n_entry.next_location = p_entry.suggested_location
    		distance = gcd(n_entry.previous_location.geocode[0], n_entry.previous_location.geocode[1], n_entry.next_location.geocode[0], n_entry.next_location.geocode[1])
    		n_entry.distance = distance
    		n_entry.number_of_segments = int(distance / p_entry.speed)
    		if (distance / p_entry.speed) < 1:
    			n_entry.number_of_segments = 1
    		print "Now moving towards" + n_entry.next_location.name +"..."
    	else :
    		print "okay, not moving"
    #if the bot is approaching the destination..
    elif p_entry.status is True:
    	if p_entry.segment is p_entry.number_of_segments:
    		print "got there!"
    		#then stop, and calibrate the location, reset
    		n_entry.status = False
    		n_entry.current_location = p_entry.next_location
    		n_entry.segment = 1
    	#Okay, now let's move..
    	else:
    		print "moving.."
    		lon = (p_entry.next_location.geocode[0] - p_entry.previous_location.geocode[0]) / p_entry.number_of_segments
    		lat = (p_entry.next_location.geocode[1] - p_entry.previous_location.geocode[1]) / p_entry.number_of_segments
    		xy = (p_entry.current_location.geocode[0]+lon,p_entry.current_location.geocode[1]+lat)
    		n_entry.current_location.geocode = xy
    		n_entry.segment = p_entry.segment + 1
    		print n_entry.segment 
    		print n_entry.number_of_segments
    n_entry.current_time = str(datetime.datetime.now())
    n_entry.save()
开发者ID:soloture,项目名称:wanderer,代码行数:50,代码来源:coordinate.py

示例6: smoke_on

# 需要导入模块: from models import History [as 别名]
# 或者: from models.History import save [as 别名]
def smoke_on(all_sensors, all_rules):
    smoke = True
    GPIO.output(4, 1)
    for sensor in all_sensors:
        if sensor.name == 'Smoke':
            sensor.open = True
            sensor.save()

    for rule in all_rules:
        if rule.rule_id == 6 and rule.is_enabled:
            msg = 'Smoke alarm was triggered!'
            Push.message(msg, channels=["Notifications"])
            history_item = History(Text=msg)
            history_item.save()
            message = sendgrid.Mail(to='[email protected]', subject='Allstate Hub Notification', html='', text=msg, from_email='[email protected]')
            status, mersg = sg.send(message)
开发者ID:mathur,项目名称:allstate_hub,代码行数:18,代码来源:app.py

示例7: crawl_user

# 需要导入模块: from models import History [as 别名]
# 或者: from models.History import save [as 别名]
def crawl_user(account):
    client = weibo.APIClient(app_key=settings.WEIBO_APPKEY, app_secret=settings.WEIBO_APPSECRET)
    client.set_access_token(account.access_token, 0)
    
    if settings.DEBUG:
        COUNT = 21
    else:
        COUNT = settings.WEIBO_API_MAX_COUNT
    id_func = lambda s:s.id 
    
    ##TODO: handle exception
    if not account.latest_status:
        all_statuses = client.statuses.home_timeline.get(count = COUNT).statuses
    else:
        statuses = client.statuses.home_timeline.get(since_id = account.latest_status.id, count = COUNT).statuses
        all_statuses = statuses
        
        while len(statuses) == COUNT:
            last_minid = min(map(id_func, statuses))
            ## The API will return the largest COUNT statuses whose id is larger than since_id
            ## so here is how we iterate to retrieve the entire set
            statuses = client.statuses.home_timeline.get(max_id = last_minid - 1, since_id = account.latest_status.id, count = COUNT).statuses
            all_statuses.extend(statuses)
            
    all_statuses.sort(key=id_func)
    ids = map(id_func, all_statuses)
    assert len(ids) == len(set(ids)) ## Sanity check: no duplicates in the list
    
    saved_statuses = map(store_status, all_statuses)
    for status in saved_statuses:
        ## If we encounter duplicated status, do not create history m2m again
        if not status.weiboaccount_set.exists():
            h = History()
            h.user = account
            h.status = status
            h.save()
    ## Move on if the status is 15 minutes old
    ## This is to deal with API sometimes having missing statuses in between (not even eventually consistent?!) 
    if saved_statuses:
        for i in reversed(range(len(saved_statuses))):
            if older_than(all_statuses[i].created_at, 15): 
                account.latest_status = saved_statuses[i]
                break
    account.save()
    return map(lambda s:s.id, saved_statuses)
开发者ID:xurubin,项目名称:WeiboObservatory,代码行数:47,代码来源:crawl.py

示例8: handle

# 需要导入模块: from models import History [as 别名]
# 或者: from models.History import save [as 别名]
        def handle(self, message):
		tel=message.connection.identity
		msg=message.text.lower().split(" ")

		if History.objects.filter(tel_num=tel):				
			"""The phone number is known in our system """
			for q in History.objects.filter(tel_num=tel):	#We pass on each question that we have to ask to the user
				if(q.status==1):
                                        #The question has been asked to the user but the response is not yet registered.So the incoming text message is the response.
					q.reponse=message.text
					q.status=2
					q.save()
				if(q.status==0):
                                        #The question is not yet asked to the user. We have to ask it to him or to her
					q.status=1
					q.save()
					quest=q.question
					message.respond(" %s " %(quest))
					return True
			message.respond("CONGRATULATION! YOU ARE REGISTERED IN OUR SYSTEM !")	#All questions we have prepared to ask to that user for his/her registration have got response
			return True
		elif msg[0]=='joindre':	
			"""The phone number is not known in our system and the user ask for registration"""
			for q in Questions.objects.all():
                                #We put all questions that we will ask to him/her in the table "History"
				h=History(question=q.question,tel_num=tel,status=0)
				h.save()
			if History.objects.filter(tel_num=tel):
                                #The question(s) for registration are available
				message.respond("WELCOME TO RAPIDSMS!")
			else:
				"""The question(s) for registration are not available 
                and the user must try again later to ask for registration 
                """
				message.respond("SORY, TRY AGAIN LATER!")
                        return True
		else:
			"""The phone number is not known in our system and the 
			system must inform to the user the mesage to send if he/she 
			want to be registered """
			message.respond("SORY YOU ARE NOT REGISTERED! TO REGISTER YOURSELF SEND <JOINDRE> !")
			return True
开发者ID:j3andidier,项目名称:sendsms,代码行数:44,代码来源:app.py


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