def clean_user(self):
        """
        Raises ``ValidationError`` if user is already member of given group or
        user does not exist.
        """
        user = self.cleaned_data['user']
        if user:
            try:
                user.groups.get(name=self.group.name)
            except Group.DoesNotExist:
                pass
            else:
                raise forms.ValidationError(_("User %(user)s is already a "
                    "member of %(group)s" %
                    {'user': user, 'group': self.group}))
        return user
dataset/ETHPy150Open lukaszb/django-projector/projector/forms.py/DashboardAddMemberForm.clean_user/original