Пример #1
0
class NodeModelView(ModelView):

    can_batchly_edit = False

    def try_create(self):
        raise PermissionDenied

    def try_edit(self, objs=None):
        handle_node.test()

    __list_columns__ = [
        column_spec.ColumnSpec('work_flow.id', label=u'工作流编号'),
        column_spec.ColumnSpec('name', label=u'名称'),
        column_spec.PlaceHolderColumnSpec(
            'annotation',
            label=u'描述',
            template_fname=
            'work-flow/permit-delivery-task-with-abnormal-weight-annotation.html'
        ),
        column_spec.ColumnSpec('create_time',
                               label=u'创建时间',
                               formatter=lambda v, obj: v.strftime(
                                   '%Y年%m月%d日 %H:%M').decode('utf-8')),
        column_spec.ColumnSpec('handle_time',
                               label=u'处理时间',
                               formatter=lambda v, obj: v.strftime(
                                   '%Y年%m月%d日 %H:%M').decode('utf-8')
                               if v else '--'),
        column_spec.ColumnSpec('work_flow.status',
                               label=u'工作流状态',
                               formatter=_get_literally_status)
    ]

    __sortable_columns__ = ['work_flow.id', 'create_time']

    __default_order__ = ("create_time", "desc")

    __column_filters__ = [
        filters.EqualTo('work_flow.id', name=u'是', display_col_name=u'工作流编号'),
        filters.Only('handle_time',
                     display_col_name=u'仅展示待处理工作流',
                     test=lambda col: col == None,
                     default_value=True,
                     notation="__only_unhandled"),
        filters.Between('create_time', name=u'介于', display_col_name=u'创建时间')
    ]

    def get_customized_actions(self, objs=None):
        return [_refuse_node, _approve_node]

    def __list_filters__(self):
        return [
            filters.EqualTo('handler_group_id', value=current_user.group.id),
        ]
Пример #2
0
class DepartmentModelView(AdminModelView):
    __list_columns__ = [
        "id", "name",
        column_spec.PlaceHolderColumnSpec(
            "team_list",
            label=u"班组列表",
            template_fname="admin/department-team-list-snippet.html"),
        column_spec.PlaceHolderColumnSpec(
            "leader_list",
            label=u"车间主任",
            template_fname="admin/department-leader-list-snippet.html"),
        column_spec.PlaceHolderColumnSpec(
            "procedure_list",
            label=u"允许工序",
            template_fname="admin/department-procedure-list-snippet"
            ".html")
    ]

    __create_columns__ = __form_columns__ = [
        "name",
        column_spec.InputColumnSpec(
            "leader_list",
            label=u"车间主任列表",
            opt_filter=lambda obj: any(
                (group.id == groups_const.DEPARTMENT_LEADER)
                for group in obj.groups),
            doc=u'只有用户组是"车间主任", 才能作为车间主任'), "procedure_list"
    ]

    __column_labels__ = {
        "id": u"编号",
        "name": u"名称",
        "leader_list": u"车间主任列表",
        "procedure_list": u"车间允许工序列表"
    }

    __customized_actions__ = [DeleteAction(u"删除", AdminPermission)]

    def populate_obj(self, form):
        return Department(name=form.name.data, leaders=form.leader_list.data)
Пример #3
0
class UserModelView(AdminModelView):
    edit_template = create_template = "admin/user.html"
    column_hide_backrefs = False

    __list_columns__ = [
        "id", "username",
        column_spec.PlaceHolderColumnSpec(
            "groups",
            label=u"用户组",
            template_fname="admin/user-groups-snippet.html"), 'enabled'
    ]
    __column_labels__ = {
        "id": u"编号",
        "username": u"用户名",
        "group": u"用户组",
        "password": u"密码(md5加密)",
        "groups": u"用户组列表",
        'enabled': u'激活'
    }
    __column_formatters__ = {"enabled": lambda v, obj: u"是" if v else u"否"}

    class UserDeleteAction(DeleteAction):
        def test_enabled(self, obj):
            if obj.id == constants.ADMIN_USER_ID:
                return -2
            return 0

        def get_forbidden_msg_formats(self):
            return {-2: u"您不能删除超级管理员!"}

    def get_column_filters(self):
        class UserGroupFilter(BaseFilter):
            def set_sa_criterion(self, query):
                if isinstance(self.value,
                              numbers.Number) or self.value.isdigit():
                    self.value = int(self.value)
                    query = query.filter(
                        User.groups.any(Group.id == self.value))
                return query

        return [
            UserGroupFilter(u"group",
                            name=u"是",
                            options=[(group.id, group.name)
                                     for group in Group.query.all()]),
            Contains(u'username', name=u'包含')
        ]

    # ============ FORM PART ===========================
    __create_columns__ = __form_columns__ = [
        "username", "password", "groups", 'enabled'
    ]
Пример #4
0
    def get_form_columns(self, obj=None):

        form_columns = OrderedDict()
        c = column_spec.ColumnSpec("",
                                   formatter=lambda v, obj: u"%s-%s" %
                                   (v.id, v.cause_name) if v else "")

        form_columns[u"工单信息"] = [
            column_spec.ColumnSpec("id"),
            column_spec.ColumnSpec("org_weight"),
            column_spec.ColumnSpec("org_cnt"),
            column_spec.ColumnSpec("sub_order.unit"),
            column_spec.ColumnSpec("sub_order.spec", label=u"规格"),
            column_spec.ColumnSpec("sub_order.type", label=u"型号"), "urgent",
            "sub_order.returned", "tech_req",
            column_spec.ColumnSpec("cause_name", label=u"产生原因"),
            column_spec.ColumnSpec("previous_work_command",
                                   label=u"上级工单",
                                   formatter=lambda v, obj: u"%s-%s" %
                                   (v.id, v.cause_name) if v else ""),
            column_spec.ListColumnSpec("next_work_command_list",
                                       label=u"下级工单",
                                       item_col_spec=c),
            column_spec.PlaceHolderColumnSpec(
                "log_list", label=u"日志", template_fname="logs-snippet.html")
        ]
        form_columns[u"加工信息"] = [
            column_spec.ColumnSpec("department"),
            column_spec.ColumnSpec("team"),
            column_spec.ColumnSpec("procedure"),
            column_spec.ColumnSpec("previous_procedure"),
            column_spec.ColumnSpec("processed_weight", label=u"工序后重量"),
            column_spec.ColumnSpec("processed_cnt", label=u"工序后数量"),
            column_spec.ColumnSpec("status_name", label=u"状态"),
            column_spec.ColumnSpec("completed_time", label=u"生产结束时间"),
            column_spec.ColumnSpec(
                "handle_type",
                label=u"处理类型",
                formatter=lambda v, obj: get_handle_type_list().get(v, u"未知"))
        ]
        if obj and obj.qir_list:
            from lite_mms.apis.quality_inspection import get_QI_result_list
            from lite_mms.portal.quality_inspection.views import qir_model_view

            def result(qir):
                for i in get_QI_result_list():
                    if qir.result == i[0]:
                        status = i[1]
                        break
                else:
                    status = u"未知"
                return u"<a href='%s'>质检单%s%s了%s(公斤)</a>" % (
                    qir_model_view.url_for_object(
                        qir, url=request.url), qir.id, status, qir.weight)

            form_columns[u"质检信息"] = [
                column_spec.ListColumnSpec(
                    "qir_list",
                    label=u"质检结果",
                    formatter=lambda v, obj: [result(qir) for qir in v])
            ]

        form_columns[u"订单信息"] = [
            column_spec.ColumnSpec("sub_order"),
            column_spec.ColumnSpec("sub_order.order", label=u"订单号")
        ]
        return form_columns
Пример #5
0
class QIR(ModelView):
    @login_required
    def try_view(self, processed_objs=None):
        pass

    def try_create(self):
        raise PermissionDenied

    can_batchly_edit = False

    def try_edit(self, processed_objs=None):
        QualityInspectorPermission.test()
        raise PermissionDenied

    def edit_hint_message(self, obj, read_only=False):
        if read_only:
            if QualityInspectorPermission.can():
                return u"质检报告%s不能在浏览器上修改" % obj.id
            else:
                return u"您没有修改质检报告%s的权限" % obj.id
        else:
            return super(QIR, self).edit_hint_message(obj, read_only)

    __default_order__ = ("id", "desc")

    __list_columns__ = [
        "id", "work_command_id", "weight", "quantity",
        column_spec.ColumnSpec("result",
                               label=u"质检结果",
                               formatter=lambda v, obj: get_QI_result(v)),
        column_spec.ColumnSpec("actor", label=u"质检员"),
        column_spec.ImageColumnSpec("pic_url",
                                    label=u"图片",
                                    css_class="img-responsive img-polaroid")
    ]

    __column_labels__ = {
        "id": u"编号",
        "quantity": u"数量",
        "weight": u"重量",
        "work_command_id": u"工单号"
    }

    __form_columns__ = [
        column_spec.ColumnSpec("id"), "weight", "quantity",
        column_spec.ColumnSpec('unit', label=u"单位"),
        column_spec.SelectColumnSpec(col_name="result",
                                     label=u"质检结果",
                                     choices=get_QI_result_list()),
        column_spec.ColumnSpec("work_command", label=u"工单编号"),
        column_spec.ColumnSpec("report_time", label=u"创建时间"),
        column_spec.ColumnSpec("actor", label=u"质检员"),
        column_spec.PlaceHolderColumnSpec("pic_url",
                                          template_fname="pic-snippet.html",
                                          label=u"图片")
    ]

    __column_filters__ = [
        filters.EqualTo("result",
                        display_col_name=u"质检结果",
                        options=get_QI_result_list())
    ]

    def preprocess(self, obj):
        from lite_mms.apis.quality_inspection import QIReportWrapper

        return QIReportWrapper(obj)