예제 #1
0
def addcase():
    form = AddCaseForm(next=request.referrer)
    temp = [(0, _(u'请选择所属模块'))]

    form.module_type.choices = temp + [(item.id, _(item.name))
                                       for item in ModuleType.query.
                                       get_allsubmodule()]

    if form.validate_on_submit():
        case = Case()
        """
        if form.attach_pre.has_file():
            filename = up.save(form.attach_pre.data)
            case.precondition_path = unicode(filename)
        if form.attach_process.has_file():
            filename = up.save(form.attach_process.data)
            case.process_path = unicode(filename)
        if form.attach_other.has_file():
            filename = up.save(form.attach_other.data)
            case.other_path = unicode(filename)
        """
        case.author_id = g.user.id
        form.populate_obj(case)
        if case.module_type:
            case.parent_id = ModuleType.query.get_or_404(form.module_type.data).\
                parent_id
            db.session.add(case)
            db.session.commit()
            clear_cache()
            flash(u"Add {0} successfully!".format(case.title), "success")
            return redirect(form.next.data or url_for("case.showcase"))
    parents = ModuleType.query.get_parent()
    nodes = ModuleType.query.get_allsubmodule()
    return render_template('case/case.html', form=form, parents=parents,
                           nodes=nodes)
예제 #2
0
def copycase(case_id):
    case = Case.query.get_or_404(case_id)
    case.title = None
    form = EditCaseForm(case, next=request.referrer)
    #attention performance refresh
    db.session.refresh(case)
    #print form.module_type.data
    form.module_type.choices = [(item.id, _(item.name))
                                for item in ModuleType.query.
                                get_allsubmodule()]
    if form.validate_on_submit():
        new_case = Case()
        form.populate_obj(new_case)
        print new_case.title
        new_case.author_id = g.user.id
        if new_case.parent_id != ModuleType.query.\
                get_or_404(form.module_type.data).parent_id:
            new_case.parent_id = ModuleType.query.\
                get_or_404(form.module_type.data).parent_id
        new_case.case_create_time = datetime.now()
        new_case.case_update_time = datetime.now()
        db.session.add(new_case)
        db.session.commit()
        clear_cache()
        flash(u"Copy {0} successfully!".format(new_case.title), "success")
        return redirect(form.next.data or url_for("case.showcase"))
    parents = ModuleType.query.get_parent()
    nodes = ModuleType.query.get_allsubmodule()
    return render_template('case/editcase.html', form=form, parents=parents,
                           nodes=nodes)
예제 #3
0
def addcase():
    form = AddCaseForm(next=request.referrer)
    temp = [(0, _(u'请选择所属模块'))]

    form.module_type.choices = temp + [(item.id, _(
        item.name)) for item in ModuleType.query.get_allsubmodule()]

    if form.validate_on_submit():
        case = Case()
        """
        if form.attach_pre.has_file():
            filename = up.save(form.attach_pre.data)
            case.precondition_path = unicode(filename)
        if form.attach_process.has_file():
            filename = up.save(form.attach_process.data)
            case.process_path = unicode(filename)
        if form.attach_other.has_file():
            filename = up.save(form.attach_other.data)
            case.other_path = unicode(filename)
        """
        case.author_id = g.user.id
        form.populate_obj(case)
        if case.module_type:
            case.parent_id = ModuleType.query.get_or_404(form.module_type.data).\
                parent_id
            db.session.add(case)
            db.session.commit()
            clear_cache()
            flash(u"Add {0} successfully!".format(case.title), "success")
            return redirect(form.next.data or url_for("case.showcase"))
예제 #4
0

@case.route("/<int:case_id>/copycase/", methods=("GET", "POST"))
def copycase(case_id):
    case = Case.query.get_or_404(case_id)
    case.title = None
    form = EditCaseForm(case, next=request.referrer)
    #attention performance refresh
    db.session.refresh(case)
    #print form.module_type.data
    form.module_type.choices = [
        (item.id, _(item.name))
        for item in ModuleType.query.get_allsubmodule()
    ]
    if form.validate_on_submit():
        new_case = Case()
        form.populate_obj(new_case)
        print new_case.title
        new_case.author_id = g.user.id
        if new_case.parent_id != ModuleType.query.\
                get_or_404(form.module_type.data).parent_id:
            new_case.parent_id = ModuleType.query.\
                get_or_404(form.module_type.data).parent_id
        new_case.case_create_time = datetime.now()
        new_case.case_update_time = datetime.now()
        db.session.add(new_case)
        db.session.commit()
        clear_cache()
        flash(u"Copy {0} successfully!".format(new_case.title), "success")
        return redirect(form.next.data or url_for("case.showcase"))
    parents = ModuleType.query.get_parent()