예제 #1
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()
예제 #2
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()
예제 #3
0
 def create(self, validated_data):
     if Group.objects.filter(name=validated_data['name']).count() > 0:
         raise ValueError
     elif validated_data.get('gid') and Group.objects.filter(gid=validated_data['gid']).count() > 0:
         raise ValueError
     validated_data['members'] = self.check_members([], validated_data)
     user = Group(**validated_data)
     user.save()
     return user
예제 #4
0
 def create(self, validated_data):
     if Group.objects.filter(name=validated_data['name']).count() > 0:
         raise ValueError
     elif validated_data.get('gid') and Group.objects.filter(
             gid=validated_data['gid']).count() > 0:
         raise ValueError
     validated_data['members'] = self.check_members([], validated_data)
     user = Group(**validated_data)
     user.save()
     return user
예제 #5
0
 def handle(self, *args, **options):
     groupname = options['groupname']
     if not list(Group.objects.filter(name=groupname)[0:1]):
         group = Group(name=groupname, gid=options['gid'])
         group.save()
예제 #6
0
 def handle(self, *args, **options):
     groupname = force_text(options['groupname'])
     if not list(Group.objects.filter(name=groupname)[0:1]):
         group = Group(name=groupname, gid=options['gid'])
         group.save()