Exemplo n.º 1
0
        def get_data(i: int) -> dict:
            data = {
                "username": "******".format(i),
                "email": "tbson{}@gmail.com".format(i),
                "password": "******",
                "first_name": "first{}".format(i),
                "last_name": "last{}".format(i)
            }
            if save is False:
                return data

            try:
                instance = User.objects.get(
                    Q(username=data['username']) | Q(email=data['email']))
            except User.DoesNotExist:
                instance = UserSr(data=data)
                instance.is_valid(raise_exception=True)
                instance = instance.save()
            return instance
Exemplo n.º 2
0
    def change(self, request, pk=None):
        obj = get_object_or_404(Staff, pk=pk)

        data = Tools.parse_user_related_data(request.data)
        userSr = UserSr(obj.user, data=data['user'])
        if userSr.is_valid(raise_exception=True):
            userSr.save()

        remain = data['remain']
        remain.update({'user': obj.user_id})
        serializer = StaffBaseSr(obj, data=remain)
        if serializer.is_valid(raise_exception=True):
            serializer.save()
        return res(serializer.data)
Exemplo n.º 3
0
    def add(self, request):
        data = Tools.parse_user_related_data(request.data)
        userSr = UserSr(data=data['user'])
        if userSr.is_valid(raise_exception=True):
            userSr.save()

        remain = data['remain']
        remain.update({'user': userSr.data['id']})
        serializer = StaffBaseSr(data=remain)
        if serializer.is_valid(raise_exception=True):
            serializer.save()

        serializer.data.update({'user': userSr.data})
        return res(serializer.data)
Exemplo n.º 4
0
    def change(self, request, pk=None):
        obj = get_object_or_404(Customer, pk=pk)

        data = Tools.parse_user_related_data(request.data)
        userSr = UserSr(obj.user, data=data['user'])
        if userSr.is_valid(raise_exception=True):
            userSr.save()

        remain = data['remain']
        remain.update({'user': obj.user_id})
        if type(remain.get('avatar')) is not InMemoryUploadedFile:
            remain.pop('avatar', None)
        serializer = CustomerBaseSr(obj, data=remain)
        if serializer.is_valid(raise_exception=True):
            serializer.save()
        return res(serializer.data)
Exemplo n.º 5
0
    def add(self, request):
        data = Tools.parse_user_related_data(request.data)
        userSr = UserSr(data=data['user'])
        if userSr.is_valid(raise_exception=True):
            userSr.save()

        remain = data['remain']
        remain.update({'user': userSr.data['id']})
        if type(remain.get('avatar')) is not InMemoryUploadedFile:
            remain.pop('avatar', None)
        serializer = CustomerBaseSr(data=remain)
        if serializer.is_valid(raise_exception=True):
            serializer.save()

        serializer.data.update({'user': userSr.data})
        return res(serializer.data)
Exemplo n.º 6
0
    def post(self, request, format=None):
        user = self.get_object()
        obj = user.staff

        data = Tools.parse_user_related_data(request.data)

        userSr = UserSr(user, data=data['user'])
        if userSr.is_valid(raise_exception=True):
            userSr.save()

        remain = data['remain']
        remain.update({'user': user.pk})
        serializer = StaffBaseSr(obj, data=remain)
        if serializer.is_valid(raise_exception=True):
            serializer.save()
            return res(serializer.data)
        else:
            return err_res(serializer.errors)
Exemplo n.º 7
0
    def post(self, request, format=None):
        user = self.get_object()
        obj = user.customer
        data = request.data
        if (type(request.data) is QueryDict):
            data = request.data.dict()

        data = Tools.parse_user_related_data(data)

        userSr = UserSr(user, data=data['user'])
        if userSr.is_valid(raise_exception=True):
            userSr.save()

        remain = data['remain']
        remain.update({'user': user.pk})
        if type(remain.get('avatar')) is not InMemoryUploadedFile:
            remain.pop('avatar', None)
        serializer = CustomerBaseSr(obj, data=remain)
        if serializer.is_valid(raise_exception=True):
            serializer.save()
            return res(serializer.data)
        else:
            return err_res(serializer.errors)