def set_organization(user): groups = get_organization_groups(user) current_org = user.user_profile.current_organization if current_org not in groups: user.user_profile.current_organization = groups.first() user.user_profile.save(update_fields=['current_organization'])
def get_organizations(self, user): groups = get_organization_groups(user).order_by('name') serializer = GroupSerializer(data=groups, many=True) serializer.is_valid() return serializer.data
def validate_organization(self, org_id): user = self.context.get('request').user try: return get_organization_groups(user).get(pk=org_id) except Group.DoesNotExist: raise serializers.ValidationError('Invalid id')
def get_queryset(self): request = self.context.get('request', None) if not request: return None return get_organization_groups(request.user)