本文整理汇总了Python中moneta.repository.models.Repository.index_queryset方法的典型用法代码示例。如果您正苦于以下问题:Python Repository.index_queryset方法的具体用法?Python Repository.index_queryset怎么用?Python Repository.index_queryset使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类moneta.repository.models.Repository
的用法示例。
在下文中一共展示了Repository.index_queryset方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: index
# 需要导入模块: from moneta.repository.models import Repository [as 别名]
# 或者: from moneta.repository.models.Repository import index_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))