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


Python Job.objects方法代码示例

本文整理汇总了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)
开发者ID:stage37,项目名称:deploybot,代码行数:51,代码来源:views.py

示例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)
开发者ID:stage37,项目名称:deploybot,代码行数:91,代码来源:views.py

示例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()
开发者ID:stage37,项目名称:deploybot,代码行数:8,代码来源:views.py

示例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('')
开发者ID:stage37,项目名称:deploybot,代码行数:8,代码来源:views.py


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