예제 #1
0
def require_add(request):
    if request.method == 'POST':
        form = RequireForm(request.POST)
        if form.is_valid():
            title = form.cleaned_data["title"]
            owner = form.cleaned_data["owner"]
            msg_user = AppOwner.objects.filter(
                name=owner).values("dingding").first()

            db_form = form.save(commit=False)
            db_form.order_user = request.user.username
            db_form.save()
            require_id = db_form.id

            if title is not None and msg_user is not None:
                if msg_user["dingding"] is not None:
                    dingding_msg.delay(
                        msg_user["dingding"],
                        u"您有新的工单(编号:%s)需要处理,标题为:%s" % (require_id, title))
            return HttpResponseRedirect(reverse('require_list'))
    else:
        form = RequireForm()

    results = {
        'form': form,
        'request': request,
    }
    return render(request, 'orders/require_base.html', results)
예제 #2
0
def deploy_finish(request, deploy_id):
    if deploy_id:
        deploy = Deploy.objects.get(id=deploy_id)

        document = Document.objects.filter(
            Q(doc_id=deploy.app_name_id)
            & Q(next_ver=deploy.version)).values().first()
        document.pop("id")
        document.pop("doc_id")
        document.pop("next_ver")
        document.pop("product_id")
        document.pop("dev_id")
        document.pop("ops_id")
        document["current_ver"] = deploy.version
        Project.objects.filter(id=deploy.app_name_id).update(**document)

        Deploy.objects.filter(id=deploy_id).update(
            status=1,
            update_time=datetime.datetime.now(),
            completion_time=datetime.datetime.now())

        app_name = Deploy.objects.filter(
            id=deploy_id).values("app_name__name").first()
        msg_user = AppOwner.objects.filter(
            username__username=deploy.order_user).values("dingding").first()

        if msg_user is not None and app_name is not None and deploy.version is not None:
            if msg_user["dingding"] is not None:
                dingding_msg.delay(
                    msg_user["dingding"], u"您的工单(编号:%s)已处理,应用名:%s,版本号:%s" %
                    (deploy_id, app_name["app_name__name"], deploy.version))

    return HttpResponseRedirect(reverse('deploy_list'))
예제 #3
0
def project_edit(request, project_id):
    project = Project.objects.get(id=project_id)
    ops_id = project.ops_id
    if request.method == 'POST':
        form = ProjectForm(request.POST, instance=project)
        if form.is_valid():
            priv_ops_id = ops_id
            if form.cleaned_data["ops"] is not None:
                cur_ops_id = form.cleaned_data["ops"].id
            else:
                cur_ops_id = None
            form.save()

            if priv_ops_id != cur_ops_id:
                msg_user = AppOwner.objects.filter(
                    id=cur_ops_id).values("dingding").first()
                deploy = Deploy.objects.filter(
                    Q(app_name_id=project_id) & Q(status=0))
                for d in deploy:
                    if msg_user is not None:
                        if msg_user["dingding"] is not None:
                            dingding_msg.delay(msg_user["dingding"], \
                                               u"您有应用更新(编号:%s)需要处理,应用名:%s,版本号:%s" \
                                               % (d.id, d.app_name, d.version))

            return HttpResponseRedirect(reverse('project_list'))
    else:
        form = ProjectForm(instance=project)

    results = {
        'form': form,
        'project_id': project_id,
        'request': request,
    }
    return render(request, 'appconf/project_base.html', results)
예제 #4
0
def dbscript_finish(request, dbscript_id):
    if dbscript_id:
        DBScript.objects.filter(id=dbscript_id).update(
            status=1,
            update_time=datetime.datetime.now(),
            completion_time=datetime.datetime.now())

        dbscript = DBScript.objects.get(id=dbscript_id)

        script_path = os.path.join(get_dir("script_path"),
                                   dbscript.db_name.name, dbscript.env)
        archive_path = os.path.join(script_path, "archive")
        archive_file = str(dbscript.id) + "_" + dbscript.script_name
        if not os.path.exists(archive_path):
            os.makedirs(archive_path)

        srcfile = os.path.join(script_path, dbscript.script_name)
        dstfile = os.path.join(archive_path, archive_file)
        if os.path.exists(srcfile):
            shutil.move(srcfile, dstfile)

        db_name = DBScript.objects.filter(
            id=dbscript_id).values("db_name__name").first()
        msg_user = AppOwner.objects.filter(
            username__username=dbscript.order_user).values("dingding").first()

        if msg_user is not None and db_name is not None and dbscript.script_name is not None:
            if msg_user["dingding"] is not None:
                dingding_msg.delay(msg_user["dingding"], \
                                   u"您的工单(编号:%s)已处理,环境:%s,数据库名:%s,脚本:%s" \
                                   % (dbscript_id, dbscript.env, db_name["db_name__name"], dbscript.script_name))

    return HttpResponseRedirect(reverse('dbscript_list'))
예제 #5
0
def apply_add(request):
    status = 0
    if request.method == 'POST':
        form = ApplyForm(request.POST)
        if form.is_valid():
            product = form.cleaned_data["product"]
            if Apply.objects.filter(Q(product=product)
                                    & Q(feedback=0)).exists():
                status = 3
            else:
                msg_user = Product.objects.filter(
                    id=product.id).values("qa__dingding").first()
                db_form = form.save(commit=False)
                db_form.order_user = request.user.username
                db_form.save()
                apply_id = db_form.id

                if msg_user is not None:
                    if msg_user["qa__dingding"] is not None:
                        dingding_msg.delay(
                            msg_user["qa__dingding"],
                            u"您有新的测试需求(编号:%s)需要处理,产品线:%s" %
                            (apply_id, product))
                status = 1
        else:
            status = 2
    else:
        form = ApplyForm()

    results = {
        'form': form,
        'request': request,
        'status': status,
    }
    return render(request, 'tests/apply_base.html', results)
예제 #6
0
def dbscript_add(request):
    status = 0
    if request.method == 'POST':
        dbscript_file = request.FILES.get("dbscript_file", None)
        env_list = request.POST.getlist('checkbox_env')
        if env_list:
            for env in env_list:
                form = DBScriptForm(request.POST)
                if form.is_valid() and dbscript_file:
                    db_name = form.cleaned_data["db_name"].name
                    script_path = os.path.join(get_dir("script_path"), db_name,
                                               env)
                    if not os.path.exists(script_path):
                        os.makedirs(script_path)

                    file = os.path.join(script_path, dbscript_file.name)
                    if not os.path.exists(file):
                        destination = open(file, 'wb+')
                        for chunk in dbscript_file.chunks():
                            destination.write(chunk)
                        destination.close()

                        db_form = form.save(commit=False)
                        db_form.script_name = dbscript_file.name
                        db_form.order_user = request.user.username
                        db_form.env = env
                        db_form.save()

                        dbscript_id = db_form.id
                        msg_user = Database.objects.filter(
                            name=db_name).values("ops__dingding").first()
                        if db_name is not None and msg_user is not None:
                            if msg_user["ops__dingding"] is not None:
                                dingding_msg.delay(msg_user["ops__dingding"], \
                                                   u"您有数据库更新(编号:%s)需要处理,环境:%s,数据库名:%s,脚本:%s" \
                                                   % (dbscript_id, env, db_name, dbscript_file.name))
                        status = 1
                    else:
                        status = 3
                        break
                else:
                    status = 2
                    break
            if status == 1:
                return HttpResponseRedirect(reverse('dbscript_list'))
        else:
            form = DBScriptForm(request.POST)
            status = 4
    else:
        form = DBScriptForm()

    results = {
        'form': form,
        'status': status,
        'request': request,
    }
    return render(request, 'orders/dbscript_base.html', results)
예제 #7
0
def dbscript_add_mini(request):
    status = 0
    dbscript_id = 0
    if request.method == 'POST':
        form = DBScriptForm(request.POST)
        dbscript_file = request.FILES.get("dbscript_file", None)
        env = "Pro"
        if form.is_valid() and dbscript_file:
            db_name = form.cleaned_data["db_name"].name
            script_path = os.path.join(get_dir("script_path"), db_name, env)
            if not os.path.exists(script_path):
                os.makedirs(script_path)

            file = os.path.join(script_path, dbscript_file.name)
            if not os.path.exists(file):
                destination = open(file, 'wb+')
                for chunk in dbscript_file.chunks():
                    destination.write(chunk)
                destination.close()

                db_form = form.save(commit=False)
                db_form.script_name = dbscript_file.name
                db_form.order_user = request.user.username
                db_form.env = env
                db_form.save()
                dbscript_id = db_form.id

                msg_user = Database.objects.filter(
                    name=db_name).values("ops__dingding").first()
                if db_name is not None and msg_user is not None:
                    if msg_user["ops__dingding"] is not None:
                        dingding_msg.delay(msg_user["ops__dingding"], \
                                           u"您有数据库更新(编号:%s)需要处理,环境:%s,数据库名:%s,脚本:%s" \
                                           % (dbscript_id, env, db_name, dbscript_file.name))

                status = 1
                dbscript_id = DBScript.objects.get(
                    Q(db_name__name=db_name)
                    & Q(script_name=dbscript_file.name) & Q(status=0)).id
            else:
                status = 3
        else:
            status = 2
    else:
        form = DBScriptForm()

    results = {
        'form': form,
        'request': request,
        'status': status,
        'dbscript_id': dbscript_id,
    }
    return render(request, 'orders/dbscript_add_mini.html', results)
예제 #8
0
def project_offline(request):
    project_id = request.GET.get('id', '')
    if project_id:
        Project.objects.filter(id=project_id).update(is_offline=True)

        app_name = Project.objects.get(id=project_id).name
        msg_user = Project.objects.filter(
            id=project_id).values("ops__dingding").first()
        username = request.user.username

        if msg_user is not None:
            if msg_user["ops__dingding"] is not None:
                dingding_msg.delay(msg_user["ops__dingding"], \
                                   u"应用已下架,应用名:%s,操作者:%s" % (app_name, username))

    return HttpResponseRedirect(reverse('project_list'))
예제 #9
0
def config_finish(request, config_id):
    if config_id:
        Config.objects.filter(id=config_id).update(status=1, update_time=datetime.datetime.now(),
                                                   completion_time=datetime.datetime.now())

        config = Config.objects.get(id=config_id)

        app_name = Config.objects.filter(id=config_id).values("app_name__name").first()
        msg_user = AppOwner.objects.filter(username__username=config.order_user).values("dingding").first()

        if msg_user is not None and app_name is not None:
            if msg_user["dingding"] is not None:
                dingding_msg.delay(msg_user["dingding"], \
                                   u"您的工单(编号:%s)已处理,环境:%s,应用名称:%s" \
                                   % (config_id, config.env, app_name["app_name__name"]))

    return HttpResponseRedirect(reverse('config_list'))
예제 #10
0
def require_finish(request, require_id):
    if require_id:
        Require.objects.filter(id=require_id).update(
            status=1,
            update_time=datetime.datetime.now(),
            completion_time=datetime.datetime.now())

        require = Require.objects.get(id=require_id)
        title = require.title
        msg_user = AppOwner.objects.filter(
            username__username=require.order_user).values("dingding").first()

        if msg_user is not None and title is not None:
            if msg_user["dingding"] is not None:
                dingding_msg.delay(
                    msg_user["dingding"],
                    u"您的工单(编号:%s)已处理,标题为:%s" % (require_id, title))

    return HttpResponseRedirect(reverse('require_list'))
예제 #11
0
def apply_finish(request):
    status = 0
    apply_id = int(request.GET.get('id', 0))
    try:
        apply = Apply.objects.get(id=apply_id)
    except:
        return HttpResponseRedirect(reverse('permission_deny'))

    if request.method == 'POST':
        form = ApplyFinishForm(request.POST, instance=apply)
        if form.is_valid():
            report_addr = form.cleaned_data["report_address"]
            db_form = form.save(commit=False)
            db_form.report_file = report_addr.split('/')[-1]
            db_form.status = True
            db_form.finishtime = datetime.datetime.now()
            db_form.save()
            product_name = apply.product.name
            msg_user = AppOwner.objects.filter(
                username__username=apply.order_user).values(
                    "dingding").first()
            if msg_user is not None and product_name is not None:
                if msg_user["dingding"] is not None:
                    dingding_msg.delay(
                        msg_user["dingding"],
                        u"您的测试需求(编号:%s)已完成,产品线:%s,请及时确认是否上线!" %
                        (apply_id, product_name))
            status = 1
        else:
            status = 2
    else:
        form = ApplyFinishForm(instance=apply)

    results = {
        'form': form,
        'request': request,
        'status': status,
        'apply_id': apply_id,
    }
    return render(request, 'tests/apply_finish.html', results)
예제 #12
0
def config_add(request):
    status = 0
    if request.method == 'POST':
        env_list = request.POST.getlist('checkbox_env')
        if env_list:
            for env in env_list:
                form = ConfigScriptForm(request.POST)
                if form.is_valid():
                    app_name = form.cleaned_data["app_name"].name
                    config_form = form.save(commit=False)
                    config_form.order_user = request.user.username
                    config_form.env = env
                    config_id = config_form.id
                    config_form.save()
                    msg_user = Database.objects.filter(name=app_name).values("ops__dingding").first()
                    if app_name is not None and msg_user is not None:
                        if msg_user["ops__dingding"] is not None:
                            dingding_msg.delay(msg_user["ops__dingding"],
                                               u"您有配置更新(编号:%s)需要处理,环境:%s,应用名称:%s,应用版本号:%s, 配置版本号:%s"
                                               % (config_id, env, app_name, config_form.app_version, config_form.conf_version))
                    status = 1
                else:
                    status = 3
                    break
            if status == 1:
                return HttpResponseRedirect(reverse('config_list'))
        else:
            form = ConfigScriptForm(request.POST)
            status = 4
    else:
        form = ConfigScriptForm()

    results = {
        'form': form,
        'status': status,
        'request': request,
    }
    return render(request, 'orders/config_base.html', results)
예제 #13
0
def require_edit(request, require_id):
    try:
        if request.user.is_superuser or request.user.is_staff:
            require = Require.objects.get(id=require_id)
            owner_id = require.owner_id
        else:
            require = Require.objects.get(
                Q(id=require_id) & Q(order_user=request.user.username))
            owner_id = require.owner_id
    except:
        return HttpResponseRedirect(reverse('permission_deny'))

    if request.method == 'POST':
        form = RequireForm(request.POST, instance=require)
        if form.is_valid():
            priv_owner_id = owner_id
            cur_owner_id = form.cleaned_data["owner"].id
            title = form.cleaned_data["title"]
            form.save()

            if priv_owner_id != cur_owner_id:
                msg_user = AppOwner.objects.filter(
                    id=cur_owner_id).values("dingding").first()
                if title is not None and msg_user is not None:
                    if msg_user["dingding"] is not None:
                        dingding_msg.delay(
                            msg_user["dingding"],
                            u"您有新的工单(编号:%s)需要处理,标题为:%s" % (require_id, title))
            return HttpResponseRedirect(reverse('require_list'))
    else:
        form = RequireForm(instance=require)

    results = {
        'form': form,
        'require_id': require_id,
        'request': request,
    }
    return render(request, 'orders/require_base.html', results)
예제 #14
0
def deploy_doc(request):
    app_name_id = request.GET.get('app_name_id', '')
    latest_ver = request.GET.get('version', '')
    try:
        if request.user.is_superuser or request.user.is_staff:
            project = Project.objects.get(id=app_name_id)
        else:
            project = Project.objects.get(
                Q(id=app_name_id)
                & Q(dev__username__username=request.user.username))
    except:
        return HttpResponseRedirect(reverse('permission_deny'))

    if request.method == 'POST':
        form = DocumentForm(request.POST, instance=project)
        if form.is_valid():
            Document.objects.update_or_create(doc_id=app_name_id, \
                                              current_ver=project.current_ver, \
                                              next_ver=latest_ver, \
                                              name=project.name, \
                                              product_id=project.product_id, \
                                              dev_id=project.dev_id, \
                                              ops_id=project.ops_id, \
                                              defaults=form.cleaned_data)
            Deploy.objects.filter(
                Q(app_name_id=app_name_id)
                & Q(version=latest_ver)).update(order_status=1)

            if Deploy.objects.get(
                    Q(app_name_id=app_name_id)
                    & Q(version=latest_ver)).is_new == True:
                Project.objects.filter(id=app_name_id).update(language_type=form.cleaned_data["language_type"], \
                                                              app_type=form.cleaned_data["app_type"], \
                                                              code_address=form.cleaned_data["code_address"])

            deploy_id = Deploy.objects.get(
                Q(app_name_id=app_name_id) & Q(version=latest_ver)).id
            app_name = Project.objects.get(id=app_name_id).name
            msg_user = Project.objects.filter(
                id=app_name_id).values("ops__dingding").first()
            if msg_user is not None:
                if msg_user["ops__dingding"] is not None:
                    dingding_msg.delay(msg_user["ops__dingding"], \
                                       u"您有应用更新(编号:%s)需要处理,应用名:%s,版本号:%s" \
                                       % (deploy_id, app_name, latest_ver))
                else:
                    ops_leader = Product.objects.filter(
                        name=u"运维").values("owner__dingding").first()
                    if ops_leader is not None:
                        if ops_leader["owner__dingding"] is not None:
                            dingding_msg.delay(ops_leader["owner__dingding"], \
                                               u"有新的应用更新(编号:%s)需要分配运维,应用名:%s,版本号:%s" \
                                               % (deploy_id, app_name, latest_ver))

            return HttpResponseRedirect(reverse('deploy_list'))
    else:
        form = DocumentForm(instance=project)
        deploy_id = Deploy.objects.get(
            Q(app_name_id=app_name_id) & Q(version=latest_ver)).id

    results = {
        'form': form,
        'app_name_id': app_name_id,
        'version': latest_ver,
        'deploy_id': deploy_id,
        'request': request,
    }
    return render(request, 'orders/deploy_document.html', results)