def manage(request, owner, package): """ """ template_name='userpypi/package_manage.html' template_object_name='package' form_class=PackageForm obj = get_object_or_404(Package, owner__username=owner, name=package) if request.method == 'POST': form = PackageForm(request.POST, instance=obj) if form.is_valid(): obj = form.save(commit=False) maintainer_formset = MaintainerFormSet(request.POST, instance=obj) if maintainer_formset.is_valid(): obj.save() maintainer_formset.save() return HttpResponseRedirect(reverse('userpypi-package-manage', kwargs={'owner': owner, 'package': obj})) else: form = PackageForm(instance=obj) maintainer_formset = MaintainerFormSet(instance=obj) t = loader.get_template(template_name) c = RequestContext(request, { 'form': form, 'maintainer_formset': maintainer_formset, 'package': obj, }) response = HttpResponse(t.render(c)) return response
def submit_package_or_release(user, post_data, files): """Registers/updates a package or release""" try: package = Package.objects.get(owner=user, name=post_data['name']) except Package.DoesNotExist: package = None package_form = PackageForm(post_data, instance=package) if package_form.is_valid(): package = package_form.save(commit=False) package.owner = user package.save() for c in post_data.getlist('classifiers'): classifier, created = Classifier.objects.get_or_create(name=c) package.classifiers.add(classifier) if files: allow_overwrite = ALLOW_VERSION_OVERWRITE try: release = Release.objects.get(version=post_data['version'], package=package, distribution=RELEASE_UPLOAD_TO + '/' + files['distribution']._name) if not allow_overwrite: return HttpResponseForbidden(ALREADY_EXISTS_FMT % (release.filename, release)) except Release.DoesNotExist: release = None # If the old file already exists, django will append a _ after the # filename, however with .tar.gz files django does the "wrong" # thing and saves it as package-0.1.2.tar_.gz. So remove it before # django sees anything. release_form = ReleaseForm(post_data, files, instance=release) if release_form.is_valid(): if release and os.path.exists(release.distribution.path): os.remove(release.distribution.path) release = release_form.save(commit=False) release.package = package release.save() else: return HttpResponseBadRequest("ERRORS: %s" % release_form.errors) else: return HttpResponseBadRequest("ERRORS: %s" % package_form.errors) return HttpResponse()
def submit_package_or_release(user, post_data, files): """Registers/updates a package or release""" try: package = Package.objects.get(owner=user, name=post_data['name']) except Package.DoesNotExist: package = None package_form = PackageForm(post_data, instance=package) if package_form.is_valid(): package = package_form.save(commit=False) package.owner = user package.save() for c in post_data.getlist('classifiers'): classifier, created = Classifier.objects.get_or_create(name=c) package.classifiers.add(classifier) if files: allow_overwrite = ALLOW_VERSION_OVERWRITE try: release = Release.objects.get(version=post_data['version'], package=package, distribution=RELEASE_UPLOAD_TO + '/' + files['distribution']._name) if not allow_overwrite: return HttpResponseForbidden(ALREADY_EXISTS_FMT % ( release.filename, release)) except Release.DoesNotExist: release = None # If the old file already exists, django will append a _ after the # filename, however with .tar.gz files django does the "wrong" # thing and saves it as package-0.1.2.tar_.gz. So remove it before # django sees anything. release_form = ReleaseForm(post_data, files, instance=release) if release_form.is_valid(): if release and os.path.exists(release.distribution.path): os.remove(release.distribution.path) release = release_form.save(commit=False) release.package = package release.save() else: return HttpResponseBadRequest( "ERRORS: %s" % release_form.errors) else: return HttpResponseBadRequest("ERRORS: %s" % package_form.errors) return HttpResponse()
def manage(request, owner, package): """ """ template_name = 'userpypi/package_manage.html' template_object_name = 'package' form_class = PackageForm obj = get_object_or_404(Package, owner__username=owner, name=package) if request.method == 'POST': form = PackageForm(request.POST, instance=obj) if form.is_valid(): obj = form.save(commit=False) maintainer_formset = MaintainerFormSet(request.POST, instance=obj) if maintainer_formset.is_valid(): obj.save() maintainer_formset.save() return HttpResponseRedirect( reverse('userpypi-package-manage', kwargs={ 'owner': owner, 'package': obj })) else: form = PackageForm(instance=obj) maintainer_formset = MaintainerFormSet(instance=obj) t = loader.get_template(template_name) c = RequestContext(request, { 'form': form, 'maintainer_formset': maintainer_formset, 'package': obj, }) response = HttpResponse(t.render(c)) return response