def index(self): c.repos_list = self.scm_model.get_repos() c.groups = Group.query().filter(Group.group_parent_id == None).all() return render('/index.html')
def validate_python(self, value, state): #TODO WRITE VALIDATIONS group_name = value.get('group_name') group_parent_id = int(value.get('group_parent_id') or -1) # slugify repo group just in case :) slug = repo_name_slug(group_name) # check for parent of self if edit and old_data['group_id'] == group_parent_id: e_dict = {'group_parent_id':_('Cannot assign this group ' 'as parent')} raise formencode.Invalid('', value, state, error_dict=e_dict) old_gname = None if edit: old_gname = Group.get( old_data.get('group_id')).group_name if old_gname != group_name or not edit: # check filesystem gr = Group.query().filter(Group.group_name == slug)\ .filter(Group.group_parent_id == group_parent_id).scalar() if gr: e_dict = {'group_name':_('This group already exists')} raise formencode.Invalid('', value, state, error_dict=e_dict)
def index(self, format='html'): """GET /repos_groups: All items in the collection""" # url('repos_groups') sk = lambda g:g.parents[0].group_name if g.parents else g.group_name c.groups = sorted(Group.query().all(), key=sk) return render('admin/repos_groups/repos_groups_show.html')
def validate_python(self, value, state): # TODO WRITE VALIDATIONS group_name = value.get('group_name') group_parent_id = value.get('group_parent_id') # slugify repo group just in case :) slug = repo_name_slug(group_name) # check for parent of self parent_of_self = lambda: ( old_data['group_id'] == int(group_parent_id) if group_parent_id else False ) if edit and parent_of_self(): e_dict = { 'group_parent_id': _('Cannot assign this group as parent') } raise formencode.Invalid('', value, state, error_dict=e_dict) old_gname = None if edit: old_gname = Group.get( old_data.get('group_id')).group_name if old_gname != group_name or not edit: # check group gr = Group.query()\ .filter(Group.group_name == slug)\ .filter(Group.group_parent_id == group_parent_id)\ .scalar() if gr: e_dict = { 'group_name': _('This group already exists') } raise formencode.Invalid('', value, state, error_dict=e_dict) # check for same repo repo = Repository.query()\ .filter(Repository.repo_name == slug)\ .scalar() if repo: e_dict = { 'group_name': _('Repository with this name already exists') } raise formencode.Invalid('', value, state, error_dict=e_dict)
def repo2db_mapper(initial_repo_list, remove_obsolete=False): """maps all repos given in initial_repo_list, non existing repositories are created, if remove_obsolete is True it also check for db entries that are not in initial_repo_list and removes them. :param initial_repo_list: list of repositories found by scanning methods :param remove_obsolete: check for obsolete entries in database """ sa = meta.Session() rm = RepoModel() user = sa.query(User).filter(User.admin == True).first() added = [] # fixup groups paths to new format on the fly # TODO: remove this in future for g in Group.query().all(): g.group_name = g.get_new_name(g.name) sa.add(g) for name, repo in initial_repo_list.items(): group = map_groups(name.split(Repository.url_sep())) if not rm.get_by_repo_name(name, cache=False): log.info("repository %s not found creating default", name) added.append(name) form_data = { "repo_name": name, "repo_name_full": name, "repo_type": repo.alias, "description": repo.description if repo.description != "unknown" else "%s repository" % name, "private": False, "group_id": getattr(group, "group_id", None), } rm.create(form_data, user, just_db=True) removed = [] if remove_obsolete: # remove from database those repositories that are not in the filesystem for repo in sa.query(Repository).all(): if repo.repo_name not in initial_repo_list.keys(): removed.append(repo.repo_name) sa.delete(repo) sa.commit() return added, removed
def index(self): sortables = ['name', 'description', 'last_change', 'tip', 'owner'] current_sort = request.GET.get('sort', 'name') current_sort_slug = current_sort.replace('-', '') if current_sort_slug not in sortables: c.sort_by = 'name' current_sort_slug = c.sort_by else: c.sort_by = current_sort c.sort_slug = current_sort_slug sort_key = current_sort_slug + '_sort' c.repos_list = self.scm_model.get_repos(sort_key=sort_key) c.groups = Group.query().filter(Group.group_parent_id == None).all() return render('/index.html')