12345678910111213141516171819202122232425 |
- def publisher_api_upload(request, pub_name):
- """TastyPie does not support file uploads, so for now, this is handled
- outside of the normal API space.
- """
- if request.method == "POST":
- pub = models.Publisher.objects.get(name=pub_name)
- form = PublisherContentUploadValidator(request.POST, request.FILES)
- if form.is_valid():
- upload, async_task = edit_upload(
- pub, form.cleaned_data["file"], form.cleaned_data["meta"]
- )
- from iondb.rundb.api import ContentUploadResource
- resource = ContentUploadResource()
- bundle = Bundle(upload)
- serialized_upload = resource.serialize(
- None, resource.full_dehydrate(bundle), "application/json"
- )
- return HttpResponse(serialized_upload, mimetype="application/json")
- else:
- logger.warning(form.errors)
- else:
- return HttpResponseRedirect("/rundb/publish/%s/" % pub_name)
|