def make_api_version(version_data): from readthedocs.builds.models import Version for key in ['resource_uri', 'absolute_url', 'downloads']: if key in version_data: del version_data[key] project_data = version_data['project'] project = make_api_project(project_data) version_data['project'] = project ver = Version(**version_data) ver.save = _new_save return ver
def _create_versions(project, type, versions): """ Create versions (tuple of version_id and version_name). Returns the slug of all added versions. .. note:: ``Version.slug`` relies on the post_save signal, so we can't use bulk_create. """ versions_objs = ( Version( project=project, type=type, identifier=version_id, verbose_name=version_name, ) for version_id, version_name in versions ) added = set() for version in versions_objs: version.save() added.add(version.slug) return added
def make_api_version(version_data): from readthedocs.builds.models import Version del version_data['resource_uri'] project_data = version_data['project'] project = make_api_project(project_data) version_data['project'] = project ver = Version(**version_data) return ver
def _create_versions_in_bulk(project, type, versions): """ Create versions (tuple of version_id and version_name) in batch. Returns the slug of all added versions. """ added = set() batch_size = 150 objs = (Version( project=project, type=type, identifier=version_id, verbose_name=version_name, ) for version_id, version_name in versions) while True: batch = list(itertools.islice(objs, batch_size)) if not batch: break Version.objects.bulk_create(batch, batch_size) added.update(v.slug for v in batch) return added
def setUp(self): self.project = Project.objects.get(slug='pip') self.version = Version(slug='foo', verbose_name='foobar') self.project.versions.add(self.version, bulk=False) self.mocks = EnvironmentMockGroup() self.mocks.start()
def setUp(self): self.project = Project.objects.get(slug='pip') self.version = Version(slug='foo', verbose_name='foobar') self.project.versions.add(self.version, bulk=False)