Ejemplo n.º 1
0
    def create(self, context, **kwargs):


        password=context.DATA.pop('usr_password')

        context.DATA['usr_first_login']= datetime.datetime.now()
        

        serializer = UserSerializer(data=context.DATA)

        if serializer.is_valid():
            serializer.save()
            user = User.objects.get(usr_userid=context.DATA.get('usr_userid'))

            if password:
                user.usr_password = Encrypt.encrypt(password)
                user.save()

            for g in context.DATA.get('groups'):
                group = Group.objects.get(grp_groupname=g)
                UserGroup.objects.get_or_create(
                    aug_userid=user, aug_groupname=group)

            return Response(serializer.data, status=201)
        return Response(serializer.errors, status=400)
Ejemplo n.º 2
0
    def create(self, context, **kwargs):

        password = context.DATA.pop('usr_password')

        context.DATA['usr_first_login'] = datetime.datetime.now()

        serializer = UserSerializer(data=context.DATA)

        if serializer.is_valid():
            serializer.save()
            user = User.objects.get(usr_userid=context.DATA.get('usr_userid'))

            if password:
                user.usr_password = Encrypt.encrypt(password)
                user.save()

            for g in context.DATA.get('groups'):
                group = Group.objects.get(grp_groupname=g)
                UserGroup.objects.get_or_create(aug_userid=user,
                                                aug_groupname=group)

            return Response(serializer.data, status=201)
        return Response(serializer.errors, status=400)
Ejemplo n.º 3
0
    def update(self, context, **kwargs):
        user = User.objects.get(usr_userid=kwargs.get('pk'))

        usr_password = context.DATA.pop('usr_password', None)

        if usr_password:
            user.usr_password = Encrypt.encrypt(usr_password)

        a = UserGroup.objects.filter(aug_userid=user)
        a.delete()
        serializer = UserSerializer(user, data=context.DATA)

        if serializer.is_valid():
            serializer.save()
            user = User.objects.get(usr_userid=context.DATA.get('usr_userid'))

            for g in context.DATA.get('groups'):
                group = Group.objects.get(grp_groupname=g)
                UserGroup.objects.get_or_create(aug_userid=user,
                                                aug_groupname=group)

            return Response(serializer.data, status=201)
        return Response(serializer.errors, status=400)
Ejemplo n.º 4
0
    def update(self, context, **kwargs):
        user = User.objects.get(usr_userid=kwargs.get('pk'))

        usr_password=context.DATA.pop('usr_password',None)

        if usr_password :
            user.usr_password = Encrypt.encrypt(usr_password)
        
        a = UserGroup.objects.filter(aug_userid=user)
        a.delete()
        serializer = UserSerializer(user, data=context.DATA)

        if serializer.is_valid():
            serializer.save()
            user = User.objects.get(usr_userid=context.DATA.get('usr_userid'))

            for g in context.DATA.get('groups'):
                group = Group.objects.get(grp_groupname=g)
                UserGroup.objects.get_or_create(
                    aug_userid=user, aug_groupname=group)

            return Response(serializer.data, status=201)
        return Response(serializer.errors, status=400)