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


Python Task.delete方法代码示例

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


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

示例1: test_task_should_be_deletable

# 需要导入模块: from models import Task [as 别名]
# 或者: from models.Task import delete [as 别名]
 def test_task_should_be_deletable(self):
     """
     A Task should be deletable via the ORM
     """
     task = Task(description="Workout")
     task.save()
     self.assertTrue(Task.objects.all().exists())
     task.delete()
     self.assertFalse(Task.objects.all().exists())
开发者ID:freyes,项目名称:django-todo,代码行数:11,代码来源:tests.py

示例2: api_task

# 需要导入模块: from models import Task [as 别名]
# 或者: from models.Task import delete [as 别名]
def api_task(task_id=0):
    response = Response()
    response.content_type = 'application/json;charset=UTF-8'
    if request.method == 'DELETE':
        Task.delete(id_=task_id)
        response.response = json.dumps({'error': False, 'deleted': True, 'id_': task_id})
    elif request.method == 'GET':
        response.response = json.dumps(
            Task.list(column=request.args.get('column', 'A'))
        )
    else:
        task = Task(request.data)
        task.save()
        json_response = dict()
        json_response['error'] = False
        json_response['data'] = task.to_dict
        response.response = json.dumps(json_response)
    return response
开发者ID:wilson2cs,项目名称:todo-board,代码行数:20,代码来源:app.py

示例3: home

# 需要导入模块: from models import Task [as 别名]
# 或者: from models.Task import delete [as 别名]
def home(request):
    if request.method == 'POST':
        form = TaskForm(request.POST)
        if form.is_valid():
            cd = form.cleaned_data
           
            task = Task(name=cd['name'], target=cd['target'],
                task_type=cd['choice'],website=cd['target'],user=request.user, 
                created_time=datetime.datetime.now(),task_status=1, scrawl_deep =cd['deep'])
            task.save()
            task_request = task_Request(str(task.id),
                cd['target'],'job',cd['deep'],domain='subdomain' )
            flag = task_request.start()
            if not flag:
                task.delete()
            re = {"flag":flag,"task_id":task.id}
            re = json.dumps(re)
            
            return HttpResponse( re )
    else:
        form = TaskForm()
    return render_to_response('task_home.html',{'form':form }, RequestContext(request))
开发者ID:saltdealer,项目名称:space,代码行数:24,代码来源:views.py

示例4: ingest

# 需要导入模块: from models import Task [as 别名]
# 或者: from models.Task import delete [as 别名]
def ingest():
	"""View function for ingest. It takes json with items (by POST) to ingest or batch_id to show batch state."""
	
	### Show info about already started ingest (Batch) ###
	if request.method == 'GET':
		batch_id = request.args.get('batch_id', None)

		if batch_id is None:
			return "The batch ID must be provided", 400
		
		conn = sqlite3.connect(app.config['SQL_DB_URL'])
		c = conn.cursor()
		c.execute("SELECT batch_data FROM Batch WHERE batch_id=?", (batch_id,))

		try:
			batch_data = json.loads(c.fetchone()[0])
		except:
			return "Batch with provided ID doesn't exists", 400
		output = []
		
		for item in batch_data:
			item_id = item['id']
			tmp = {'id': item_id}
			
			item_tasks = []
			item_tasks_status = {}
			item_tasks_message = {}
			
			item_task_count = 1
			task_order = 0
			
			while item_task_count > task_order:
				try:
					task = Task(batch_id, item_id, task_order)
					item_tasks.append(task)
					item_task_count = task.item_tasks_count
					task_order += 1
					
					if not item_tasks_status.has_key(task.url) or (item_tasks_status.has_key(task.url) and item_tasks_status[task.url] != 'ok'):
						item_tasks_status[task.url] = task.status
						item_tasks_message[task.url] = task.message
							
				except:
					break

			if len(item_tasks) == 0:
				# tasks are in sqlite
				c.execute("SELECT * FROM Task WHERE batch_id=? AND item_id=?", (batch_id, item_id))

				for task in c.fetchall():
					task_status = task[3]
					task_url = task[4]
					task_message = task[5]
				
					if not item_tasks_status.has_key(task_url) or (item_tasks_status.has_key(task_url) and item_tasks_status[task_url] != 'ok'):
						item_tasks_status[task_url] = task_status
						item_tasks_message[task_url] = task_message
			else:
				#if item tasks are finished move them from redis to sqlite
				if not 'pending' in item_tasks_status.values():
					for task in item_tasks:
						c.execute("INSERT INTO Task VALUES (?,?,?,?,?,?)", (task.task_id, task.batch_id, task.item_id, task.status, task.url, task.message))
						task.delete()
					
					conn.commit()

			if item.has_key('status') and item['status'] == 'deleted':
				tmp['status'] = 'deleted'
				output.append(tmp)
				continue
				
			tmp['urls'] = []
				
			for url in item['url']:
				# actualy ingested url
				if item_tasks_status.has_key(url):
					tmp['urls'].append(item_tasks_status[url])
				# ingested url in past
				else:
					tmp['urls'].append('ok')
			
			if len(tmp['urls']) == 1:
				tmp.pop('urls', None)
			
			if 'error' in item_tasks_status.values():
				tmp['status'] = 'error'
				tmp['message'] = []
				
				for message in item_tasks_message.values():
					if message != ERR_MESSAGE_NONE:
						tmp['message'].append(ERR_MESSAGE_OUTPUT[message])
				
				if len(tmp['message']) == 1:
					tmp['message'] = tmp['message'][0]
				
			elif 'pending' in item_tasks_status.values():
				tmp['status'] = 'pending'
			else:
				tmp['status'] = 'ok'
			
#.........这里部分代码省略.........
开发者ID:tomkr,项目名称:hawk,代码行数:103,代码来源:views.py


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