示例#1
0
def deploy_ask(request, pid):
    try:
        project = Project_Config.objects.get(id=pid)
        if project.project_repertory == 'git': version = GitTools()
        elif project.project_repertory == 'svn': version = SvnTools()
    except:
        return render(
            request,
            'deploy/deploy_ask.html',
            {
                "user": request.user,
                "errorInfo": "项目不存在,可能已经被删除."
            },
        )
    if request.method == "GET":
        vList = None
        version.pull(path=project.project_repo_dir)
        if project.project_model == 'branch':
            #获取最新版本
            bList = version.branch(path=project.project_repo_dir)
            vList = version.log(path=project.project_repo_dir, number=50)
        elif project.project_model == 'tag':
            bList = version.tag(path=project.project_repo_dir)
        audit_group = Group.objects.get(id=project.project_audit_group)
        userList = [u.get('username') for u in audit_group.user_set.values()]
        return render(
            request,
            'deploy/deploy_ask.html',
            {
                "user": request.user,
                "project": project,
                "userList": userList,
                "bList": bList,
                "vList": vList
            },
        )
    elif request.method == "POST":
        try:
            order = Project_Order.objects.create(
                order_user=request.user,
                order_project=project,
                order_subject=request.POST.get('order_subject'),
                order_audit=request.POST.get('order_audit'),
                order_status=request.POST.get('order_status', 2),
                order_level=request.POST.get('order_level'),
                order_content=request.POST.get('order_content'),
                order_branch=request.POST.get('order_branch', None),
                order_comid=request.POST.get('order_comid', None),
                order_tag=request.POST.get('order_tag', None))
            sendDeployNotice.delay(order_id=order.id, mask='【申请中】')
        except Exception, e:
            return render(
                request,
                'deploy/deploy_ask.html',
                {
                    "user": request.user,
                    "errorInfo": "项目部署申请失败:%s" % str(e)
                },
            )
        return HttpResponseRedirect('/deploy_ask/{id}/'.format(id=pid))
示例#2
0
def deploy_ask(request,pid):
    try:
        project = Project_Config.objects.get(id=pid)
        if project.project_repertory == 'git':version = GitTools()
        elif project.project_repertory == 'svn':version = SvnTools()
    except:
        return render(request,'deploy/deploy_ask.html',{"user":request.user,
                                                         "errorInfo":"项目不存在,可能已经被删除."}, 
                                  )     
    if request.method == "GET":
        vList = None
        version.pull(path=project.project_repo_dir)
        if project.project_model == 'branch':
            #获取最新版本
            bList = version.branch(path=project.project_repo_dir) 
            vList = version.log(path=project.project_repo_dir, number=50)
        elif project.project_model == 'tag':
            bList = version.tag(path=project.project_repo_dir) 
        audit_group = Group.objects.get(id=project.project_audit_group)
        userList = [ u.get('username') for u in audit_group.user_set.values()]
        return render(request,'deploy/deploy_ask.html',{"user":request.user,"project":project,
                                                         "userList":userList,"bList":bList,"vList":vList}, 
                                  )  
    elif request.method == "POST":       
        try:      
            order = Project_Order.objects.create(
                                                    order_user = request.user,
                                                    order_project = project, 
                                                    order_subject = request.POST.get('order_subject'),
                                                    order_audit = request.POST.get('order_audit'),
                                                    order_status = request.POST.get('order_status',2),
                                                    order_level = request.POST.get('order_level'),
                                                    order_content = request.POST.get('order_content'),
                                                    order_branch = request.POST.get('order_branch',None),
                                                    order_comid = request.POST.get('order_comid',None),
                                                    order_tag  = request.POST.get('order_tag',None)
                                                    )
            sendDeployNotice.delay(order_id=order.id,mask='【申请中】')
        except Exception,e:
            return render(request,'deploy/deploy_ask.html',{"user":request.user,"errorInfo":"项目部署申请失败:%s" % str(e)},
                                      )   
        return HttpResponseRedirect('/deploy_ask/{id}/'.format(id=pid))   
示例#3
0
def deploy_order(request,page):
    if request.method == "GET":
        allOrderList = Project_Order.objects.filter(Q(order_user=User.objects.get(username=request.user)) |
                                                 Q(order_audit=User.objects.get(username=request.user))).order_by("-id")[0:1000]
        totalOrder = Project_Order.objects.all().count()
        doneOrder = Project_Order.objects.filter(order_status=3).count()
        authOrder = Project_Order.objects.filter(order_status=2).count()
        rejectOrder = Project_Order.objects.filter(order_status=1).count()
        deploy_nmuber = Project_Order.objects.values('order_user').annotate(dcount=Count('order_user'))
        deploy_project =  Project_Order.objects.values('order_project').annotate(dcount=Count('order_project'))
        paginator = Paginator(allOrderList, 25)          
        try:
            orderList = paginator.page(page)
        except PageNotAnInteger:
            orderList = paginator.page(1)
        except EmptyPage:
            orderList = paginator.page(paginator.num_pages)        
        for ds in deploy_project:
            ds['order_project'] = Project_Config.objects.get(id=ds.get('order_project')).project.project_name
        return render(request,'deploy/deploy_order.html',{"user":request.user,"orderList":orderList,
                                                              "totalOrder":totalOrder,"doneOrder":doneOrder,
                                                              "authOrder":authOrder,"rejectOrder":rejectOrder,
                                                              "deploy_nmuber":deploy_nmuber,"deploy_project":deploy_project},
                                  ) 
    elif request.method == "POST" and request.user.has_perm('OpsManage.can_add_project_order'):  
        if request.POST.get('model') in ['disable','auth','finish']:
            try:     
                Project_Order.objects.filter(id=request.POST.get('id')).update(
                                order_status = request.POST.get('order_status'),
                                order_cancel = request.POST.get('order_cancel',None),
                            )
                if request.POST.get('model') == 'auth':
                    sendDeployNotice.delay(order_id=request.POST.get('id'),mask='【已授权】')
                elif request.POST.get('model') == 'finish':
                    sendDeployNotice.delay(order_id=request.POST.get('id'),mask='【已部署】')
                elif request.POST.get('model') == 'disable':
                    sendDeployNotice.delay(order_id=request.POST.get('id'),mask='【已取消】')                   
            except Exception,e:
                return JsonResponse({'msg':"操作失败:"+str(e),"code":500,'data':[]}) 
            return JsonResponse({'msg':"操作成功","code":200,'data':[]})                
        else:return JsonResponse({'msg':"非法操作","code":500,'data':[]})
示例#4
0
def deploy_order(request,page):
    if request.method == "GET":
        allOrderList = Project_Order.objects.filter(Q(order_user=User.objects.get(username=request.user)) |
                                                 Q(order_audit=User.objects.get(username=request.user))).order_by("-id")[0:1000]
        totalOrder = Project_Order.objects.all().count()
        doneOrder = Project_Order.objects.filter(order_status=3).count()
        authOrder = Project_Order.objects.filter(order_status=2).count()
        rejectOrder = Project_Order.objects.filter(order_status=1).count()
        deploy_nmuber = Project_Order.objects.values('order_user').annotate(dcount=Count('order_user'))
        deploy_project =  Project_Order.objects.values('order_project').annotate(dcount=Count('order_project'))
        paginator = Paginator(allOrderList, 25)          
        try:
            orderList = paginator.page(page)
        except PageNotAnInteger:
            orderList = paginator.page(1)
        except EmptyPage:
            orderList = paginator.page(paginator.num_pages)        
        for ds in deploy_project:
            ds['order_project'] = Project_Config.objects.get(id=ds.get('order_project')).project.project_name
        return render(request,'deploy/deploy_order.html',{"user":request.user,"orderList":orderList,
                                                              "totalOrder":totalOrder,"doneOrder":doneOrder,
                                                              "authOrder":authOrder,"rejectOrder":rejectOrder,
                                                              "deploy_nmuber":deploy_nmuber,"deploy_project":deploy_project},
                                  ) 
    elif request.method == "POST" and request.user.has_perm('OpsManage.can_add_project_order'):  
        if request.POST.get('model') in ['disable','auth','finish']:
            try:     
                Project_Order.objects.filter(id=request.POST.get('id')).update(
                                order_status = request.POST.get('order_status'),
                                order_cancel = request.POST.get('order_cancel',None),
                            )
                if request.POST.get('model') == 'auth':
                    sendDeployNotice.delay(order_id=request.POST.get('id'),mask='【已授权】')
                elif request.POST.get('model') == 'finish':
                    sendDeployNotice.delay(order_id=request.POST.get('id'),mask='【已部署】')
                elif request.POST.get('model') == 'disable':
                    sendDeployNotice.delay(order_id=request.POST.get('id'),mask='【已取消】')                   
            except Exception,e:
                return JsonResponse({'msg':"操作失败:"+str(e),"code":500,'data':[]}) 
            return JsonResponse({'msg':"操作成功","code":200,'data':[]})                
        else:return JsonResponse({'msg':"非法操作","code":500,'data':[]})