コード例 #1
0
ファイル: permission_resource.py プロジェクト: cash2one/APL
class PermissionListResource(Resource):
    method_decorators = [admin_manager.login_required()]

    def get(self):
        permission = Permission.query.all()
        schema = PermissionSchema(many=True)
        result = schema.dump(permission).data

        return {'permissions': result}, Const.STATUS_OK

    def post(self):
        args = parser.parse_args()

        # TODO 判断权限值是否是2N次方

        permission = Permission()
        merge(permission, args)

        try:
            with safe_session(db):
                db.session.add(permission)
        except sqlalchemy.exc.IntegrityError as e:
            print('create permission error:', e)
            return {Const.MESSAGE_KEY: '权限创建失败,权限值不能重复'}, Const.STATUS_ERROR

        return {Const.MESSAGE_KEY: '权限创建成功'}, Const.STATUS_OK
コード例 #2
0
ファイル: permission_resource.py プロジェクト: cash2one/APL
class PermissionListResource(Resource):
    method_decorators = [admin_manager.login_required()]

    def get(self):
        args = search_parser.parse_args()
        page = args.get('page')
        per_page = current_app.config['ITEM_COUNT_PER_PAGE']

        pagination = Permission.query.paginate(page,
                                               per_page=per_page,
                                               error_out=False)

        schema = PaginationSchema()
        schema.declared_fields['items'] = fields.Nested(PermissionSchema,
                                                        many=True)

        data = schema.dump(pagination).data

        return {Const.RESULT_KEY: data}, Const.STATUS_OK

    def post(self):
        args = parser.parse_args()

        permission = Permission()
        merge(permission, args)

        try:
            with safe_session(db):
                db.session.add(permission)
        except sqlalchemy.exc.IntegrityError:
            raise IllegalPermissionValueException()

        return {Const.MESSAGE_KEY: '权限创建成功'}, Const.STATUS_OK
コード例 #3
0
class UserAttachmentListResource(Resource):
    method_decorators = [admin_manager.login_required()]

    def get(self):
        args = search_parser.parse_args()
        page = args.get('page')
        per_page = current_app.config['ITEM_COUNT_PER_PAGE']

        pagination = UserAttachment.query.paginate(page,
                                                   per_page=per_page,
                                                   error_out=False)

        schema = PaginationSchema()
        schema.declared_fields['items'] = fields.Nested(UserAttachmentSchema,
                                                        many=True)

        data = schema.dump(pagination).data

        return {Const.RESULT_KEY: data}, Const.STATUS_OK

    def post(self):

        attachment = UserAttachment()
        args = parser.parse_args()
        merge(attachment, args)

        with safe_session(db):
            db.session.add(attachment)

        return {Const.MESSAGE_KEY: '交付物发布成功'}, Const.STATUS_OK
コード例 #4
0
ファイル: project_resource.py プロジェクト: cash2one/APL
class ProjectResource(Resource):
    method_decorators = [admin_manager.login_required()]

    def get(self, pid):
        project = Project.query.get_or_404(pid)

        for phase in project.phases:
            phase.phase_name = phase.phase.name

        schema = ProjectSchema(exclude=('comments.project_id',
                                        'phases.project_id'))
        result = schema.dump(project).data

        return {'project': result}, Const.STATUS_OK

    def post(self, pid):

        project = Project.query.get_or_404(pid)
        args = parser.parse_args()
        merge(project, args)

        with safe_session(db):
            db.session.add(project)

        return {Const.MESSAGE_KEY: '项目修改成功'}, Const.STATUS_OK
コード例 #5
0
class ProjectPhaseResource(Resource):
    method_decorators = [admin_manager.login_required()]

    def get(self, ppid):
        pp = ProjectPhase.query.get_or_404(ppid)

        # if pp:
        #     pp.attachments = []
        #     for a in pp.phase.attachments:
        #         print(a.attachment)
        #         pp.attachments.append(a.attachment)

        schema = ProjectPhaseSchema()
        result = schema.dump(pp).data

        return {'pp': result}, Const.STATUS_OK

    def post(self, ppid):
        pp = ProjectPhase.query.get_or_404(ppid)
        args = parser.parse_args()
        merge(pp, args)

        with safe_session(db):
            db.session.add(pp)

        return {Const.MESSAGE_KEY: '修改成功'}, Const.STATUS_OK
コード例 #6
0
class PhaseAttachmentDetailListResource(Resource):
    method_decorators = [admin_manager.login_required()]

    def get(self):

        args = search_parser.parse_args()
        padid = args.get('id')
        page = args.get('page')
        per_page = current_app.config['ITEM_COUNT_PER_PAGE']

        pagination = PhaseAttachmentDetail.query.filter_by(paid=padid).paginate(page, per_page=per_page, error_out=False)

        schema = PaginationSchema()
        schema.declared_fields['items'] = fields.Nested(PhaseAttachmentDetailSchema, many=True)

        data = schema.dump(pagination).data

        return {Const.RESULT_KEY: data}, Const.STATUS_OK

    def post(self):
        pad = PhaseAttachmentDetail()
        args = parser.parse_args()
        merge(pad, args)

        with safe_session(db):
            db.session.add(pad)

        return {Const.MESSAGE_KEY: '新增附件信息成功'}, Const.STATUS_OK
コード例 #7
0
class UserAttachmentListResource(Resource):
    method_decorators = [admin_manager.login_required()]

    def get(self):
        attachments = UserAttachment.query.all()
        for attachment in attachments:

            if attachment.ppid:
                pp = ProjectPhase.query.get(attachment.ppid)
                if pp and pp.project:
                    attachment.project_name = pp.project.name

            if attachment.attachment_id:
                a = Attachment.query.get(attachment.attachment_id)
                if a:
                    attachment.attachment_name = a.name

        schema = UserAttachmentSchema(many=True)
        result = schema.dump(attachments).data

        return {'attachments': result}, Const.STATUS_OK

    def post(self):

        attachment = UserAttachment()
        args = parser.parse_args()

        merge(attachment, args)

        with safe_session(db):
            db.session.add(attachment)

        return {Const.MESSAGE_KEY: '交付物发布成功'}, Const.STATUS_OK
コード例 #8
0
ファイル: project_resource.py プロジェクト: cash2one/APL
class ProjectListResource(Resource):
    method_decorators = [admin_manager.login_required()]

    def get(self):
        args = search_parser.parse_args()
        pid = args.get('id')
        name = args.get('name')
        contact_name = args.get('contact_name')
        industry = args.get('industry')
        phase_index = args.get('phase_index')
        contact_phone = args.get('contact_phone')
        starttime = args.get('starttime')
        endtime = args.get('endtime')
        page = args.get('page')
        per_page = current_app.config['ITEM_COUNT_PER_PAGE']

        conditions = []

        if isinstance(pid, int):
            conditions.append(Project.id == pid)

        if name:
            conditions.append(Project.name.contains(name))

        if contact_name:
            conditions.append(Project.contact_name.contains(contact_name))

        if industry in Industry.__members__.keys():
            conditions.append(Project.industry == Industry[industry])

        if phase_index:
            conditions.append(Project.phase_index == phase_index)

        if contact_phone:
            conditions.append(Project.contact_phone.contains(contact_phone))

        if isinstance(starttime, int) and isinstance(endtime, int):
            conditions.append(int(starttime) <= Project.gmt_create <= int(endtime))

        pagination = Project.query.filter(and_(*conditions)).paginate(page, per_page=per_page, error_out=False)

        schema = PaginationSchema()
        schema.declared_fields['items'] = fields.Nested(ProjectSchema, many=True)  # , exclude=('comments.project_id', 'phases.project_id'))

        data = schema.dump(pagination).data

        return {Const.RESULT_KEY: data}, Const.STATUS_OK

    def post(self):

        project = Project()
        args = parser.parse_args()
        merge(project, args)

        with safe_session(db):
            db.session.add(project)

        return {Const.MESSAGE_KEY: '创建项目成功'}, Const.STATUS_OK
コード例 #9
0
ファイル: file_resource.py プロジェクト: cash2one/APL
class FileResource(Resource):
    method_decorators = [admin_manager.login_required()]

    def get(self, name):
        file = File.query.filter_by(server_name=name).first()

        if file:
            url = get_file_url(file.server_name, file.local_name)
            return url

        return None
コード例 #10
0
class PhaseAttachmentListResource(Resource):
    method_decorators = [admin_manager.login_required()]

    def get(self):

        conditions = []
        args = search_parser.parse_args()
        phase_name = args.get('phase_name')
        attachment_name = args.get('attachment_name')
        status = args.get('status')
        starttime = args.get('starttime')
        endtime = args.get('endtime')
        page = args.get('page')
        per_page = current_app.config['ITEM_COUNT_PER_PAGE']

        if phase_name:
            conditions.append(PhaseAttachment.phase_name.contains(phase_name))

        if attachment_name:
            conditions.append(
                PhaseAttachment.attachment_name.contains(attachment_name))

        if status in AttachmentStatus.__members__.values():
            conditions.append(PhaseAttachment.status == status)

        if isinstance(starttime, int) and isinstance(endtime, int):
            conditions.append(
                int(starttime) <= PhaseAttachment.timestamp <= int(endtime))

        pagination = PhaseAttachment.query.filter(and_(*conditions)).paginate(
            page, per_page=per_page, error_out=False)

        schema = PaginationSchema()
        schema.declared_fields['items'] = fields.Nested(PhaseAttachmentSchema,
                                                        many=True)

        data = schema.dump(pagination).data

        return {Const.RESULT_KEY: data}, Const.STATUS_OK

    def post(self):
        pa = PhaseAttachment()
        args = parser.parse_args()
        merge(pa, args)

        with safe_session(db):
            db.session.add(pa)

        return {Const.MESSAGE_KEY: '创建成功'}, Const.STATUS_OK
コード例 #11
0
class STSInfoResource(Resource):
    method_decorators = [admin_manager.login_required()]

    def get(self):

        now = int(time.time())
        expire_syncpoint = now + 1800
        expire = get_iso_8601(expire_syncpoint)

        policy_dict = dict()
        policy_dict["expiration"] = expire
        condition_array = []
        array_item = list()
        array_item.append("content-length-range")
        array_item.append(0)
        array_item.append(104857600)
        condition_array.append(array_item)

        policy_dict["conditions"] = condition_array

        policy = json.dumps(policy_dict).strip()
        policy_encode = base64.b64encode(bytes(policy, 'utf-8'))

        sts = request_sts_token('rain')

        signature = get_sign_policy(sts.access_key_secret, policy_encode)

        callback_dict = dict()
        callback_dict["callbackUrl"] = "https://apl.apluslabs.com/after_upload"
        callback_dict[
            "callbackBody"] = "bucket=${bucket}&object=${object}&etag=${etag}&size=${size}&mimeType=${mimeType}&filename=${x:filename}&uid=${x:uid}"
        callback_dict["callbackBodyType"] = "application/x-www-form-urlencoded"
        callback_param = json.dumps(callback_dict).strip()
        base64_callback_body = base64.b64encode(bytes(callback_param, 'utf-8'))

        result = dict()
        result['OSSAccessKeyId'] = sts.access_key_id
        result['x-oss-security-token'] = sts.security_token
        result['policy'] = policy_encode.decode()
        result['Signature'] = signature.decode()
        result['key'] = str(uuid.uuid1()).replace('-', '')
        result['success_action_status'] = '201'
        result['callback'] = base64_callback_body.decode()
        result['x:uid'] = 1
        result['x:filename'] = ''

        return jsonify(result)
コード例 #12
0
class ScheduleResource(Resource):
    method_decorators = [admin_manager.login_required()]

    def get(self, sid):
        schedul = Schedule.query.get_or_404(sid)
        schema = ScheduleSchema()
        result = schema.dump(schedul).data
        return {Const.RESULT_KEY: result}, Const.STATUS_OK

    def post(self, sid):
        schedule = Schedule.query.get_or_404(sid)
        args = parser.parse_args()
        merge(schedule, args, ignore=('from_id', 'to_id', 'project_id'))

        with safe_session(db):
            db.session.add(schedule)
        return {Const.MESSAGE_KEY: '修改约谈表成功'}, Const.STATUS_OK
コード例 #13
0
ファイル: role_resource.py プロジェクト: cash2one/APL
class RoleListResource(Resource):
    method_decorators = [admin_manager.login_required()]

    def get(self):
        args = search_parser.parse_args()
        page = args.get('page')
        per_page = current_app.config['ITEM_COUNT_PER_PAGE']

        pagination = Role.query.paginate(page,
                                         per_page=per_page,
                                         error_out=False)

        schema = PaginationSchema()
        schema.declared_fields['items'] = fields.Nested(RoleSchema, many=True)

        data = schema.dump(pagination).data

        return {Const.RESULT_KEY: data}, Const.STATUS_OK

    def post(self):

        role = Role()
        args = parser.parse_args()
        ps = args.get('permissions')

        if ps:
            ps = ps.split(',')

            for p in ps:
                permission = Permission.query.get(int(p))

                if permission:
                    db.session.expunge(permission)
                    rp = RolePermission()
                    rp.permission = permission
                    role.permissions.append(rp)

            with safe_session(db):
                db.session.add(role)

        merge(role, args, ignore=('permissions', ))

        with safe_session(db):
            db.session.add(role)

        return {Const.MESSAGE_KEY: '角色创建成功'}, Const.STATUS_OK
コード例 #14
0
class PhaseListResource(Resource):
    method_decorators = [admin_manager.login_required()]

    def get(self):
        args = search_parser.parse_args()
        page = args.get('page')
        per_page = current_app.config['ITEM_COUNT_PER_PAGE']

        pagination = Phase.query.paginate(page,
                                          per_page=per_page,
                                          error_out=False)

        schema = PaginationSchema()
        schema.declared_fields['items'] = fields.Nested(PhaseSchema, many=True)

        data = schema.dump(pagination).data

        return {Const.RESULT_KEY: data}, Const.STATUS_OK

    def post(self):
        phase = Phase()
        args = parser.parse_args()
        attachments = args.get('attachments')

        if attachments:
            aids = attachments.split(',')

            for aid in aids:
                a = Attachment.query.get(int(aid))
                if a:
                    db.session.expunge(a)
                    pa = PhaseAttachment()
                    pa.attachment = a
                    phase.attachments.append(pa)

            with safe_session(db):
                db.session.add(phase)

        merge(phase, args, ignore=('attachments', ))

        with safe_session(db):
            db.session.add(phase)

        return {Const.MESSAGE_KEY: '创建项目阶段成功'}, Const.STATUS_OK
コード例 #15
0
class BusinessPlanListResource(Resource):
    method_decorators = [admin_manager.login_required()]

    def get(self):
        bps = BusinessPlan.query.all()
        schema = BusinessPlanSchema(many=True)
        result = schema.dump(bps).data

        return {'bps': result}, Const.STATUS_OK

    def post(self):
        bp = BusinessPlan()
        args = parser.parse_args()
        merge(bp, args)

        with safe_session(db):
            db.session.add(bp)

        return {Const.MESSAGE_KEY: '创建成功'}, Const.STATUS_OK
コード例 #16
0
class ProjectPhaseListResource(Resource):
    method_decorators = [admin_manager.login_required()]

    def get(self):
        pps = ProjectPhase.query.all()
        schema = ProjectPhaseSchema(many=True)
        result = schema.dump(pps).data

        return {'pps': result}, Const.STATUS_OK

    def post(self):
        pp = ProjectPhase()
        args = parser.parse_args()
        merge(pp, args)

        with safe_session(db):
            db.session.add(pp)

        return {Const.MESSAGE_KEY: '创建成功'}, Const.STATUS_OK
コード例 #17
0
ファイル: permission_resource.py プロジェクト: cash2one/APL
class PermissionResource(Resource):
    method_decorators = [admin_manager.login_required()]

    def get(self, pid):
        permission = Permission.query.get_or_404(pid)
        schema = PermissionSchema()
        result = schema.dump(permission).data

        return {'permission': result}, Const.STATUS_OK

    def post(self, pid):
        permission = Permission.query.get_or_404(pid)
        args = parser.parse_args()
        merge(permission, args)

        with safe_session(db):
            db.session.add(permission)

        return {Const.MESSAGE_KEY: '权限修改成功'}, Const.STATUS_OK
コード例 #18
0
ファイル: department_resource.py プロジェクト: cash2one/APL
class DepartmentListResource(Resource):
    method_decorators = [admin_manager.login_required()]

    def get(self):
        department = Department.query.all()
        schema = DepartmentSchema(many=True)
        result = schema.dump(department).data

        return {'departments': result}, Const.STATUS_OK

    def post(self):
        department = Department()
        args = parser.parse_args()
        merge(department, args)

        with safe_session(db):
            db.session.add(department)

        return {Const.MESSAGE_KEY: '部门创建成功'}, Const.STATUS_OK
コード例 #19
0
ファイル: department_resource.py プロジェクト: cash2one/APL
class DepartmentResource(Resource):
    method_decorators = [admin_manager.login_required()]

    def get(self, did):
        department = Department.query.get_or_404(did)
        schema = DepartmentSchema()
        result = schema.dump(department).data

        return {'department': result}, Const.STATUS_OK

    def post(self, did):
        department = Department.query.get_or_404(did)
        args = parser.parse_args()
        merge(department, args)

        with safe_session(db):
            db.session.add(department)

        return {Const.MESSAGE_KEY: '修改成功'}, Const.STATUS_OK
コード例 #20
0
class CustomServiceItemResource(Resource):
    method_decorators = [admin_manager.login_required()]

    def get(self, usiid):
        item = CustomServiceItem.query.get_or_404(usiid)
        schema = CustomServiceItemSchema()
        result = schema.dump(item).data

        return {'item': result}, Const.STATUS_OK

    def post(self, usiid):
        usi = CustomServiceItem.query.get_or_404(usiid)
        args = parser.parse_args()
        merge(usi, args)

        with safe_session(db):
            db.session.add(usi)

        return {Const.MESSAGE_KEY: '定制订单修改成功'}, Const.STATUS_OK
コード例 #21
0
class BillListResource(Resource):
    method_decorators = [admin_manager.login_required()]

    def get(self):
        args = search_parser.parse_args()

        uid = args.get('id')
        project_name = args.get('project_name')
        starttime = args.get('starttime')
        endtime = args.get('endtime')

        conditions = []

        if isinstance(uid, int):
            conditions.append(UserServiceItem.id == uid)

        if project_name:
            projects = Project.query.filter(
                Project.name.contains(project_name)).all()

            if len(projects) > 0:

                pids = [p.id for p in projects]

                pps = ProjectPhase.query.filter(
                    ProjectPhase.project_id.in_(pids)).all()

                conditions.append(
                    UserServiceItem.ppid.in_([pp.id for pp in pps]))

        if isinstance(starttime, int) and isinstance(endtime, int):
            conditions.append(
                int(starttime) <= UserServiceItem.timestamp <= int(endtime))

        items = UserServiceItem.query.filter(or_(*conditions)).all()

        for item in items:
            _convert_id_to_name(item)

        schema = UserServiceItemSchema(many=True)
        result = schema.dump(items).data

        return {'bills': result}, Const.STATUS_OK
コード例 #22
0
class ServiceCategoryListResource(Resource):
    method_decorators = [admin_manager.login_required()]

    def get(self):
        sclist = ServiceItemCategory.query.all()
        schema = ServiceItemCategorySchema(many=True)
        result = schema.dump(sclist).data

        return {'service_category_list': result}, Const.STATUS_OK

    def post(self):
        sc = ServiceItemCategory()
        args = parser.parse_args()
        merge(sc, args)

        with safe_session(db):
            db.session.add(sc)

        return {Const.MESSAGE_KEY: '服务包类别创建成功'}, Const.STATUS_OK
コード例 #23
0
class PhaseAttachmentResource(Resource):
    method_decorators = [admin_manager.login_required()]

    def get(self, paid):
        pa = PhaseAttachment.query.get_or_404(paid)
        schema = PhaseAttachmentSchema()
        result = schema.dump(pa).data

        return {'pa': result}, Const.STATUS_OK

    def post(self, paid):
        pa = PhaseAttachment.query.get_or_404(paid)
        args = parser.parse_args()
        merge(pa, args)

        with safe_session(db):
            db.session.add(pa)

        return {Const.MESSAGE_KEY: '修改成功'}, Const.STATUS_OK
コード例 #24
0
class BusinessPlanResource(Resource):
    method_decorators = [admin_manager.login_required()]

    def get(self, bid):
        bp = BusinessPlan.query.get_or_404(bid)
        schema = BusinessPlanSchema()
        result = schema.dump(bp).data

        return {Const.RESULT_KEY: result}, Const.STATUS_OK

    def post(self, bid):
        bp = BusinessPlan.query.get_or_404(bid)
        args = parser.parse_args()
        merge(bp, args)

        with safe_session(db):
            db.session.add(bp)

        return {Const.MESSAGE_KEY: '修改成功'}, Const.STATUS_OK
コード例 #25
0
class UserServiceItemResource(Resource):
    method_decorators = [admin_manager.login_required()]

    def get(self, usiid):
        item = UserServiceItem.query.get_or_404(usiid)
        schema = UserServiceItemSchema()
        result = schema.dump(item).data

        return {Const.RESULT_KEY: result}, Const.STATUS_OK

    def post(self, usiid):
        usi = UserServiceItem.query.get_or_404(usiid)
        args = parser.parse_args()
        merge(usi, args, ignore=('ppid', 'service_id'))

        with safe_session(db):
            db.session.add(usi)

        return {Const.MESSAGE_KEY: '用户订单修改成功'}, Const.STATUS_OK
コード例 #26
0
class UserAttachmentResource(Resource):
    method_decorators = [admin_manager.login_required()]

    def get(self, uaid):
        attachment = UserAttachment.query.get_or_404(uaid)
        schema = UserAttachmentSchema()
        result = schema.dump(attachment).data

        return {Const.RESULT_KEY: result}, Const.STATUS_OK

    def post(self, uaid):
        attachment = UserAttachment.query.get_or_404(uaid)
        args = parser.parse_args()
        merge(attachment, args, ignore=('ppid', 'attachment_id'))

        with safe_session(db):
            db.session.add(attachment)

        return {Const.MESSAGE_KEY: '交付物修改成功'}, Const.STATUS_OK
コード例 #27
0
ファイル: ticket_resource.py プロジェクト: cash2one/APL
class TicketResource(Resource):
    method_decorators = [admin_manager.login_required()]

    def get(self, tid):
        ticket = Ticket.query.get_or_404(tid)

        schema = TicketSchema()
        result = schema.dump(ticket).data

        return {Const.RESULT_KEY: result}, Const.STATUS_OK

    def post(self, tid):
        ticket = Ticket.query.get_or_404(tid)
        args = parser.parse_args()
        merge(ticket, args, ignore=('author_id', ))

        with safe_session(db):
            db.session.add(ticket)

        return {Const.MESSAGE_KEY: '工单表修改成功'}, Const.STATUS_OK
コード例 #28
0
class ProjectPhaseResource(Resource):
    method_decorators = [admin_manager.login_required()]

    def get(self, ppid):
        pp = ProjectPhase.query.get_or_404(ppid)

        schema = ProjectPhaseSchema()
        result = schema.dump(pp).data

        return {Const.RESULT_KEY: result}, Const.STATUS_OK

    def post(self, ppid):
        pp = ProjectPhase.query.get_or_404(ppid)
        args = parser.parse_args()
        merge(pp, args, ignore=('project_id', 'phase_id'))

        with safe_session(db):
            db.session.add(pp)

        return {Const.MESSAGE_KEY: '修改成功'}, Const.STATUS_OK
コード例 #29
0
class ServiceItemResource(Resource):
    method_decorators = [admin_manager.login_required()]

    def get(self, sid):
        item = ServiceItem.query.get_or_404(sid)
        item.category_name = item.category.name
        schema = ServiceItemSchema()
        result = schema.dump(item).data

        return {Const.RESULT_KEY: result}, Const.STATUS_OK

    def post(self, sid):
        item = ServiceItem.query.get_or_404(sid)
        args = parser.parse_args()
        merge(item, args, ignore=('category_id', ))

        with safe_session(db):
            db.session.add(item)

        return {Const.MESSAGE_KEY: '服务项修改成功'}, Const.STATUS_OK
コード例 #30
0
ファイル: schedule_resource.py プロジェクト: cash2one/APL
class ScheduleListResource(Resource):
    method_decorators = [admin_manager.login_required()]

    def get(self):

        schedule = Schedule.query.all()
        schema = ScheduleSchema(many=True)
        result = schema.dump(schedule).data
        return {'schedules': result}, Const.STATUS_OK

    def post(self):
        schedule = Schedule()

        args = parser.parse_args()
        merge(schedule, args)

        with safe_session(db):
            db.session.add(schedule)

        return {Const.MESSAGE_KEY: '约谈记录成功'}, Const.STATUS_OK