Example #1
0
def consignment(id_=None):
    import litefac.apis as apis
    from flask.ext.principal import Permission

    Permission.union(CargoClerkPermission, AccountantPermission).test()
    if request.method == "GET":
        cons = apis.delivery.get_consignment(id_)
        team_list = apis.manufacture.get_team_list()
        if not cons:
            abort(404)
        else:
            return dict(plate=cons.plate, consignment=cons, titlename=u'发货单详情',
                        team_list=team_list)
    else:
        if id_:
            cons = apis.delivery.get_consignment(id_)
            if not cons:
                abort(404)
            params = {}
            if request.form:
                params["pay_in_cash"] = request.form.get("pay_in_cash",
                                                         type=int)
                params["notes"] = request.form.get("notes")
                try:
                    cons.update(cons.id, **params)
                    if CargoClerkPermission.can():
                        flash(u"更新成功")
                except ValueError, e:
                    flash(unicode(e.message), "error")
            else:
                if cons.pay_in_cash:
                    cons.paid()
                    flash(u"支付成功")
            return redirect(url_for("delivery.consignment", id_=id_,
                                    url=request.form.get("url")))
Example #2
0
def consignment_product(id_):
    from flask.ext.principal import Permission

    Permission.union(CargoClerkPermission, AccountantPermission).test()

    import litefac.apis as apis

    current_product = apis.delivery.ConsignmentProductWrapper.get_product(id_)
    if current_product:
        if request.method == "GET":
            return dict(current=current_product,
                        product_types=apis.product.get_product_types(),
                        products=json.dumps(apis.product.get_products()),
                        team_list=apis.manufacture.get_team_list(),
                        titlename=u"发货产品详情")
        else:
            class ProductForm(Form):
                team_id = IntegerField("team_id")
                product_id = IntegerField("product_id")
                weight = IntegerField("weight")
                returned_weight = IntegerField("returned_weight")
                spec = TextField("spec")
                type = TextField("type")
                unit = TextField("unit")

            form = ProductForm(request.form)
            current_product.update(**form.data)
            return redirect(
                request.form.get("url") or url_for("delivery.consignment",
                                                   id_=current_product.consignment.id))
    else:
        return _(u"没有该产品编号:%d" + id_), 404
Example #3
0
def consignment_preview(id_):
    from flask.ext.principal import Permission

    Permission.union(CargoClerkPermission, AccountantPermission).test()

    import lite_mms.apis as apis

    cons = apis.delivery.get_consignment(id_)
    if not cons:
        abort(404)
    else:
        per_page = apis.config.get("print_count_per_page", 5.0, type=float)
        import math

        pages = int(math.ceil(len(cons.product_list) / per_page))
        return dict(plate=cons.plate, consignment=cons, titlename=u'发货单详情',
                    pages=pages, per_page=per_page)
Example #4
0
def test_permission_and():

    p1 = Permission(RolePermit('boss'))
    p2 = Permission(RolePermit('lackey'))

    p3 = p1 & p2
    p4 = p1.union(p2)

    assert p3.allow == p4.allow
Example #5
0
def consignment_preview(id_):
    from flask.ext.principal import Permission

    Permission.union(CargoClerkPermission, AccountantPermission).test()

    import lite_mms.apis as apis

    cons = apis.delivery.get_consignment(id_)
    if not cons:
        abort(404)
    else:
        per_page = apis.config.get("print_count_per_page", 5.0, type=float)
        import math

        pages = int(math.ceil(len(cons.product_list) / per_page))
        return dict(plate=cons.plate,
                    consignment=cons,
                    titlename=u'发货单详情',
                    pages=pages,
                    per_page=per_page)
            too_late,
            'profile_update_deadline':
            format_utc_datetime(profile_deadline, eastern),
            'mit':
            mit,
            'travel':
            travel
        }
    }


ConfirmationPermission = Permission(AttributeNeed('admit', 'pending'))

UpdatePermission = Permission(AttributeNeed('admit', 'update'))

ResumePermission = ConfirmationPermission.union(UpdatePermission)

register_policy_route(
    '/accounts/<int:account_id>/resume/policy', 'resume', ResumePermission,
    lambda kwargs: 'accounts/' + str(kwargs['account_id']) + '/resume.pdf')

register_policy_route(
    '/accounts/<int:account_id>/travel/policy', 'travel',
    ConfirmationPermission,
    lambda kwargs: 'accounts/' + str(kwargs['account_id']) + '/travel.pdf')


@bp.route('/confirmation')
@ConfirmationPermission.require()
def confirmation():
    attendee = Attendee.lookup_from_account_id(
Example #7
0
 def try_view_report(self):
     Permission.union(AdminPermission, AccountantPermission).test()
Example #8
0
    def try_edit(self, processed_objs=None):
        Permission.union(SchedulerPermission, CargoClerkPermission).test()

        if processed_objs:
            if processed_objs[0].order.refined or processed_objs[0].order.dispatched:
                raise PermissionDenied
    admit = Admit.lookup_from_account_id(current_user.id)
    deadline = admit.get_deadline()
    too_late = has_passed(deadline)
    completed = admit.get_admit_data()['graduation'] is not None
    confirmed = admit.is_confirmed()
    profile_deadline = dates['profile_update_closing']
    hacker = Hacker.lookup_from_account_id(current_user.id)
    mit = (hacker.school_id == 166683)
    travel = admit.travel
    return {'name':'admit_dashboard.html', 'context':{'deadline':format_utc_datetime(deadline, eastern), 'completed':completed, 'confirmed':confirmed, 'too_late':too_late, 'profile_update_deadline':format_utc_datetime(profile_deadline, eastern), 'mit':mit, 'travel':travel}}

ConfirmationPermission = Permission(AttributeNeed('admit', 'pending'))

UpdatePermission = Permission(AttributeNeed('admit', 'update'))

ResumePermission = ConfirmationPermission.union(UpdatePermission)

register_policy_route('/accounts/<int:account_id>/resume/policy', 'resume', ResumePermission, lambda kwargs: 'accounts/' + str(kwargs['account_id']) + '/resume.pdf')

register_policy_route('/accounts/<int:account_id>/travel/policy', 'travel', ConfirmationPermission, lambda kwargs: 'accounts/' + str(kwargs['account_id']) + '/travel.pdf')

@bp.route('/confirmation')
@ConfirmationPermission.require()
def confirmation():
    attendee = Attendee.lookup_from_account_id(current_user.id).get_attendee_data()
    if attendee['badge_name'] is None:
        attendee['badge_name'] = current_user.get_name()
    admit = Admit.lookup_from_account_id(current_user.id).get_admit_data()

    admit['deadline'] = format_utc_datetime(Admit.lookup_from_account_id(current_user.id).get_deadline(), eastern)
Example #10
0
 def try_view(self, objs=None):
     Permission.union(AdminPermission, CargoClerkPermission).test()
Example #11
0
                 #default_url="/delivery/consignment-list",
                 #permissions=[AccountantPermission])
nav_bar.register(manufacture_page, name=u"质检管理",
                 default_url="/manufacture/qir-list",
                 permissions=[DepartmentLeaderPermission])
nav_bar.register(store_bill_page, name=u"仓单管理",
                 default_url="/store/store-bill-list",
                 permissions=[QualityInspectorPermission])
nav_bar.register(deduction_page, name=u"扣重管理", default_url="/deduction/",
                 permissions=[QualityInspectorPermission])
nav_bar.register(dashboard, name=u"仪表盘", permissions=[AdminPermission])

nav_bar.register(time_line_page, name=u"时间线", default_url="/timeline/log-list")
nav_bar.register(search_page, name=u"搜索", default_url="/search/search")
nav_bar.register(admin2_page, name=u"管理中心", default_url="/admin2/user-list", permissions=[AdminPermission])
nav_bar.register(report_page, name=u"报表列表", default_url="/report/report-list", permissions=[Permission.union(AdminPermission, AccountantPermission)], group=u'报表',
                 enabler=lambda nav: request.path.startswith('/report/report'))
nav_bar.register(report_page, name=u"数据集合列表", default_url="/report/data-sets", permissions=[Permission.union(AdminPermission, AccountantPermission)], group=u'报表',
                 enabler=lambda nav: request.path.startswith('/report/data-set'))
nav_bar.register(report_page, name=u"推送列表", default_url="/report/notification-list", permissions=[Permission.union(AdminPermission, AccountantPermission)], group=u'报表',
                 enabler=lambda nav: request.path.startswith('/report/notification-list'))
nav_bar.register(to_do_page, name=u"待办事项", default_url="/todo/todo-list")
nav_bar.register(qir_page, name=u"质检报告", default_url="/qir/qireport-list", permissions=[QualityInspectorPermission])
nav_bar.register(work_flow_page, name=lambda: u"工作流(%d)" % models.Node.query.filter(models.Node.handle_time==None).count(),
                 default_url="/work-flow/node-list", permissions=[CargoClerkPermission])

#install jinja utilities
from litefac.utilities import url_for_other_page, datetimeformat
from litefac.utilities.decorators import after_this_request
from litefac import permissions
Example #12
0
 def try_(self, preprocessed_objs):
     from litefac.permissions import CargoClerkPermission,AdminPermission
     from flask.ext.principal import Permission
     Permission.union(CargoClerkPermission, AdminPermission).test()
Example #13
0
    def try_(self, preprocessed_objs):
        from lite_mms.permissions import CargoClerkPermission, AdminPermission
        from flask.ext.principal import Permission

        Permission.union(CargoClerkPermission, AdminPermission).test()
Example #14
0
 def try_edit_data_set(self):
     Permission.union(AdminPermission, AccountantPermission).test()
Example #15
0
 def try_view(self, processed_objs=None):
     from flask.ext.principal import Permission
     Permission.union(CargoClerkPermission, AdminPermission).test()
Example #16
0
    def try_edit(self, processed_objs=None):
        Permission.union(SchedulerPermission, CargoClerkPermission).test()

        if processed_objs:
            if processed_objs[0].order.refined or processed_objs[0].order.dispatched:
                raise PermissionDenied
Example #17
0
    def try_view(self, processed_objs=None):
        from flask.ext.principal import Permission

        Permission.union(CargoClerkPermission, AdminPermission).test()
Example #18
0
def test_permission_union_denial():
    p1 = Permission(('a', 'b'))
    p2 = Denial(('a', 'c'))
    p3 = p1.union(p2)
    assert p1.issubset(p3)
    assert p2.issubset(p3)
Example #19
0
                 permissions=[CargoClerkPermission.union(AccountantPermission)], group=u"发货管理")
nav_bar.register(manufacture_page, name=u"工单管理",
                 permissions=[SchedulerPermission])
nav_bar.register(store_bill_page, name=u"仓单管理",
                 default_url="/store/store-bill-list",
                 permissions=[QualityInspectorPermission])
nav_bar.register(qir_page, name=u"质检报告", default_url="/qir/qireport-list",
                 permissions=[QualityInspectorPermission])
nav_bar.register(deduction_page, name=u"扣重管理", default_url="/deduction/",
                 permissions=[QualityInspectorPermission])
nav_bar.register(dashboard, name=u"仪表盘", permissions=[AdminPermission])

nav_bar.register(time_line_page, name=u"时间线", default_url="/timeline/log-list")
nav_bar.register(admin_page, name=u"管理中心", default_url="/admin/user-list", permissions=[AdminPermission])
nav_bar.register(report_page, name=u"报表列表", default_url="/report/report-list",
                 permissions=[Permission.union(AdminPermission, AccountantPermission)], group=u'报表',
                 enabler=lambda nav: request.path.startswith('/report/report'))
nav_bar.register(report_page, name=u"数据集合列表", default_url="/report/data-sets",
                 permissions=[Permission.union(AdminPermission, AccountantPermission)], group=u'报表',
                 enabler=lambda nav: request.path.startswith('/report/data-set'))
nav_bar.register(report_page, name=u"推送列表", default_url="/report/notification-list",
                 permissions=[Permission.union(AdminPermission, AccountantPermission)], group=u'报表',
                 enabler=lambda nav: request.path.startswith('/report/notification-list'))
nav_bar.register(to_do_page, name=u"待办事项", default_url="/todo/todo-list", count=0)
nav_bar.register(work_flow_page, name=lambda: u"工作流",
                 count=lambda: models.Node.query.filter(models.Node.handle_time == None).count(),
                 default_url="/work-flow/node-list", permissions=[CargoClerkPermission])

#install jinja utilities
from lite_mms.utilities import url_for_other_page, datetimeformat
from lite_mms import permissions
Example #20
0
 def try_view(self, objs=None):
     Permission.union(AdminPermission, CargoClerkPermission).test()
Example #21
0
 def try_view_report(self):
     Permission.union(AdminPermission, AccountantPermission).test()
Example #22
0
 def try_edit_data_set(self):
     Permission.union(AdminPermission, AccountantPermission).test()
Example #23
0
nav_bar.register(deduction_page,
                 name=u"扣重管理",
                 default_url="/deduction/",
                 permissions=[QualityInspectorPermission])
nav_bar.register(dashboard, name=u"仪表盘", permissions=[AdminPermission])

nav_bar.register(time_line_page, name=u"时间线", default_url="/timeline/log-list")
nav_bar.register(admin_page,
                 name=u"管理中心",
                 default_url="/admin/user-list",
                 permissions=[AdminPermission])
nav_bar.register(
    report_page,
    name=u"报表列表",
    default_url="/report/report-list",
    permissions=[Permission.union(AdminPermission, AccountantPermission)],
    group=u'报表',
    enabler=lambda nav: request.path.startswith('/report/report'))
nav_bar.register(
    report_page,
    name=u"数据集合列表",
    default_url="/report/data-sets",
    permissions=[Permission.union(AdminPermission, AccountantPermission)],
    group=u'报表',
    enabler=lambda nav: request.path.startswith('/report/data-set'))
nav_bar.register(
    report_page,
    name=u"推送列表",
    default_url="/report/notification-list",
    permissions=[Permission.union(AdminPermission, AccountantPermission)],
    group=u'报表',