Ejemplo n.º 1
0
def index(request: HttpRequest):
    repositories = Repository.index_queryset(request).annotate(
        package_count=Count('element'))
    if not request.user.has_perm('repository.add_repository'):
        form = None
    elif request.method == 'POST':
        form = get_repository_form()(request.POST)
        if form.is_valid():
            author = None if request.user.is_anonymous() else request.user
            repo = Repository(author=author,
                              name=form.cleaned_data['name'],
                              on_index=form.cleaned_data['on_index'],
                              archive_type=form.cleaned_data['archive_type'],
                              is_private=form.cleaned_data['is_private'])
            repo.save()
            for group in form.cleaned_data['admin_group']:
                repo.admin_group.add(group)
            for state in set(form.cleaned_data['states'].split()):
                ArchiveState(repository=repo, name=state, author=author).save()
            messages.info(request, _('Your new repository has been created.'))
            return HttpResponseRedirect(reverse('moneta:index'))
    else:
        form = get_repository_form()()
    # compute repos with admin rights
    upload_ids = {x.id for x in Repository.upload_queryset(request)}
    admin_ids = {x.id for x in Repository.admin_queryset(request)}
    template_values = {
        'repositories': repositories,
        'form': form,
        'request': request,
        'upload_ids': upload_ids,
        'admin_ids': admin_ids,
    }
    return render_to_response('moneta/index.html', template_values,
                              RequestContext(request))
Ejemplo n.º 2
0
def index(request: HttpRequest):
    repositories = Repository.index_queryset(request).annotate(package_count=Count('element'))
    if not request.user.has_perm('repository.add_repository'):
        form = None
    elif request.method == 'POST':
        form = get_repository_form()(request.POST)
        if form.is_valid():
            author = None if request.user.is_anonymous() else request.user
            repo = Repository(author=author, name=form.cleaned_data['name'], on_index=form.cleaned_data['on_index'],
                              archive_type=form.cleaned_data['archive_type'],
                              is_private=form.cleaned_data['is_private'])
            repo.save()
            for group in form.cleaned_data['admin_group']:
                repo.admin_group.add(group)
            for state in set(form.cleaned_data['states'].split()):
                ArchiveState(repository=repo, name=state, author=author).save()
            messages.info(request, _('Your new repository has been created.'))
            return HttpResponseRedirect(reverse('moneta:index'))
    else:
        form = get_repository_form()()
    # compute repos with admin rights
    upload_ids = {x.id for x in Repository.upload_queryset(request)}
    admin_ids = {x.id for x in Repository.admin_queryset(request)}
    template_values = {'repositories': repositories, 'form': form, 'request': request,
                       'upload_ids': upload_ids, 'admin_ids': admin_ids, }
    return render_to_response('moneta/index.html', template_values, RequestContext(request))
Ejemplo n.º 3
0
 def create_repository(self, repo_cls, name='test_repo', author=None, states='qualif prod'):
     assert issubclass(repo_cls, RepositoryModel)
     if author is None:
         author = User.objects.get_or_create(username='******')[0]
     repo = Repository(author=author, name=name, on_index=True, archive_type=repo_cls.archive_type, is_private=False)
     repo.save()
     for state in states.split():
         ArchiveState(repository=repo, name=state, author=author).save()
     return repo
Ejemplo n.º 4
0
 def create_repository(self,
                       repo_cls,
                       name='test_repo',
                       author=None,
                       states='qualif prod'):
     assert issubclass(repo_cls, RepositoryModel)
     if author is None:
         author = User.objects.get_or_create(username='******')[0]
     repo = Repository(author=author,
                       name=name,
                       on_index=True,
                       archive_type=repo_cls.archive_type,
                       is_private=False)
     repo.save()
     for state in states.split():
         ArchiveState(repository=repo, name=state, author=author).save()
     return repo