Example #1
0
    def post(self, request, sid, aid):
        """
        提交评分表
        :param request:
        :param sid:
        :param aid:
        :return:
        """
        logic = AppraisingScoreLogic(self.auth, sid, aid)
        # logic.check(AssociationPermissionEnum.APPRAISING, AssociationPermissionEnum.ASSOCIATION_VIEW_DATA)

        params = ParamsParser(request.JSON)
        target_id = params.int('target_id', desc='填写对象id')
        content = params.dict('content', desc='评分正文')           # type: dict {"number": "answer"}
        # 检查目标用户是否符合标准
        if not AssociationAccount.objects.filter(association=logic.association, id=target_id).exists():
            raise AssociationExcept.not_account()
        # 过滤非发起评优时段提交 或 已填写过
        if AppraisingScore.objects.filter(target_id=target_id, association=logic.association).exists():
            raise AppraisingInfoExcept.no_time_post()

        score = AppraisingScore.objects.create(
            author=logic.account,
            association=logic.association,
            target_id=target_id,
            content=json.dumps(content),
            version=logic.get_version(),
            score=logic.content_to_score(content),
            template_id=logic.get_template_id(),
        )

        return Result(id=score.id, association_id=self.auth.get_association_id())
Example #2
0
 def get_association_account(self, throw=False):
     """
     获取人事表
     :return:
     """
     account = AssociationAccount.objects.filter_cache(
         account=self.auth.get_account(), association=self.association)
     if account is None or len(account) == 0:
         if throw: return None
         raise AssociationExcept.no_permission()
     return account[0]
Example #3
0
    def check(self, *permission):
        """
        权限处理
        :param permission:
        :return:
        """
        # !为了世界的和平 管理员权限在协会当中并不放行
        if not self.inspect(*permission):
            raise AssociationExcept.no_permission()

        return True
Example #4
0
 def get_association(self, aid):
     """
     获取协会model
     :param aid:
     :return:
     """
     if aid == "" or aid is None:
         return None
     association = Association.objects.get_once(pk=aid)
     if association is None or association.school_id != self.school.id:
         raise AssociationExcept.association_not_found()
     return association
Example #5
0
    def get_account(self, acid):
        """
        获取协会人事model
        :param acid:
        :return:
        """
        if acid == "" or acid is None:
            return
        account = AssociationAccount.objects.get_once(pk=acid)
        if account is None or account.association_id != self.association.id:
            raise AssociationExcept.not_account()

        return account
Example #6
0
    def post(self, request, sid, aid, tid):
        """
        接手任务 or 指派任务
        :param request:
        :param sid:
        :param aid:
        :param tid:
        :return:
        """
        logic = TaskLogic(self.auth, sid, aid, tid)
        params = ParamsParser(request.JSON)
        account_id = params.int('account',
                                desc='用户id',
                                default=-1,
                                require=False)

        if logic.task.working:
            raise TaskInfoExcept.working()

        # 指派任务
        if account_id != -1:
            # logic.check(AssociationPermissionEnum.ASSOCIATION_VIEW_DATA, AssociationPermissionEnum.TASK)
            account = AssociationAccount.objects.get_once(pk=account_id)
            # 过滤协会
            if account is None or account.association_id != logic.association.id:
                raise AssociationExcept.not_account()
        else:
            account = logic.account

        AssociationTaskReport.objects.create(
            task=logic.task,
            worker=account,
        )
        logic.task.working = True
        logic.task.save()

        return Result(id=tid)
Example #7
0
    def put(self, request, sid, aid, acid=""):
        """
        修改用户信息
        :param request:
        :param sid:
        :param aid:
        :param acid:
        :return:
        """
        params = ParamsParser(request.JSON)
        alogic = AssociationAccountLogic(self.auth, sid, aid, acid)

        if acid != "":
            # alogic.check(AssociationPermissionEnum.ASSOCIATION)
            account = alogic.other_account
            # 角色修改
            if params.has('role'):
                # 缺少权限判断 输入过滤
                role = params.int('role', desc='用户角色')
                # 若是部长 则需添加部门id信息
                if role == int(RoleEnum.MINISTER):
                    department_id = params.int('department_id', desc='部门id')
                    department = AssociationDepartment.objects.get_once(
                        pk=department_id)
                    # 过滤部门不存在或非该协会部门
                    if department is None or department.association_id != account.association_id:
                        raise AssociationExcept.department_not_exist()
                    # 更新数据库信息
                    account.department_id = department_id
                    department.manager.add(account)
                    department.save()
                # 若此前是部长但现在不是则清除部门部长信息
                elif account.role == int(RoleEnum.MINISTER):
                    # 查询quertset对象 因为反正都会被修改所以没必要使用filter_cache 性能反而不如filter
                    department = AssociationDepartment.objects.filter(
                        association_id=aid, manager__id=account.id)
                    # 去除管理员关联(部长)
                    if department.exists():
                        department = department[0]
                        department.manager.remove(account)
                        department.save()
                    account.department = None
                account.role = role
            # 权限修改
            if params.has('permissions'):
                permissions = AssociationPermissionsEntity.parse(
                    account.permissions)
                permissions.update(params.dict('permissions', desc='权限'))
                account.permissions = permissions.dumps()
            # 部门修改
            if params.has('department'):
                # 过滤为本协会部门
                department = AssociationDepartment.objects.get_once(
                    pk=params.int('department', desc='部门id'))
                if department is not None and department.association_id == alogic.association.id:
                    account.department = department
            # 退休换届
            if params.has('retire'):
                account.retire = params.bool('retire', desc='退休换届与否')
        else:
            account = alogic.account

        with params.diff(account):
            account.nickname = params.str('nickname', desc='协会内昵称')

        account.save()
        return Result(id=acid, association_id=self.auth.get_association_id())