本文整理汇总了Python中models.Task.save方法的典型用法代码示例。如果您正苦于以下问题:Python Task.save方法的具体用法?Python Task.save怎么用?Python Task.save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Task
的用法示例。
在下文中一共展示了Task.save方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: addtask
# 需要导入模块: from models import Task [as 别名]
# 或者: from models.Task import save [as 别名]
def addtask(request):
# email = request.POST.get('owner', '')
title = request.POST.get('title', '')
description = request.POST.get('description', '')
collaborator1 = request.POST.get('collaborator1', '')
collaborator2 = request.POST.get('collaborator2', '')
collaborator3 = request.POST.get('collaborator3', '')
uid = request.session['mid']
userobj = User.objects.get(id=uid)
# because collaborators is a multi entry field, you have to add collaborators after creating the new task
# I'm not sure why save goes above adding collaborators, but the code broke when the save was not above
new_Task = Task(owner=userobj, title=title, description=description)
new_Task.save()
if collaborator1 != '':
collaboratored = User.objects.filter(email = collaborator1)
coll = collaboratored[0]
new_Task.collaborators.add(coll)
if collaborator2 != '':
collaboratored = User.objects.filter(email = collaborator2)
coll = collaboratored[0]
new_Task.collaborators.add(coll)
if collaborator3 != '':
collaboratored = User.objects.filter(email = collaborator3)
coll = collaboratored[0]
new_Task.collaborators.add(coll)
# new_Task.save()
return HttpResponseRedirect ('/tasks/')
示例2: _add_task
# 需要导入模块: from models import Task [as 别名]
# 或者: from models.Task import save [as 别名]
def _add_task(data, user, id=0):
logger.debug("Task name = %s", data[NAME])
if id:
# get existing task
task = Task.objects.get(pk=id)
if not task.editable:
raise IgniteException(ERR_TASK_NOT_EDITABLE)
else:
# create new task
task = Task()
task.name = data[NAME]
task.handler = data[HANDLER]
task.function = data[FUNCTION]
task.desc = data[DESCRIPTION]
task.location_access_protocol = data[LOC_ACCESS_PROTO]
task.location_server_ip = data[LOC_SERVER_IP]
task.location_server_user = data[LOC_SERVER_USER]
password = encrypt_data(data[LOC_SERVER_PASSWORD])
task.location_server_password = password
task.is_encrypted = True
task.parameters = data[PARAMETERS]
task.updated_by = user
task.save()
return task
示例3: post
# 需要导入模块: from models import Task [as 别名]
# 或者: from models.Task import save [as 别名]
def post(self, request):
# validate the form
# validate the form
form = DBSCANForm(request.POST)
if form.is_valid():
task = Task()
task.method = 'dbscan'
task.params = {
'eps': form.cleaned_data['eps'],
'min_samples': form.cleaned_data['min_samples'],
'metric': form.cleaned_data['metric']
}
task.running = False
task.duration = datetime.timedelta(0)
task.save()
if 'run' in request.POST:
return redirect('/cluster/run/'+str(task.id))
return redirect('/cluster')
return render(request, self.template_name, {
'form': form
});
示例4: addTask
# 需要导入模块: from models import Task [as 别名]
# 或者: from models.Task import save [as 别名]
def addTask(request):
"""Add a task"""
d = {}
pagename = request.POST["pagename"]
page = TaskPage.objects.get(name__iexact=pagename)
if "taskid" not in request.POST.keys():
t = Task()
t.text = request.POST["taskcontent"]
t.page = page
t.save()
d["message"] = "Successfully added the task"
d["text"] = t.text
d["taskid"] = t.id
d["update"] = 0
else:
taskid = int(request.POST["taskid"])
giventask = Task.objects.get(pk=taskid)
giventask.text = request.POST["taskcontent"]
giventask.save()
d["message"] = "Successfully updated the task"
d["text"] = urlize(giventask.text)
d["taskid"] = giventask.id
d["update"] = 1
# return all the tasks
d["error"] = "0"
json = simplejson.dumps(d)
return HttpResponse(json)
示例5: tasks
# 需要导入模块: from models import Task [as 别名]
# 或者: from models.Task import save [as 别名]
def tasks(request):
# tasks supports GET and POST
if request.method == "GET":
# GET should return all of the tasks
# first, create a list of tasks
raw_tasks = []
for task in Task.objects.all():
raw_tasks.append(task_to_raw(task))
# now, create and return json (remember, front-end wants it in "contents")
return_data = {"content": raw_tasks}
return HttpResponse(json.dumps(return_data), mimetype="application/json")
elif request.method == "POST":
# Create a Task
task = Task()
# Load data
raw = json.loads(request.raw_post_data)
raw_to_task(raw, task)
# attempt to save
task.save()
# return just the plain hash
# returning Location header causes problems
response = HttpResponse(json.dumps({"content": task_to_raw(task)}))
response.status = 201
return response
示例6: save_task
# 需要导入模块: from models import Task [as 别名]
# 或者: from models.Task import save [as 别名]
def save_task(request):
""" Save a new task or update an old one.
"""
tids = request.POST.get('t_id','')
if '-' in tids:
item, task = tids.split('-')
else:
item = tids
task = None
logger.debug('save_task: item=%s, task=%s'%(item,task))
tname = request.POST.get('tname','')
ttech = request.POST.get('ttech','')
# est = request.POST.get('testimate','')
notes = request.POST.get('tnotes','')
if task:
logger.debug('save_task: update SprintTask, id=%s'%task)
t = Task.objects.get(pk=int(task))
else:
logger.debug('save_task: new SprintTask,item_id=%s'%item)
try:
itm = Backlog.objects.get(pk=item)
except:
logger.error('save_task: Backlog(%s) not found in db'%item)
return HttpResponse('{"error":"%s"}'%_('Backlog item not found, please check.'))
t = Task(item=itm)
t.name = tname
t.technology = ttech
t.notes = notes
t.number = int(time.time()) % 1000000000
try:
t.save()
return HttpResponse('{"status":"OK","item":"%s","task":"%s"}' % (item, t.pk))
except Exception,e:
logger.error('save_task error: %s'%e)
return HttpResponse('{"error":"%s"}'%_('Error saving task, retry later.'))
示例7: project
# 需要导入模块: from models import Task [as 别名]
# 或者: from models.Task import save [as 别名]
def project(request, project_id):
project = get_object_or_404(Project, id=project_id)
if request.method == 'POST':
form = UploadFabFileForm(request.POST, request.FILES)
if form.is_valid():
fabfile = request.FILES['file']
content = fabfile.readlines()
import_block, tasks = get_source(content)
project.import_block = import_block
project.save()
stage = Stage(name="Imported", project=project)
stage.save()
stage_user = StageUser(user=request.user, stage=stage)
stage_user.save()
for task in tasks:
task_obj = Task(name=task['name'], body=task['body'])
task_obj.save()
stage_task = StageTask(task=task_obj, stage=stage)
stage_task.save()
else:
form = UploadFabFileForm()
stages = project.stage_set.order_by('name',)
deployments = Deploy.objects.filter(stage__in=stages).order_by('-finished_at',)[:3]
return {'p': project, 'stages': stages, 'deps': deployments, 'form': form}
示例8: generate_task
# 需要导入模块: from models import Task [as 别名]
# 或者: from models.Task import save [as 别名]
def generate_task(self, sp_id, name):
subprocess = SubProcess.objects.get(id=sp_id)
task = Task(subprocess=subprocess, name=name)
task.save()
return task
示例9: add_processor_jobs
# 需要导入模块: from models import Task [as 别名]
# 或者: from models.Task import save [as 别名]
def add_processor_jobs(sms):
for processor in Processor.objects.all():
if processor.receiver == sms.received:
task = Task()
task.message = sms
task.processor = processor
task.processed = False
task.save()
示例10: new_task
# 需要导入模块: from models import Task [as 别名]
# 或者: from models.Task import save [as 别名]
def new_task():
form = TaskForm(request.form)
if request.method == 'POST' and form.validate():
task = Task(form.name.data, form.text.data, form.memory.data, form.time_limit.data, g.user)
task.save()
return redirect(url_for('task', task_id=task.task_id))
return render_template('task_form.html', form=form)
示例11: test_delete_should_delete_task
# 需要导入模块: from models import Task [as 别名]
# 或者: from models.Task import save [as 别名]
def test_delete_should_delete_task(self):
"""
A DELETE request should result in the task being deleted.
"""
task = Task(description="run")
task.save()
response = Client().delete('/tasks/' + str(task.id))
self.assertFalse(Task.objects.all().exists())
示例12: test_task_should_be_fetchable
# 需要导入模块: from models import Task [as 别名]
# 或者: from models.Task import save [as 别名]
def test_task_should_be_fetchable(self):
"""
A Task should be fetchable via the ORM
"""
task = Task(description="Test")
task.save()
fetched_task = Task.objects.filter(description="Test")[0]
self.assertEqual(fetched_task.id, task.id)
示例13: download_datasets
# 需要导入模块: from models import Task [as 别名]
# 或者: from models.Task import save [as 别名]
def download_datasets(request):
ds = request.GET.get('dataset')
task_id = str(uuid.uuid4())
job = Task(task_id=task_id, task_type='download_dataset', data_input=ds)
job.save()
download.apply_async(args=(ds, job), task_id=task_id)
context = {'task_id': task_id, 'dataset': ds}
return render_to_response('main/datasets.html', context)
示例14: task_new
# 需要导入模块: from models import Task [as 别名]
# 或者: from models.Task import save [as 别名]
def task_new(request):
user = request.user
dataset_id = request.GET.get('dataset_id', '')
program_id = request.GET.get('model_id', '')
try:
dataset_id = int(dataset_id)
program_id = int(program_id)
except ValueError:
raise Http404();
if request.method == 'POST':
query_dataset = (Q(id=dataset_id))
dataset = Dataset.objects.filter(query_dataset)[0]
query_program = (Q(id=program_id))
program = Program.objects.filter(query_program)[0]
if request.POST["options"] == "":
task_options = ""
else:
if program_id == 1:
task_options = "-t " + request.POST["options"]
else:
task_options = "-l " + request.POST["options"]
create_date = datetime.datetime.now()
access = request.POST["access"]
new_task = Task(owner = user, data = dataset, program = program, options = task_options, create_date = create_date, progress = "waiting", result_dir = "", access = access)
new_task.save()
program.task_num += 1
program.save()
new_task_id = new_task.id
#result_dir = os.path.join(settings.USR_RESULT_ROOT, str(new_task_id))
#if not os.path.exists(result_dir):
# os.makedirs(result_dir)
new_task.result_dir = str(new_task_id)
new_task.save()
# return render_to_response("task/success.html", RequestContext(request, {'user': user, 'new_task': new_task}))
return HttpResponseRedirect("/tasks/%s/" % new_task.id)
else:
dataset = Dataset.objects.filter(Q(id=dataset_id))
program = Program.objects.filter(Q(id=program_id))
if len(dataset) == 0 or len(program) == 0:
notice="Couldn't find the dataset(ID="+str(dataset_id)+")or model(ID="+str(program_id)+")"
return render_to_response('task/error.html', RequestContext(request, {'notice': notice}))
dataset = dataset[0]
program = program[0]
dataset_name = dataset.name
program_name = program.name
return render_to_response('task/new.html', RequestContext(request, {'dataset_id': dataset_id, 'program_id': program_id, 'dataset_name': dataset_name, 'program_name': program_name}))
示例15: test_task_should_be_deletable
# 需要导入模块: from models import Task [as 别名]
# 或者: from models.Task import save [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())