Example #1
0
 def create(self, validated_data):
     if User.objects.filter(name=validated_data['name']).count() > 0:
         raise ValueError
     elif validated_data.get('uid_number') and User.objects.filter(uid_number=validated_data['uid_number']).count() > 0:
         raise ValueError
     user = User(**validated_data)
     user.save()
     return user
Example #2
0
 def create(self, validated_data):
     if User.objects.filter(name=validated_data['name']).count() > 0:
         raise ValueError
     elif validated_data.get('uid_number') and User.objects.filter(
             uid_number=validated_data['uid_number']).count() > 0:
         raise ValueError
     user = User(**validated_data)
     user.save()
     return user
Example #3
0
    def handle(self, *args, **options):

        username = force_text(options['username'])
        users = list(User.objects.filter(name=username)[0:1])
        if not users:
            user = User(name=username, uid_number=options['uid'], gid_number=options['gid'])
        else:
            user = users[0]
        if options['display_name']:
            user.display_name = options['display_name']
        if options['phone']:
            user.phone = options['phone']
        if options['gid']:
            user.gid = options['gid']
        if options['password']:
            user.set_password(options['password'])
        else:
            user.save()
        for group_name in options['group']:
            group_name = force_text(group_name)
            groups = list(Group.objects.filter(name=group_name)[0:1])
            if groups:
                group = groups[0]
            else:
                group = Group(name=group_name)
            if username not in group.members:
                group.members.append(username)
            group.save()
Example #4
0
    def handle(self, *args, **options):

        username = force_text(options['username'])
        users = list(User.objects.filter(name=username)[0:1])
        if not users:
            user = User(name=username, uid_number=options['uid'], gid_number=options['gid'])
        else:
            user = users[0]
        if options['display_name']:
            user.display_name = options['display_name']
        if options['phone']:
            user.phone = options['phone']
        if options['gid']:
            user.gid = options['gid']
        if options['password']:
            user.set_password(options['password'])
        else:
            user.save()
        for group_name in options['group']:
            group_name = force_text(group_name)
            groups = list(Group.objects.filter(name=group_name)[0:1])
            if groups:
                group = groups[0]
            else:
                group = Group(name=group_name)
            if username not in group.members:
                group.members.append(username)
            group.save()