本文整理匯總了Python中moneta.repository.models.Repository.save方法的典型用法代碼示例。如果您正苦於以下問題:Python Repository.save方法的具體用法?Python Repository.save怎麽用?Python Repository.save使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類moneta.repository.models.Repository
的用法示例。
在下文中一共展示了Repository.save方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: index
# 需要導入模塊: from moneta.repository.models import Repository [as 別名]
# 或者: from moneta.repository.models.Repository import save [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))
示例2: create_repository
# 需要導入模塊: from moneta.repository.models import Repository [as 別名]
# 或者: from moneta.repository.models.Repository import save [as 別名]
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='test_user')[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