def test_roles_update_repo_2(self): """ Test update repo name with same name """ repo = Repository.objects.create( name=self.repo_name, description=self.repo_desc, created_by=self.user ) api.roles_update_repo(repo, self.repo_slug) # this is to test that the repo created groups with the right name # they will raise an exception if they fail Group.objects.get(name=self.group_admin) Group.objects.get(name=self.group_curator) Group.objects.get(name=self.group_author)
def save(self, *args, **kwargs): """ Handle slugs and groups. """ is_update = False if self.id is None or self.name != get_object_or_404(Repository, id=self.id).name: # if it is an update of the repository, need the old slug if self.id is not None: is_update = True old_slug = get_object_or_404(Repository, id=self.id).slug self.slug = default_slugify( self.name, Repository._meta.model_name, lambda slug: Repository.objects.filter(slug=slug).exists()) # check if it's necessary to initialize the permissions new_repository = super(Repository, self).save(*args, **kwargs) if is_update: roles_update_repo(self, old_slug) return new_repository
def save(self, *args, **kwargs): """ Handle slugs and groups. """ is_update = False if self.id is None or self.name != get_object_or_404( Repository, id=self.id).name: # if it is an update of the repository, need the old slug if self.id is not None: is_update = True old_slug = get_object_or_404(Repository, id=self.id).slug self.slug = default_slugify( self.name, Repository._meta.model_name, lambda slug: Repository.objects.filter(slug=slug).exists() ) # check if it's necessary to initialize the permissions new_repository = super(Repository, self).save(*args, **kwargs) if is_update: roles_update_repo(self, old_slug) return new_repository
def save(self, *args, **kwargs): """ Handle slugs and groups. """ is_update = False if self.id is None or self.name != get_object_or_404( Repository, id=self.id).name: # if it is an update of the repository, need the old slug if self.id is not None: is_update = True old_slug = get_object_or_404(Repository, id=self.id).slug slug = slugify(self.name) count = 1 while Repository.objects.filter(slug=slug).exists(): slug = "{0}{1}".format(slugify(self.name), count) count += 1 self.slug = slug # check if it's necessary to initialize the permissions new_repository = super(Repository, self).save(*args, **kwargs) if is_update: roles_update_repo(self, old_slug) return new_repository