コード例 #1
0
ファイル: views.py プロジェクト: fortyMiles/my-family
    def put(self, request, name, format=None):
        group = self.get_object(name)
        serializer = GroupSerializer(group, data=request.data)
        if serializer.is_valid():
            serializer.save()
            return Response(
                {'data': serializer.data},
                status=status.HTTP_202_ACCEPTED
            )

        return Response(status=status.HTTP_406_NOT_ACCEPTABLE)
コード例 #2
0
    def put(self, request, pk):
        group = self.get_object(pk)
        data = request.data['params']
        # data = request.data
        # print(request.data['extraParams'])
        serializer = GroupSerializer(group, data=data)
        if serializer.is_valid():
            serializer.save()
            if 'extraParams' in request.data:
                extraData = request.data['extraParams']
                menuKey = None
                if 'menuKey' in extraData:
                    menuKey = extraData['menuKey']
                departKey = None
                if 'departKey' in extraData:
                    departKey = extraData['departKey']
                permissionsKey = None
                if 'permissionsKey' in extraData:
                    permissionsKey = extraData['permissionsKey']
                if not departKey is None:
                    rd = GroupDepart.objects.filter(group_id=group.id).first()
                    if not rd is None:
                        GroupDepart.objects.filter(id=rd.id).update(group_id=group.id, depart_id=departKey)
                    else:
                        GroupDepart.objects.create(group_id=group.id, depart_id=departKey)
                if menuKey:
                    GroupMenu.objects.filter(group=group).delete()
                    querysetlist = []
                    for i in menuKey:
                        querysetlist.append(GroupMenu(group_id=group.id, menu_id=i))
                    GroupMenu.objects.bulk_create(querysetlist)
                else:
                    GroupMenu.objects.filter(group=group).delete()

                if permissionsKey:
                    g = Group.objects.get(id=group.id)
                    g.permissions.clear()
                    for i in permissionsKey:
                        p = Permission.objects.get(id=i)
                        g.permissions.add(p)
                        g.save()

                else:
                    g = Group.objects.get(id=group.id)
                    g.permissions.clear()

            return Response(serializer.data)
        return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
コード例 #3
0
    def post(self, request):
        data = request.data['params']
        # data = request.data
        # print(request.data['extraParams'])
        serializer = GroupSerializer(data=data)
        if serializer.is_valid():
            serializer.save()
            groupId = serializer.data['id']
            if 'extraParams' in request.data:
                extraData = request.data['extraParams']
                menuKey = None
                if 'menuKey' in extraData:
                    menuKey = extraData['menuKey']
                departKey = None
                if 'departKey' in extraData:
                    departKey = extraData['departKey']
                permissionsKey = None
                if 'permissionsKey' in extraData:
                    permissionsKey = extraData['permissionsKey']
                if not departKey is None:
                    GroupDepart.objects.create(group_id=groupId, depart_id=departKey)
                if menuKey:
                    querysetlist = []
                    for i in menuKey:
                        querysetlist.append(GroupMenu(group_id=groupId, menu_id=i))
                    GroupMenu.objects.bulk_create(querysetlist)
                if permissionsKey:
                    g = Group.objects.get(id=groupId)
                    for i in permissionsKey:
                        p = Permission.objects.get(id=i)
                        g.permissions.add(p)
                        g.save()


            return Response(serializer.data, status=status.HTTP_201_CREATED)
        return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)