Mercurial > kallithea
changeset 1346:cf78d302d441 beta
#47 implemented deleting of empty groups. Fixed problem with full paths on nested groups
author | Marcin Kuzminski <marcin@python-works.com> |
---|---|
date | Mon, 23 May 2011 02:46:43 +0200 |
parents | 3bce31f026b8 |
children | 43b8e161be3f |
files | rhodecode/controllers/admin/repos_groups.py rhodecode/model/db.py rhodecode/model/forms.py rhodecode/model/repos_group.py |
diffstat | 4 files changed, 43 insertions(+), 12 deletions(-) [+] |
line wrap: on
line diff
--- a/rhodecode/controllers/admin/repos_groups.py Mon May 23 02:22:00 2011 +0200 +++ b/rhodecode/controllers/admin/repos_groups.py Mon May 23 02:46:43 2011 +0200 @@ -112,6 +112,27 @@ # method='delete') # url('repos_group', id=ID) + repos_group_model = ReposGroupModel() + gr = Group.get(id) + repos = gr.repositories.all() + if repos: + h.flash(_('This group contains %s repositores and cannot be ' + 'deleted' % len(repos)), + category='error') + return redirect(url('repos_groups')) + + + try: + repos_group_model.delete(id) + h.flash(_('removed repos group %s' % gr.group_name), category='success') + #TODO: in futureaction_logger(, '', '', '', self.sa) + except Exception: + log.error(traceback.format_exc()) + h.flash(_('error occurred during deletion of repos group %s' % gr.group_name), + category='error') + + return redirect(url('repos_groups')) + def show(self, id, format='html'): """GET /repos_groups/id: Show a specific item""" # url('repos_group', id=ID)
--- a/rhodecode/model/db.py Mon May 23 02:22:00 2011 +0200 +++ b/rhodecode/model/db.py Mon May 23 02:46:43 2011 +0200 @@ -320,6 +320,11 @@ return "<%s('%s:%s')>" % (self.__class__.__name__, self.group_id, self.group_name) + + @classmethod + def url_sep(cls): + return '/' + @property def parents(self): groups = [] @@ -338,7 +343,7 @@ @property def full_path(self): - return '/'.join([g.group_name for g in self.parents] + + return Group.url_sep().join([g.group_name for g in self.parents] + [self.group_name]) @property
--- a/rhodecode/model/forms.py Mon May 23 02:22:00 2011 +0200 +++ b/rhodecode/model/forms.py Mon May 23 02:46:43 2011 +0200 @@ -237,9 +237,9 @@ if value.get('repo_group'): gr = Group.get(value.get('repo_group')) group_path = gr.full_path - # value needs to be aware of group name - # it has to use '/' - repo_name_full = group_path + '/' + repo_name + # value needs to be aware of group name in order to check + # db key + repo_name_full = group_path + Group.url_sep() + repo_name else: group_path = '' repo_name_full = repo_name
--- a/rhodecode/model/repos_group.py Mon May 23 02:22:00 2011 +0200 +++ b/rhodecode/model/repos_group.py Mon May 23 02:46:43 2011 +0200 @@ -58,12 +58,12 @@ """ if parent_id: - parent_group_name = Group.get(parent_id).group_name + paths = Group.get(parent_id).full_path.split(Group.url_sep()) + parent_path = os.sep.join(paths) else: - parent_group_name = '' + parent_path = '' - create_path = os.path.join(self.repos_path, parent_group_name, - group_name) + create_path = os.path.join(self.repos_path, parent_path, group_name) log.debug('creating new group in %s', create_path) if os.path.isdir(create_path): @@ -81,13 +81,17 @@ """ pass - def __delete_group(self, group_name): + def __delete_group(self, group): """ Deletes a group from a filesystem - :param group_name: + :param group: instance of group from database """ - pass + paths = group.full_path.split(Group.url_sep()) + paths = os.sep.join(paths) + + rm_path = os.path.join(self.repos_path, paths) + os.rmdir(rm_path) def create(self, form_data): try: @@ -124,8 +128,9 @@ def delete(self, users_group_id): try: - users_group = self.get(users_group_id, cache=False) + users_group = Group.get(users_group_id) self.sa.delete(users_group) + self.__delete_group(users_group) self.sa.commit() except: log.error(traceback.format_exc())