本文整理汇总了Python中job.models.Job.objects方法的典型用法代码示例。如果您正苦于以下问题:Python Job.objects方法的具体用法?Python Job.objects怎么用?Python Job.objects使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类job.models.Job
的用法示例。
在下文中一共展示了Job.objects方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: index
# 需要导入模块: from job.models import Job [as 别名]
# 或者: from job.models.Job import objects [as 别名]
def index(request):
if request.user.is_superuser:
record_list = Record.objects.all()
show_operator = True
elif len(Job.objects(users=str(request.user))) != 0:
record_list = []
job_list = [job.name for job in Job.objects(users=str(request.user)).values_list('builders')]
for record in Record.objects.all():
if record.job in job_list:
record_list.append(record)
show_operator = True
else:
record_list = Record.objects.filter(user=str(request.user))
show_operator = False
job_list = []
operator_list = []
result_list = []
for record in record_list:
record.start_time = (datetime.utcfromtimestamp(int(record.start_time)) + timedelta(hours=8)).\
strftime('%Y-%m-%d %H:%M:%S')
job_list.append(record.job)
operator_list.append(record.user)
result_list.append(record.result)
if record.finish_time != 0:
record.finish_time = (datetime.utcfromtimestamp(int(record.finish_time)) + timedelta(hours=8)).\
strftime('%Y-%m-%d %H:%M:%S')
else:
record.finish_time = ''
job_list = sorted(set(job_list))
operator_list = sorted(set(operator_list))
result_list = sorted(set(result_list))
context = {
'record_list': record_list[::-1],
'job_list': job_list,
'operator_list': operator_list,
'result_list': result_list,
'user': request.user,
'show_operator': show_operator,
}
return render(request, 'history/index.html', context)
示例2: record_filter
# 需要导入模块: from job.models import Job [as 别名]
# 或者: from job.models.Job import objects [as 别名]
def record_filter(request):
filter_kwargs = {
'job': request.POST.get('job_name', None),
'user': request.POST.get('operator', None),
'result': request.POST.get('result', None),
'start_time__gte': request.POST.get('date_after', None),
'finish_time__lte': request.POST.get('date_before', None)
}
for key in filter_kwargs.keys():
if filter_kwargs[key] is None:
del filter_kwargs[key]
if 'start_time__gte' in filter_kwargs:
date_str = str(filter_kwargs['start_time__gte'])
date = datetime.strptime(date_str, '%Y-%m-%d') - timedelta(hours=8)
filter_kwargs['start_time__gte'] = unicode(calendar.timegm(date.utctimetuple()))
if 'finish_time__lte' in filter_kwargs:
date_str = str(filter_kwargs['finish_time__lte']) + ' 23:59:59'
date = datetime.strptime(date_str, '%Y-%m-%d %H:%M:%S') - timedelta(hours=8)
filter_kwargs['finish_time__lte'] = unicode(calendar.timegm(date.utctimetuple()))
if len(set(filter_kwargs.values())) == 0:
if request.user.is_superuser:
record_list = Record.objects.all()
show_operator = True
elif len(Job.objects(users=str(request.user))) != 0:
record_list = []
job_list = [job.name for job in Job.objects(users=str(request.user)).values_list('builders')]
for record in Record.objects.all():
if record.job in job_list:
record_list.append(record)
show_operator = True
else:
record_list = Record.objects.filter(user=str(request.user))
show_operator = False
else:
if request.user.is_superuser:
record_list = Record.objects.filter(**filter_kwargs)
show_operator = True
elif len(Job.objects(users=str(request.user))) != 0:
record_list = []
job_list = [job.name for job in Job.objects(users=str(request.user)).values_list('builders')]
for record in Record.objects.filter(**filter_kwargs):
if record.job in job_list:
record_list.append(record)
show_operator = True
else:
record_list = Record.objects.filter(user=str(request.user))
show_operator = False
job_list = []
operator_list = []
result_list = []
for record in record_list:
record.start_time = (datetime.utcfromtimestamp(int(record.start_time)) + timedelta(hours=8)).\
strftime('%Y-%m-%d %H:%M:%S')
job_list.append(record.job)
operator_list.append(record.user)
result_list.append(record.result)
if record.finish_time != 0:
record.finish_time = (datetime.utcfromtimestamp(int(record.finish_time)) + timedelta(hours=8)).\
strftime('%Y-%m-%d %H:%M:%S')
else:
record.finish_time = ''
job_list = sorted(set(job_list))
operator_list = sorted(set(operator_list))
result_list = sorted(set(result_list))
context = {
'record_list': record_list[::-1],
'job_list': job_list,
'operator_list': operator_list,
'result_list': result_list,
'user': request.user,
'show_operator': show_operator,
}
return render(request, 'history/index.html', context)
示例3: edit_job_user
# 需要导入模块: from job.models import Job [as 别名]
# 或者: from job.models.Job import objects [as 别名]
def edit_job_user(request):
if request.method == 'POST':
Job.objects(builders__name=request.POST.get('job_name', '')).\
update_one(set__users=list(request.POST.getlist('job_users[]')))
return HttpResponse()
示例4: get_job_user
# 需要导入模块: from job.models import Job [as 别名]
# 或者: from job.models.Job import objects [as 别名]
def get_job_user(request):
try:
job = Job.objects(builders___name=request.POST.get(job_name, '')).first()
return HttpResponse(', '.join([str(user) for user in job.users]))
except:
return HttpResponse('')