def edit(self, id):
        from uliweb.utils.generic import EditView
        from forms import ApproveEditForm
        from uliweb.form.layout import BootstrapTableLayout

        obj = self.model.get(int(id))
        helper = ApproveHelper()
        helper.bind(obj, get_workflow=True)
        tasks = helper.get_active_tasks()
        if len(tasks) == 1:
            task_id = tasks[0].get_unique_id()
            fields = [{"name": "trans_message", "verbose_name": "流转意见"}]

            if helper.has_deliver_permission(tasks[0], request.user):

                task_name = tasks[0].get_name()

                form_cls = ApproveEditForm().get_form(task_name)
                fields = form_cls.fields
                layout = form_cls.layout
                auto_fill_fields = form_cls.auto_fill_fields
                if hasattr(form_cls, "static_fields"):
                    static_fields = form_cls.static_fields
                else:
                    static_fields = fields[0:-1]

                def pre_save(obj, data):
                    if auto_fill_fields:
                        data[auto_fill_fields[0]] = request.user.id
                        data[auto_fill_fields[1]] = datetime.datetime.now()

                def post_created_form(fcls, model, obj):
                    fcls.layout_class_args = {"table_class": "table width100"}
                    fcls.layout_class = BootstrapTableLayout

                view = EditView(
                    self.model,
                    url_for(self.__class__.view, id=id),
                    fields=fields,
                    static_fields=static_fields,
                    post_created_form=post_created_form,
                    obj=obj,
                    pre_save=pre_save,
                    layout=layout,
                )
                return view.run()
            else:
                flash(u"您没有权限访问编辑填写功能。")
                return redirect(url_for(ApproveView.view, id=id))
        else:
            flash(u"您没有权限访问编辑填写功能。")
            return redirect(url_for(ApproveView.view, id=id))
    def view(self, id):
        from uliweb.utils.generic import DetailView
        from forms import ApproveEditForm

        obj = self.model.get(int(id))

        helper = ApproveHelper()
        helper.bind(obj, get_workflow=True)

        tasks = helper.get_active_tasks()

        if len(tasks) == 1:

            task_id = tasks[0].get_unique_id()
            task_name = tasks[0].get_name()
            form_cls = ApproveEditForm().get_form(task_name)
            auto_fill_fields = form_cls.auto_fill_fields
            fields = form_cls.fields + auto_fill_fields
            layout = form_cls.layout + auto_fill_fields

            view = DetailView(self.model, obj=obj, fields=fields, layout=layout)
            result = view.run()

            data = {"detailview": result["view"], "obj": result["object"], "workflow": helper.get_workflow()}

            fields = [{"name": "trans_message", "verbose_name": "流转意见"}]

            if helper.has_deliver_permission(tasks[0], request.user):
                next_tasks = tasks[0].get_next_tasks()
                form = get_deliver_form(tasks[0], next_tasks)

                data.update(
                    {
                        "deliverform": form,
                        "show_deliver_form": True,
                        "task_desc": tasks[0].get_desc(),
                        "task_name": tasks[0].get_name(),
                    }
                )

            else:
                data.update(
                    {"show_deliver_form": False, "task_desc": tasks[0].get_desc(), "task_name": tasks[0].get_name()}
                )

        else:
            if not helper.workflow_is_running():
                formClass = "Archiver"
            else:
                formClass = obj.task_spec_name
            form_cls = ApproveEditForm().get_form(formClass)
            auto_fill_fields = form_cls.auto_fill_fields
            fields = form_cls.fields + auto_fill_fields
            layout = form_cls.layout + auto_fill_fields

            view = DetailView(self.model, obj=obj, fields=fields, layout=layout)
            result = view.run()

            data = {"detailview": result["view"], "obj": result["object"], "workflow": helper.get_workflow()}
            data.update({"show_deliver_form": False, "task_desc": None})

        return data