コード例 #1
0
ファイル: commonIssueView.py プロジェクト: AKMFCJ/tms
def add_common_issue():
    """添加项目共性问题"""

    for index, breadcrumb in enumerate(session['breadcrumbs']):
        if '添加问题' == breadcrumb['text']:
            session['breadcrumbs'] = session['breadcrumbs'][:index + 1]
            break
    else:
        session['breadcrumbs'].append(
            {'text': '添加问题', 'url': url_for('project.add_common_issue')})

    common_issue = CommonIssue()

    all_project = [tmp for tmp in ProjectAndroid.query.all() if tmp.status != '关闭']
    all_platform = BPlatform.query.all()
    all_developer = User.query.join(Role).filter(db.and_(User.activate==True, Role.name=='developer')).all()
    all_spm = User.query.join(Role).filter(db.and_(User.activate==True, Role.name=='spm')).all()

    if request.method == 'POST':
        name = request.form.get('name', '').strip()
        project_id = request.form.get('project_id', '')
        description = request.form.get('description', '').strip()
        solutions = request.form.get('solutions', '').strip()
        effect_scope = ','.join(request.form.getlist('effect_scope'))
        platform_name = request.form.get('platform_name', '')
        baseline_name = request.form.get('baseline_name', '').strip()
        jira_key = request.form.get('jira_key', '').strip()
        attachment = request.form.get('attachment', '')
        developer_id = request.form.get('developer_id', '')
        spm_id = request.form.get('spm_id', '')

        other = CommonIssue.query.filter(CommonIssue.name == name).first()
        if other:
            flash(u'同名的共性问题已存在', 'warning')
        else:
            common_issue.name = name
            common_issue.project_id = project_id
            common_issue.description = description
            common_issue.solutions = solutions
            common_issue.effect_scope = effect_scope
            common_issue.platform_name = platform_name
            common_issue.baseline_name = baseline_name
            common_issue.tester_id = current_user.id
            if jira_key:
                common_issue.jira_key = jira_key
            if developer_id:
                common_issue.developer_id = developer_id
                common_issue.status = 2
            if spm_id:
                common_issue.spm_id = spm_id
            common_issue.submit_issue_time = datetime.now()
            common_issue.attachment = attachment

            db.session.add(common_issue)
            db.session.commit()

            # 给开发工程师发送邮件,让其填写解决方案
            cc_list = [user.email for user in User.query.join(Role).filter(Role.name == 'scm').all()]

            msg = Message(
                u'[TSDS] %s 新增项目共性问题' % (project.name),
                sender='*****@*****.**',
                # recipients=[common_issue.developer.email]
                recipients=['*****@*****.**']
            )
            msg.html = '<h5>项目共性问题名称</h5>:<br>{0}<br><br>' \
                       '<h5>问题创建人</h5>:<br>{1}<{2}><br><br>' \
                       '<h5>提出问题项目</h5>:<br>{3}<br><br>' \
                       '<h5>项目所属平台名称</h5>:<br>{4}<br><br>' \
                       '<h5>项目当前基线</h5>:<br>{5}<br><br>' \
                       '问题描述:<br>{6}<br>'.format(common_issue.name, current_user.display_name, current_user.email,
                                                 common_issue.project.name, common_issue.platform_name,
                                                 common_issue.baseline_name, common_issue.description)
            mail.send(msg)

            return redirect(url_for('project.common_issue_page'))

    return render_template('project/android/common_issue/common_issue_edit.html',
                           common_issue=common_issue,
                           all_project=all_project,
                           all_developer=all_developer,
                           all_spm=all_spm,
                           all_platform=all_platform)
コード例 #2
0
ファイル: views.py プロジェクト: AKMFCJ/tms
def version_test(version_id):
    """版本测试结果"""

    # 显示版本信息
    if request.method == 'GET':
        for index, breadcrumb in enumerate(session['breadcrumbs']):
            if u'版本测试' == breadcrumb['text']:
                session['breadcrumbs'] = session['breadcrumbs'][:index+1]
                break
        else:
            session['breadcrumbs'].append({'text': '版本测试',
                                           'url': url_for('qa.version_test', version_id=version_id)})

        version = Version.query.filter_by(id=version_id).first()
        tasks = []

        # 测试权限
        test_permission = False
        # 发布全新
        release_permission = False

        if session['user']['role_name'] == 'os_test' and version.status == '测试':
            test_permission = True

        if session['user']['role_name'] == 'os_test' and version.status == '测试通过':
            release_permission = True

        if version.tasks:
            tasks = json.loads(version.tasks, strict=False)

        if version.documents and version.documents.strip():
            #documents = [(os.path.basename(tmp), os.path.getsize(tmp)/1024, tmp.replace('/', '<>')) for tmp in
            # version.documents.split('#') if tmp.strip()]
            documents = [(os.path.basename(tmp), '', tmp.replace('/', '<>')) for tmp in version.documents.split('#') if tmp.strip()]
        else:
            documents = []
        version_level = ['Recommend', 'Must']

        return render_template('/qa/version_test.html',
                               documents=documents,
                               version=version,
                               test_permission=test_permission,
                               release_permission=release_permission,
                               tasks=tasks,
                               version_level=version_level,
                               current_page='qa.my_version')
    # 版本测试结果
    elif request.method == 'POST':
        version = Version.query.filter_by(id=version_id).first()
        project = version.project
        version.release_note = request.form.get('release_note', '')
        version.version_issues = request.form.get('version_issues', '')
        version.unresolved_issues = request.form.get('unresolved_issues', '')
        version.testing_time = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
        version.test_user = current_user
        smi = request.form.get('smi', '')
        if smi:
            version.smi = int(smi)
        version.level = request.form.get('level', 'Recommend')
        result = request.form.get('result', '')
        version.special_version.release_path = request.form.get('release_path', '')

        # 测试通过后发送邮件地址
        test_pass_to_email = request.form.get('test_pass_to_email', '')
        if test_pass_to_email:
            project.test_pass_to_email = ';'.join([tmp.strip() for tmp in test_pass_to_email.split(';') if tmp.strip()])

        # 测试失败发送的邮件地址
        test_failure_to_email = request.form.get('test_failure_to_email', '')
        if test_failure_to_email:
            project.test_failure_to_email = ';'.join([tmp.strip() for tmp in test_failure_to_email.split(';') if tmp.strip()])

        # 选择发放版本,默认是全部
        need_release_file = request.form.get('need_release_file', '')
        if need_release_file:
            version.release_file = '#'.join([tmp.strip() for tmp in need_release_file.split('#') if tmp.strip()])
        else:
            version.release_file = version.ftp_file

        # 保存上传的附件
        exits_documents = [tmp.strip() for tmp in version.documents.split('#') if tmp.strip()]
        documents = request.files.getlist("file[]")

        if documents:
            upload_path = os.path.join(current_app.config['UPLOAD_FOLDER'], version.name, version.version_number)
            if not os.path.exists(upload_path):
                os.makedirs(upload_path)
            for document in documents:
                if document.filename:
                    current_app.logger.info(document.filename)
                    file_path = os.path.join(upload_path, document.filename)
                    # 删除已存在的
                    if os.path.exists(file_path) and os.path.isfile(file_path):
                        os.remove(file_path)

                    document.save(file_path)
                    if file_path not in exits_documents:
                        exits_documents.append(file_path)

        version.documents = '#'.join(exits_documents)

        # 通知邮件
        to_list = []
        cc_list = []
        # 版本编译工程师
        to_list.append(version.compile_email)
        # 软件开发负责人
        if project.develop_leader and project.develop_leader.email:
            to_list.append(project.develop_leader.email)
        # 软件的邮件记录
        if project.to_email:
            for email in project.to_email.split(';'):
                if email.strip():
                    cc_list.append(email)

        # 版本历史记录
        version_history = VersionHistory()

        # 测试不通过不能发放
        if result == '-1':
            if project.test_failure_to_email:
                for email in project.test_failure_to_email.split(';'):
                    if email.strip():
                        to_list.append(email)

            version.status = '测试不过'
            version.testing_result = False
            version_history.description = "{0}版本测试结果: 测试失败\n 测试人:{1}\n版本缺陷:{2}\n遗留问题{3}".format(
                version.name, current_user.username, version.version_issues, version.unresolved_issues)
            # 去重复
            to_list = list(set(to_list))
            cc_list = list(set(cc_list))
            msg = Message(
                '[TSDS] %s_%s 版本测试不通过' % (version.name, version.version_number),
                sender='*****@*****.**',
                # recipients=[version.project.test_leader.email, '*****@*****.**', '*****@*****.**']
                recipients=to_list,
                cc=cc_list
                # recipients=['*****@*****.**']
            )
            msg.html = TEST_FAILURE_TEMPLATE.format(version.project.name,
                                                    version.name,
                                                    version.version_number,
                                                    version.level,
                                                    version.version_issues,
                                                    current_user.display_name,
                                                    current_user.email).replace('通讯录', '通 讯 录')
            mail.send(msg)

            flash(u'提交成功', 'info')
        # 版本废弃
        elif result == '4':
            version.status = '已废弃'
            version.version_discard_time = datetime.now()
            version.discard_user_id = current_user.id

            db.session.add(version)

        # 研发版本测试结果通知
        elif result == '5':
            version.status = '测试通过'
            version.test_user_id = current_user.id
            version.testing_result = True
            version.testing_time = datetime.now()

            db.session.add(version)

            # 版本测试通过后需要通知的人员
            if project.test_pass_to_email:
                for email in project.test_pass_to_email.split(';'):
                    if email.strip():
                        to_list.append(email)
            # 配置组
            to_list.append('*****@*****.**')
            for scm in User.query.join(Role).filter(Role.name == 'scm').all():
                cc_list.append(scm.email)

            to_list = list(set(to_list + cc_list))
            content = VERSION_TEST_TEMPLATE.format(project.name,
                                              version.name,
                                              version.version_number,
                                              version.smi,
                                              version.version_issues.replace('<', '&lt;').replace('\n', '<br>'),
                                              version.release_note.replace('<', '&lt;').replace('\n', '<br>'),
                                              current_user.display_name,
                                              current_user.email).replace('通讯录', '通 讯 录')
            message = {
                'to_list': ';'.join([tmp for tmp in to_list if tmp]),
                'sub': '[TSDS] {0}_{1}版本,测试结果'.format(project.name, version.version_number),
                'content': content
            }
            send_mail_pubisher(json.dumps(message))

            version_history.description = "{0}版本测试结果: 测试通过,测试通过\n 测试人:{1}\n版本缺陷:{2}\n遗留问题{3}" \
                                          "\n发布说明{4}\n适配信息{5}\n导入注意事项{6}".format(version.name,
                                                                                 current_user.username,
                                                                                 version.version_issues,
                                                                                 version.unresolved_issues,
                                                                                 version.release_note,
                                                                                 version.adaptation_note,
                                                                                 version.project_import_note)
            flash(u'提交成功', 'info')

        # 测试通过进行版本发放
        else:
            # 版本测试通过后需要通知的人员
            if project.test_pass_to_email:
                for email in project.test_pass_to_email.split(';'):
                    if email.strip():
                        to_list.append(email)
            # 配置组
            to_list.append('*****@*****.**')
            for scm in User.query.join(Role).filter(Role.name == 'scm').all():
                cc_list.append(scm.email)

            version.status = '已发布'
            version.testing_result = True
            version.release_time = datetime.now()
            version.release_user_id = current_user.id
            version.release_note = request.form.get('release_note', '')
            version.adaptation_note = request.form.get('adaptation_note', '')
            version.project_import_note = request.form.get('project_import_note', '')

            project.last_release_time = version.release_time
            project.last_version_number = version.version_number

            if result == '1':
                # version.release_type = '特殊发放'
                # msg = Message(
                #     '[TSDS] {0}_{1} 特殊发放'.format(project.name, version.version_number),
                #     sender='*****@*****.**',
                #     recipients=to_list,
                #     cc=cc_list
                #     # recipients=['*****@*****.**']
                # )
                # if version.documents:
                #     for document in version.documents.split('#'):
                #         if document:
                #             file_name = os.path.basename(document)
                #             with current_app.open_resource(document) as fp:
                #                 msg.attach(file_name.encode("utf-8"),
                #                            current_app.config['MIME_TYPE'][os.path.splitext(file_name)[1]], fp.read())
                #
                # msg.html = SPECIAL_VERSION_TEMPLATE.format(project.name,
                #                                            version.name,
                #                                            version.version_number,
                #                                            version.smi,
                #                                            version.level,
                #                                            version.project_import_note,
                #                                            project.apk_name,
                #                                            project.apk_package,
                #                                            version.special_version.release_path,
                #                                            version.release_note.replace('\n', '<br>'),
                #                                            version.unresolved_issues.replace('\n', '<br>'),
                #                                            current_user.display_name,
                #                                            current_user.email)
                # mail.send(msg)
                content = SPECIAL_VERSION_TEMPLATE.format(project.name,
                                                           version.name,
                                                           version.version_number,
                                                           version.smi,
                                                           version.level,
                                                           version.project_import_note.replace('<', '&lt;'),
                                                           project.apk_name,
                                                           project.apk_package,
                                                           version.special_version.release_path,
                                                           version.release_note.replace('<', '&lt;').replace('\n', '<br>'),
                                                           version.unresolved_issues.replace('<', '&lt;').replace('\n', '<br>'),
                                                           current_user.display_name,
                                                           current_user.email).replace('通讯录', '通 讯 录')
                to_list = list(set(to_list + cc_list))
                message = {
                    'to_list': ';'.join([tmp for tmp in to_list if tmp]),
                    'sub': '[TSDS] {0}_{1} 特殊发放'.format(project.name, version.version_number),
                    'content': content
                }
                send_mail_pubisher(json.dumps(message))

            elif result == '2':
                version.release_type = 'DCC发放'
                # msg = Message(
                #     '[TSDS] {0}_{1}版本,DCC发放'.format(project.name, version.version_number),
                #     sender='*****@*****.**',
                #     recipients=to_list,
                #     cc=cc_list
                #     # recipients=['*****@*****.**']
                # )
                # if version.documents:
                #     for document in version.documents.split('#'):
                #         if document:
                #             file_name = os.path.basename(document)
                #             with current_app.open_resource(document) as fp:
                #                 msg.attach(file_name.encode("utf-8"),
                #                            current_app.config['MIME_TYPE'][os.path.splitext(file_name)[1]], fp.read())
                #     msg.html = DCC_RELEASE_TEMPLATE.format(project.name,
                #                                            version.name,
                #                                            version.version_number,
                #                                            version.smi,
                #                                            version.level,
                #                                            project.apk_name,
                #                                            project.apk_package,
                #                                            version.special_version.release_path,
                #                                            version.release_note.replace('\n', '<br>'),
                #                                            project.name,
                #                                            version.adaptation_note,
                #                                            version.unresolved_issues.replace('\n', '<br>'),
                #                                            current_user.display_name,
                #                                            current_user.email)
                #
                #     mail.send(msg)
                to_list = list(set(to_list + cc_list))
                content = DCC_RELEASE_TEMPLATE.format(project.name,
                                                       version.name,
                                                       version.version_number,
                                                       version.smi,
                                                       version.level,
                                                       project.apk_name,
                                                       project.apk_package,
                                                       version.special_version.release_path,
                                                       version.release_note.replace('<', '&lt;').replace('\n', '<br>'),
                                                       project.name,
                                                       version.adaptation_note.replace('<', '&lt;'),
                                                       version.unresolved_issues.replace('<', '&lt;').replace('\n', '<br>'),
                                                       current_user.display_name,
                                                       current_user.email).replace('通讯录', '通 讯 录')
                message = {
                    'to_list': ';'.join([tmp for tmp in to_list if tmp]),
                    'sub': '[TSDS] {0}_{1}版本,DCC发放'.format(project.name, version.version_number),
                    'content': content
                }
                send_mail_pubisher(json.dumps(message))

            elif result == '3':
                version.release_type = '迭代发放'
                # msg = Message(
                #     '[TSDS] {0}_{1}版本,迭代发放'.format(project.name, version.version_number),
                #     sender='*****@*****.**',
                #     recipients=to_list,
                #     cc=cc_list
                #     # recipients=['*****@*****.**']
                # )
                # if version.documents:
                #     for document in version.documents.split('#'):
                #         if document:
                #             file_name = os.path.basename(document)
                #             with current_app.open_resource(document) as fp:
                #                 msg.attach(file_name.encode("utf-8"),
                #                            current_app.config['MIME_TYPE'][os.path.splitext(file_name)[1]], fp.read())
                # msg.html = RELEASE_TEMPLATE.format(project.name,
                #                                    version.name,
                #                                    version.version_number,
                #                                    version.smi,
                #                                    version.level,
                #                                    project.apk_name,
                #                                    project.apk_package,
                #                                    version.special_version.release_path,
                #                                    version.release_note.replace('\n', '<br>'),
                #                                    version.unresolved_issues.replace('\n', '<br>'),
                #                                    current_user.display_name,
                #                                    current_user.email)
                # mail.send(msg)
                to_list = list(set(to_list + cc_list))
                content = RELEASE_TEMPLATE.format(project.name,
                                                   version.name,
                                                   version.version_number,
                                                   version.smi,
                                                   version.level,
                                                   project.apk_name,
                                                   project.apk_package,
                                                   version.special_version.release_path,
                                                   version.release_note.replace('<', '&lt;').replace('\n', '<br>'),
                                                   version.unresolved_issues.replace('<', '&lt;').replace('\n', '<br>'),
                                                   current_user.display_name,
                                                   current_user.email).replace('通讯录', '通 讯 录')
                message = {
                    'to_list': ';'.join([tmp for tmp in to_list if tmp]),
                    'sub': '[TSDS] {0}_{1}版本,迭代发放'.format(project.name, version.version_number),
                    'content': content
                }
                send_mail_pubisher(json.dumps(message))

            version_history.description = "{0}版本测试结果: 测试通过,已发布\n 测试人:{1}\n版本缺陷:{2}\n遗留问题{3}" \
                                          "\n发布说明{4}\n适配信息{5}\n导入注意事项{6}".format(version.name,
                                                                                 current_user.username,
                                                                                 version.version_issues,
                                                                                 version.unresolved_issues,
                                                                                 version.release_note,
                                                                                 version.adaptation_note,
                                                                                 version.project_import_note)
            flash(u'发布成功', 'info')

        version_history.version_id = version_id
        version_history.option_username = session['user']['username']
        version_history.option_email = session['user']['email']
        version_history.option_time = datetime.now().strftime('%Y-%m-%d %H:%M:%S')

        db.session.add(version)
        db.session.add(version_history)
        db.session.add(version.special_version)
        db.session.add(project)
        db.session.commit()

        return redirect(url_for('qa.version_test', version_id=version_id))