本文整理汇总了Python中moneta.repository.models.Repository.upload_queryset方法的典型用法代码示例。如果您正苦于以下问题:Python Repository.upload_queryset方法的具体用法?Python Repository.upload_queryset怎么用?Python Repository.upload_queryset使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类moneta.repository.models.Repository
的用法示例。
在下文中一共展示了Repository.upload_queryset方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: index
# 需要导入模块: from moneta.repository.models import Repository [as 别名]
# 或者: from moneta.repository.models.Repository import upload_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))
示例2: add_element
# 需要导入模块: from moneta.repository.models import Repository [as 别名]
# 或者: from moneta.repository.models.Repository import upload_queryset [as 别名]
def add_element(request: HttpRequest, rid):
repo = get_object_or_404(Repository.upload_queryset(request), id=rid)
class ElementForm(forms.Form):
package = forms.FileField(label=_('Package'))
states = forms.ModelMultipleChoiceField(repo.archivestate_set.all(), label=_('States'))
def clean(self):
data_ = super().clean()
if 'package' in self.cleaned_data:
if not repo.get_model().is_file_valid(self.cleaned_data['package']):
raise ValidationError(_('This repository is unable to handle this file.'))
return data_
if request.method == 'POST':
form = ElementForm(request.POST, files=request.FILES)
if form.is_valid():
try:
element = generic_add_element(request, repo, form.cleaned_data['package'],
[x.name for x in form.cleaned_data['states']])
messages.info(request, _('The package %(n)s has been successfully uploaded.') % {'n': element.filename})
except InvalidRepositoryException as e:
messages.error(request, _('Unable to add the package to this repository: %(msg)s.') % {'msg': str(e)})
return HttpResponseRedirect(reverse('moneta:add_element', kwargs={'rid': rid}))
else:
form = ElementForm()
template_values = {'form': form, 'repo': repo, 'upload_allowed': repo.upload_allowed(request)}
return render_to_response('moneta/add_package.html', template_values, RequestContext(request))
示例3: modify_repository
# 需要导入模块: from moneta.repository.models import Repository [as 别名]
# 或者: from moneta.repository.models.Repository import upload_queryset [as 别名]
def modify_repository(request: HttpRequest, rid):
repo = get_object_or_404(Repository.upload_queryset(request), id=rid)
author = None if request.user.is_anonymous() else request.user
if request.method == 'POST':
form = RepositoryUpdateForm(request.POST)
if form.is_valid():
new_state_names = set(form.cleaned_data['states'].split())
old_state_names = {x.name for x in repo.archivestate_set.all()}
for name in new_state_names - old_state_names: # new states
ArchiveState(name=name, repository=repo, author=author).save()
repo.on_index = form.cleaned_data['on_index']
repo.is_private = form.cleaned_data['is_private']
repo.save()
repo.admin_group.clear()
for group in form.cleaned_data['admin_group']:
repo.admin_group.add(group)
# repo.reader_group.clear()
# for group in form.cleaned_data['reader_group']:
# repo.reader_group.add(group)
removed_states = ArchiveState.objects.filter(name__in=old_state_names - new_state_names, repository=repo)
# noinspection PyUnresolvedReferences
Element.states.through.objects.filter(archivestate__in=removed_states).delete()
removed_states.delete()
messages.info(request, _('The repository %(repo)s has been modified.') % {'repo': repo.name})
return HttpResponseRedirect(reverse('moneta:modify_repository', kwargs={'rid': rid, }))
else:
form = RepositoryUpdateForm(initial={'on_index': repo.on_index, 'is_private': repo.is_private,
'reader_group': list(repo.reader_group.all()),
'states': ' '.join([x.name for x in repo.archivestate_set.all()]),
'admin_group': list(repo.admin_group.all())})
template_values = {'form': form, 'repo': repo, 'upload_allowed': repo.upload_allowed(request)}
return render_to_response('moneta/modify_repo.html', template_values, RequestContext(request))
示例4: delete_element
# 需要导入模块: from moneta.repository.models import Repository [as 别名]
# 或者: from moneta.repository.models.Repository import upload_queryset [as 别名]
def delete_element(request: HttpRequest, rid, eid):
from moneta.repository.forms import DeleteRepositoryForm
repo = get_object_or_404(Repository.upload_queryset(request), id=rid)
element = get_object_or_404(Element.objects.filter(repository=repo, id=eid))
if request.method == 'POST':
form = DeleteRepositoryForm(request.POST)
if form.is_valid():
element.delete()
messages.warning(request, _('The package %(repo)s has been deleted.') % {'repo': element.full_name})
return HttpResponseRedirect(reverse('moneta:index'))
else:
form = DeleteRepositoryForm()
template_values = {'form': form, 'repo': repo, 'element': element}
return render_to_response('moneta/delete_element.html', template_values, RequestContext(request))
示例5: delete_repository
# 需要导入模块: from moneta.repository.models import Repository [as 别名]
# 或者: from moneta.repository.models.Repository import upload_queryset [as 别名]
def delete_repository(request: HttpRequest, rid):
from moneta.repository.forms import DeleteRepositoryForm
repo = get_object_or_404(Repository.upload_queryset(request), id=rid)
if request.method == 'POST':
form = DeleteRepositoryForm(request.POST)
if form.is_valid():
for element in Element.objects.filter(repository=repo):
element.delete()
repo.delete()
messages.warning(request, _('The repository %(repo)s has been deleted.') % {'repo': repo.name})
return HttpResponseRedirect(reverse('moneta:index'))
else:
form = DeleteRepositoryForm()
template_values = {'form': form, 'repo': repo}
return TemplateResponse(request, 'moneta/delete_repo.html', template_values)
示例6: add_element_post
# 需要导入模块: from moneta.repository.models import Repository [as 别名]
# 或者: from moneta.repository.models.Repository import upload_queryset [as 别名]
def add_element_post(request: HttpRequest, rid):
try:
repo = Repository.upload_queryset(request).get(id=rid)
except Repository.DoesNotExist:
return HttpResponse(_('You cannot upload new packages to this repository'), status=403)
if request.method != 'POST':
return HttpResponse(_('Method not allowed'), status=405)
validators = [RegexValidator(r'[\w\.\-\(\)/]+')]
class ElementForm(forms.Form):
filename = forms.CharField(label=_('Package'), max_length=255, validators=validators)
states = forms.MultipleChoiceField(choices=[(x.name, x.name) for x in repo.archivestate_set.all()],
label=_('States'))
name = forms.CharField(label=_('Name'), max_length=255, validators=validators, required=False)
archive = forms.CharField(label=_('Archive'), max_length=255, validators=validators, required=False)
version = forms.CharField(label=_('Version'), max_length=255, validators=validators, required=False)
form = ElementForm(request.GET)
if not form.is_valid():
return TemplateResponse(request, 'moneta/not_allowed.html', {}, status=405)
tmp_file = tempfile.TemporaryFile(mode='w+b', dir=settings.FILE_UPLOAD_TEMP_DIR)
c = False
chunk = request.read(32768)
while chunk:
tmp_file.write(chunk)
c = True
chunk = request.read(32768)
tmp_file.flush()
tmp_file.seek(0)
if not c:
return HttpResponse(_('Empty file. You must POST a valid file.\n'), status=400)
uploaded_file = UploadedFile(name=form.cleaned_data['filename'], file=tmp_file)
try:
element = generic_add_element(request, repo, uploaded_file, form.cleaned_data['states'],
name=form.cleaned_data.get('name'), archive=form.cleaned_data.get('archive'),
version=form.cleaned_data.get('version'), )
except InvalidRepositoryException as e:
return HttpResponse(str(e), status=400)
finally:
tmp_file.close()
template_values = {'repo': repo, 'element': element}
return HttpResponse(_('Package %(element)s successfully added to repository %(repo)s.\n') % template_values)
示例7: force_index
# 需要导入模块: from moneta.repository.models import Repository [as 别名]
# 或者: from moneta.repository.models.Repository import upload_queryset [as 别名]
def force_index(self, request, rid, repo_slug):
repo = get_object_or_404(Repository.upload_queryset(request), id=rid, archive_type=self.archive_type)
self.generate_indexes(repo)
return HttpResponse(_('Indexes have been successfully rebuilt.'))