Ejemplo n.º 1
0
    def set_status(self, request, *args, **kwargs):
        """
        解冻用户

        #### 参数说明
        | 字段名称 | 描述 | 必须 | 类型 |
        | -- | --  | -- | -- |
        | 用户id | 被冻结用户的id  | True | int |


        #### 响应消息:
        | Http响应码 | 原因 | 响应模型 |
        | -- | -- | -- |
        | 200 | 解冻成功 | 返回数据 |
        """
        user = self.get_object()
        is_active = self.request.data.get('is_active', 0)
        user.is_active = is_active
        user.save()
        addlog(request, "用户管理", "解冻用户", "PUT")
        return Response({
            'msg': "修改成功",
            "code": 200
        },
                        status=status.HTTP_200_OK)
Ejemplo n.º 2
0
    def create(self, request, *args, **kwargs):
        """
        新增用户

        #### 参数说明
        | 字段名称 | 描述 | 必须 | 类型 |
        | -- | --  | -- | -- |
        | username | 用户名 | True | str |
        | password | 密码 | True | str |
        | last_name | 昵称 | True | str|
        | email | 邮箱 | True | str |
        | tel | 电话 | True | str |
        | num | 工号 | True | str |
        | gender | 性别(1男 2女) | True | int |
        | info | 备注信息 | False | int |
        | is_active | 账户状态(1 冻结 2 激活)| False |int|


        #### 响应消息:
        | Http响应码 | 原因 | 响应模型 |
        | -- | -- | -- |
        | 201 | 添加成功 | 返回数据 |
        | 400 | 参数格式错误 | 参数格式错误 |
        | 500 | 请求失败 | 服务器内部错误 |
        | 404 | 页面没有找到 | 页面没有找到 |
        """

        addlog(request, "用户管理", "新建用户", "POST")
        return super().create(request, *args, **kwargs)
Ejemplo n.º 3
0
    def list(self, request, *args, **kwargs):
        """
        获得用户列表 
        
        #### 参数说明
        | 字段名称 | 描述 | 必须 | 类型 |
        | -- | --  | -- | -- |
        | username | 用户名 | True | str |
        | password | 密码 | True | str |
        | last_name | 昵称 | True | str|
        | email | 邮箱 | True | str |
        | tel | 电话 | True | str |
        | num | 工号 | True | str |
        | gender | 性别(1男 2女) | True | int |
        | info | 备注信息 | False | int |
        | is_active | 账户状态(1 冻结 2 激活)| False |int|


        #### 响应消息:
        | Http响应码 | 原因 | 响应模型 |
        | -- | -- | -- |
        | 200 | 获取列表成功 | 返回数据 |
        | 400 | 参数格式错误 | 参数格式错误 |
        | 500 | 请求失败 | 服务器内部错误 |
        | 404 | 页面没有找到 | 页面没有找到 |
        """
        addlog(self.request, "举报模块", "查看举报用户", "GET")
        return super().list(request, *args, **kwargs)
Ejemplo n.º 4
0
    def destroy(self, request, *args, **kwargs):
        """
        冻结用户

        #### 参数说明
        | 字段名称 | 描述 | 必须 | 类型 |
        | -- | --  | -- | -- |
        | 用户id | 被冻结用户的id  | True | int |


        #### 响应消息:
        | Http响应码 | 原因 | 响应模型 |
        | -- | -- | -- |
        | 200 | 冻结成功 | 返回数据 |
        """
        # 获取对象
        # 修改属性
        # 保存

        # id = self.kwargs.get('id')
        # try:
        #     user = models.User.objects.get(id=id)
        # except Exception as e :
        #     print(e)
        #     return Response({'msg':"找不多对象","code":404},status=status.HTTP_404_NOT_FOUND)

        user = self.get_object()
        user.is_active = 0
        user.save()
        addlog(request, "用户管理", "冻结用户", "DELETE")
        return Response({
            'msg': "冻结成功",
            "code": 200
        },
                        status=status.HTTP_200_OK)
Ejemplo n.º 5
0
    def destroy(self, request, *args, **kwargs):

        device = self.get_object()
        device.is_enable = 0
        device.save()
        addlog(request, "设备模块", "冻结设备", "DELETE")
        return Response({
            'msg': "冻结成功",
            "code": 200
        },
                        status=status.HTTP_200_OK)
Ejemplo n.º 6
0
    def destroy(self, request, *args, **kwargs):

        alarm = self.get_object()
        alarm.status = 1
        alarm.dealwith_time = datetime.datetime.now()
        alarm.save()
        addlog(self.request, "报警模块", "处理报警", "DELETE")
        return Response({
            'msg': "处理成功",
            "code": 200
        },
                        status=status.HTTP_200_OK)
Ejemplo n.º 7
0
    def update(self, request, *args, **kwargs):
        """
            修改网格信息

            #### 参数说明
            | 字段名称 | 描述 | 必须 | 类型 |
            | -- | -- | -- | -- |
            | name | 网格名 | True | str |
            | location | 所在地 | True | str|
            | leader | 负责人 | True | str |
            | telephone | 联系方式 | True | int |
            """
        addlog(self.request, "网格管理", "修改网格", "PUT")
        return super().update(request, *args, **kwargs)
Ejemplo n.º 8
0
    def get_serializer_class(self):
        if self.action == 'retrieve':
            addlog(self.request, "举报模块", "查看举报", "GET")
            return serializers.ReportListallSerializer

        if self.action == 'create':
            addlog(self.request, "举报模块", "添加举报", "POST")
            return serializers.ReportAddSerializer

        if self.action == 'update':
            addlog(self.request, "举报模块", "修改举报", "PUT")
            return serializers.ReportUpdateSerializer

        return serializers.ReportSerializer
Ejemplo n.º 9
0
 def get_object(self):
     id = self.kwargs['pk']
     object = get_object_or_404(models.AlarmData, id=id)
     addlog(self.request, "报警模块", "查看报警", "GET")
     return object
Ejemplo n.º 10
0
 def get_object(self):
     id = self.kwargs['pk']
     object = get_object_or_404(models.Device, id=id)
     addlog(self.request, "设备模块", "修改设备信息", "GET")
     return object
Ejemplo n.º 11
0
 def get_object(self):
     id = self.kwargs['pk']  # id  ==> pkv  { 'pk':1}
     object = get_object_or_404(models.Device, id=id)
     addlog(self.request, "设备模块", "查看设备", "GET")
     return object
Ejemplo n.º 12
0
 def get_object(self):
     id = self.kwargs['pk']  # id  ==> pkv  { 'pk':1}
     object = get_object_or_404(models.DeviceConf, device_id=id)
     addlog(self.request, "报警模块", "查看报警", "GET")
     return object