copied from edx-platform