def add_repository_view(request): if request.method == 'POST': form = forms.RepositoryViewForm(request.POST) if form.is_valid(): repository = form.cleaned_data['repository'] params = form.cleaned_data['params'] data_source = form.cleaned_data['data_source'] # Don't support multiselect in projects yet project = form.cleaned_data['projects_state'] # Adding a new repository view try: data_source_orm = DataSource.objects.get(name=data_source) except DataSource.DoesNotExist: data_source_orm = DataSource(name=data_source) data_source_orm.save() # Try to find a repository already created try: repository_orm = Repository.objects.get( name=repository, data_source=data_source_orm) except Repository.DoesNotExist: # Create a new repository repository_orm = Repository(name=repository, data_source=data_source_orm) repository_orm.save() # Try to find a repository view already created try: repository_view_orm = RepositoryView.objects.get( params=params, repository=repository_orm) except RepositoryView.DoesNotExist: repository_view_orm = RepositoryView(params=params, repository=repository_orm) repository_view_orm.save() # If there is a project defined, add the repository view to the project if project: project_orm = Project.objects.get(name=project) project_orm.repository_views.add(repository_view_orm) project_orm.save() repository_view_orm.save() form.cleaned_data['repository_views_state'] = [] state = EditorState(form=form) return shortcuts.render(request, 'projects/editor.html', build_forms_context(state)) else: # TODO: Show error print(form.errors) raise Http404 # if a GET (or any other method) we'll create a blank form else: # TODO: Show error return shortcuts.render(request, 'projects/editor.html', build_forms_context())
def update_repository_view(request): if request.method == 'POST': form = forms.RepositoryViewForm(request.POST) if form.is_valid(): repository_view_id = form.cleaned_data['repository_view_id'] repository = form.cleaned_data['repository'] params = form.cleaned_data['params'] data_source = form.cleaned_data['data_source'] repository_view_orm = RepositoryView.objects.get( id=repository_view_id) try: repository_orm = Repository.objects.get(name=repository) repository_view_orm.repository = repository_orm except Repository.DoesNotExist: # Create a new repository data_source_orm = DataSource.objects.get(name=data_source) repository_orm = Repository(name=repository, data_source=data_source_orm) repository_orm.save() repository_view_orm.repository = repository_orm repository_view_orm.params = params repository_view_orm.save() msg = 'Data source has been updated' state = EditorState(repository_views=[repository_view_id], form=form, msg=msg) return shortcuts.render(request, 'projects/editor.html', build_forms_context(state)) else: # TODO: Show error raise Http404 # if a GET (or any other method) we'll create a blank form else: # TODO: Show error return shortcuts.render(request, 'projects/editor.html', build_forms_context())
logger.error("The project must already exists in Beastiary") sys.exit(1) for repo in repos.get_ids(): if not args.project: print(repo) else: try: ds_orm = DataSource.objects.get(name=args.data_source) except DataSource.DoesNotExist: logger.error("The data source %s does not exists in Bestiary", args.data_source) sys.exit(1) try: rep = Repository(name=repo, data_source=ds_orm) rep.save() except django.db.utils.IntegrityError: logger.debug('Repository already exists %s', repo) rep = Repository.objects.get(name=repo, data_source=ds_orm) try: # Don't support filters yet rep_view = RepositoryView(rep=rep, filters='') rep_view.save() except django.db.utils.IntegrityError: logger.debug('Repository View already exists %s', repo) rep_view = RepositoryView.objects.get(rep=rep, filters='') project_orm.rep_views.add(rep_view) if args.project: project_orm.save()