当前位置: 首页>>代码示例>>Python>>正文


Python Repository.admin_queryset方法代码示例

本文整理汇总了Python中moneta.repository.models.Repository.admin_queryset方法的典型用法代码示例。如果您正苦于以下问题:Python Repository.admin_queryset方法的具体用法?Python Repository.admin_queryset怎么用?Python Repository.admin_queryset使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在moneta.repository.models.Repository的用法示例。


在下文中一共展示了Repository.admin_queryset方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: index

# 需要导入模块: from moneta.repository.models import Repository [as 别名]
# 或者: from moneta.repository.models.Repository import admin_queryset [as 别名]
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))
开发者ID:wagnerwar,项目名称:Moneta,代码行数:28,代码来源:views.py


注:本文中的moneta.repository.models.Repository.admin_queryset方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。