def patch_replace_owner(request, thread, value): try: user_id = int(value) except (ValueError, TypeError): user_id = 0 for participant in thread.participants_list: if participant.user_id == user_id: if participant.is_owner: raise PermissionDenied(_("This user already is thread owner.")) else: break else: raise PermissionDenied(_("Participant doesn't exist.")) allow_change_owner(request.user, thread) change_owner(request, thread, participant.user) make_participants_aware(request.user, thread) participants = ThreadParticipantSerializer(thread.participants_list, many=True) return {'participants': participants.data}
def patch_replace_owner(request, thread, value): try: user_id = int(value) except (TypeError, ValueError): raise ValidationError(_("A valid integer is required.")) for participant in thread.participants_list: if participant.user_id == user_id: if participant.is_owner: raise ValidationError(_("This user already is thread owner.")) else: break else: raise ValidationError(_("Participant doesn't exist.")) allow_change_owner(request.user, thread) change_owner(request, thread, participant.user) make_participants_aware(request.user, thread) participants = ThreadParticipantSerializer(thread.participants_list, many=True) return {'participants': participants.data}