Exemple #1
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)
Exemple #2
0
def editcase(case_id):
    case = Case.query.get_or_404(case_id)
    case.permissions.edit.test(403)
    form = EditCaseForm(case, next=request.referrer)
    #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():
        """
        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)
        if case.author_id != g.user.id:
            case.author_id = g.user.id
        """
        form.populate_obj(case)
        if case.parent_id != ModuleType.query.\
                get_or_404(form.module_type.data).parent_id:
            case.parent_id = ModuleType.query.\
                get_or_404(form.module_type.data).parent_id
        case.case_update_time = datetime.now()
        db.session.add(case)
        db.session.commit()
        clear_cache()
        flash(u"Update {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/editcase.html', form=form, parents=parents,
                           nodes=nodes)