本文整理汇总了Python中models.Job类的典型用法代码示例。如果您正苦于以下问题:Python Job类的具体用法?Python Job怎么用?Python Job使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Job类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: post
def post(self, request, *args, **kwargs):
form = JobForm(request.POST, request.FILES)
if form.is_valid():
now = datetime.datetime.now()
name = request.POST['name']
description = request.POST['description']
interval = request.POST['interval']
interval_options = request.POST['interval_options']
arguments = request.POST['arguments']
active = False
try:
request.POST['active']
active = True
except:
pass
file = request.FILES['file']
file_content = file.read()
file_name = str(now.year) + str(now.month) + str(now.day) + str(now.hour) + str(now.minute) + str(now.second) + str(now.microsecond) + name.replace(' ', '-') + '.py'
f = open(BASE_DIR + '/job_files/' + file_name, 'w')
f.write(file_content)
f.close()
#Save job
new_job = Job(name=name, description=description, interval=interval, interval_options=interval_options, arguments=arguments, active=active, file_name=file_name)
new_job.save()
res = 'Job created'
return render_to_response(self.template_name, locals(), context_instance=RequestContext(request))
示例2: bpusher_PostJob
def bpusher_PostJob(request):
jsonData = json.loads(request.body)
try:
destination = Destination.objects.get(name=jsonData['job']['destination'])
except ObjectDoesNotExist:
status = http_NOT_FOUND
return HttpResponse(json.dumps({'message': 'Destination not found'}), status=status, content_type='application/json')
job = Job()
job.name = jsonData['job']['name']
job.input_name = jsonData['job']['input_name']
job.system_path = jsonData['job']['system_path']
job.input_path = jsonData['job']['input_path']
job.destination = destination
job.priority = jsonData['job']['priority']
job.status = 'Q' # Queue
job.save()
response = {"job": {"id": job.id, "name": job.name}}
#
# La unica respuesta para esto es OK
status = http_POST_OK
return HttpResponse(json.dumps(response), status=status, content_type='application/json')
示例3: imen_PostJob
def imen_PostJob(request):
jsonData = json.loads(request.body)
try:
preset = ThumbPreset.objects.get(name=jsonData['job']['thumb_preset'])
except ObjectDoesNotExist:
status = http_NOT_FOUND
return HttpResponse(json.dumps({'message': 'ThumbPreset not found'}), status=status, content_type='application/json')
job = Job()
job.input_filename = jsonData['job']['input_filename']
job.input_path = jsonData['job']['input_path']
job.basename = jsonData['job']['basename']
job.thumb_preset = preset
job.priority = jsonData['job']['priority']
job.output_path = jsonData['job']['output_path']
job.status = 'Q' # Queue
job.save()
response = {"job": {"id": job.id}}
#
# La unica respuesta para esto es OK
status = http_POST_OK
return HttpResponse(json.dumps(response), status=status, content_type='application/json')
示例4: test_job_should_emit_results_for_all_urls
def test_job_should_emit_results_for_all_urls(self):
first_domain = Domain("http://example.com")
first_img_url = Image("http://example.com/1.png")
second_img_url = Image("http://example.com/2.png")
third_img_url = Image("http://example.com/3.png")
first_domain.images.extend([first_img_url, second_img_url, third_img_url])
second_domain = Domain("http://example.com/2")
fourth_img_url = Image("http://example.com/4.png")
second_domain.images.extend([fourth_img_url])
job = Job([first_domain,second_domain])
self.assertEqual(job.get_results(), {
"id": job.id,
"domains":{
"http://example.com":[
"http://example.com/1.png",
"http://example.com/2.png",
"http://example.com/3.png"
],
"http://example.com/2":[
"http://example.com/4.png"
]
}
})
示例5: add_job
def add_job(request):
try:
form = JobForm(request.POST or None)
if form.is_valid():
required_skills = set(form.cleaned_data["required_skills"])
optional_skills = set(form.cleaned_data["optional_skills"]) - required_skills
with transaction.atomic():
employer = Employer.objects.get(user=request.user)
job = Job(
employer=employer,
description=form.cleaned_data["description"],
category=form.cleaned_data["category"],
years_of_experience=form.cleaned_data["years_of_experience"],
other=form.cleaned_data["other"],
)
job.save()
for skill in required_skills:
skill = RequiredJobSkill(job=job, skill=skill)
skill.save()
if optional_skills:
for skill in optional_skills:
skill = OptionalJobSkill(job=job, skill=skill)
skill.save()
match_job.delay(job.id)
messages.success(request, "Job saved successfully. You'll receive matching candidates soon")
return HttpResponseRedirect("/")
return render(request, "jobs/add_job.html", {"form": form})
except Exception, e:
logging.exception(e)
return server_error(request)
示例6: get
def get(self, job_id):
job = Job.get_by_key_name(job_id)
if job and job.state != DONE and job.active == True:
job.updated_at = datetime.now()
job.state = DONE
job.put()
# update the email
email = job.email
email.updated_at = datetime.now()
email.put()
# count the number of jobs attached to this flyer
job_query = Job.all()
job_query.filter("flyer =", job.flyer)
job_query.filter("active =", True)
total_jobs = job_query.count()
# count the number of jobs done so far
job_query = Job.all()
job_query.filter("flyer =", job.flyer)
job_query.filter("active =", True)
job_query.filter("state =", DONE)
done_jobs = job_query.count()
# write out
self.response.out.write(template.render("templates/finish.html",
{"total": total_jobs,
"done": done_jobs}))
else:
self.error(404)
示例7: new_job
def new_job():
if not g.site.domain == g.user:
abort(403)
j = Job()
if request.method == "POST":
portfolio = Portfolio.objects.get(site=g.site.domain)
job_name = request.form.get("name")
slugs = [__j.slug for __j in Job.objects.filter(site=g.site.domain)]
counter = 1
slug = slugify(job_name)
__slug = slug
while __slug in slugs:
counter += 1
__slug = "%s_%d" % (slug, counter)
j.slug = __slug
j.name = job_name
j.site = g.site.domain
j.categories = [ c.strip() for c in request.form.get("categories").split(",") ]
j.intro = request.form.get("intro")
j.description = request.form.get("description")
j.slides = []
texts = request.form.getlist("text")
image_urls = request.form.getlist("image_url")
captions = request.form.getlist("caption")
caption_links = request.form.getlist("caption_link")
for text, image_url, caption, caption_link in zip(texts, image_urls, captions, caption_links):
if text or image_url:
j.slides.append(Slide(text=text, image_url=image_url, caption=caption, caption_link=caption_link))
j.save()
portfolio.jobs.append(j)
portfolio.save()
return redirect(url_for(".job", slug=j.slug))
return render_template("edit_job.html", job=j)
示例8: post
def post(self, job_id):
job = Job.get_by_key_name(job_id)
# make sure the job is recent
if not(job.active):
self.error(404)
email = job.email
email.enable = False
email.updated_at = datetime.datetime.now()
email.put()
# find the email-club join
join_query = EmailToClub.all()
join_query.filter("email =", email)
joins = join_query.fetch(20)
# do the delete
for join in joins:
join.enable = False
join.updated_at = datetime.now()
join.put()
# mark all the jobs inactive
job_query = Job.all()
job_query.filter("email =", email)
job_query.filter("active =", True)
jobs = job_query.fetch(20)
for job in jobs:
job.active = False
job.put()
self.response.out.write(template.render("templates/sorry.html", {}))
示例9: test_job_should_emit_status_for_all_urls
def test_job_should_emit_status_for_all_urls(self):
first_domain = Domain("http://example.com")
first_domain.crawled = True
second_domain = Domain("http://example.com/2")
job = Job([first_domain,second_domain])
self.assertEqual(job.get_status()["completed"], 1)
self.assertEqual(job.get_status()["inprogress"], 1)
示例10: schedule
def schedule(function, args = None, kwargs = None,
run_after= None, meta = None):
"""Schedule a tast for execution.
"""
job = Job(
name=full_name(function),
args=dumps(args or []), kwargs=dumps(kwargs or {}),
meta=dumps(meta or {}), scheduled=run_after)
job.save()
return job
示例11: create
def create():
post_data = get_post_data()
post_data['lead_id'] = parse_endpoint(post_data['lead'], 'leads')
# saves the job
job = Job()
job.build(post_data)
job.status = 'CREATED'
job.unique_id = Job.generate_unique_id()
if job.put():
# enqueue job to be sent to townflix
_enqueue_job_creation_message(job)
pprint.pprint('=== JOB CREATED')
# mark the lead as converted
lead = job.lead.get()
lead.status = 'CONVERTED'
lead.put()
create_activity('LEAD_CONVERTED', lead=lead, job=job)
create_activity('JOB_CREATED', lead=lead, job=job)
# send a message to property owner
_enqueue_job_create_message(job)
# if the lead has been sent by someone
if lead.sender_broker is not None:
# send a message to the broker
_enqueue_broker_job_create_message(job)
return jsonify(data=job.to_json()), 201
else:
return jsonify(data=job.error_messages()), 500
示例12: bmanager_post_job
def bmanager_post_job(request):
jsonData =json.loads(request.body)
job = Job()
job.basename = jsonData['job']['basename']
job.format = jsonData['job']['format']
job.input_filename = jsonData['job']['input_filename']
job.input_path = jsonData['job']['input_path']
try:
job.profile = Profile.objects.get(name=jsonData['job']['profile'])
except ObjectDoesNotExist:
status = http_NOT_FOUND
return HttpResponse(json.dumps({'message': 'Profile not found'}), status=status, content_type='application/json')
dest_list = []
destinations = jsonData['job']['destinations']
for destination in destinations:
try:
dest_list.append(Destination.objects.get(name=destination))
#job.destinations.add(Destination.objects.get(name=destination))
except ObjectDoesNotExist:
status = http_NOT_FOUND
return HttpResponse(json.dumps({'message': 'Destination not found'}), status=status,content_type='application/json')
job.save()
job.destinations = dest_list
#job.save()
response = {"job": {"id": job.id, "basename": job.basename}}
status = http_POST_OK
return HttpResponse(json.dumps(response), status=status, content_type='application/json')
示例13: main
def main():
while True:
job = Job.get_queue()
if job:
print 'Working on',job['_id']
work(job)
job['is_done'] = True
Job.save(job)
print 'Done'
else:
time.sleep(POLL_TIME)
示例14: before_request
def before_request():
g.db = connect_db()
Slot_Conf.set_db(g.db)
Job.set_db(g.db)
TimeInfo.set_db(g.db)
slotStartEnd.set_db(g.db)
Projects.set_db(g.db)
Results.set_db(g.db)
ProjNames.set_db(g.db)
SlotTimes.set_db(g.db)
ProjectTimes.set_db(g.db)
示例15: job_add
def job_add(request, event_id, task_id):
event = get_object_or_404(Event, pk=event_id)
task = get_object_or_404(Task, pk=task_id)
#job_user = get_object_or_404(User, pk=user_id)
#if job_user != user:
# return HttpResponseNotAllowed('<h1>Must not add other users!</h1>')
job = Job(event=event, task = task, user = request.user)
job.save()
messages.success(request, _("Took job"))
return HttpResponseRedirect(reverse('event', args=[event.id]))