當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。