publishers_14.py 995 B

12345678910111213141516171819202122232425
  1. def publisher_api_upload(request, pub_name):
  2. """TastyPie does not support file uploads, so for now, this is handled
  3. outside of the normal API space.
  4. """
  5. if request.method == "POST":
  6. pub = models.Publisher.objects.get(name=pub_name)
  7. form = PublisherContentUploadValidator(request.POST, request.FILES)
  8. if form.is_valid():
  9. upload, async_task = edit_upload(
  10. pub, form.cleaned_data["file"], form.cleaned_data["meta"]
  11. )
  12. from iondb.rundb.api import ContentUploadResource
  13. resource = ContentUploadResource()
  14. bundle = Bundle(upload)
  15. serialized_upload = resource.serialize(
  16. None, resource.full_dehydrate(bundle), "application/json"
  17. )
  18. return HttpResponse(serialized_upload, mimetype="application/json")
  19. else:
  20. logger.warning(form.errors)
  21. else:
  22. return HttpResponseRedirect("/rundb/publish/%s/" % pub_name)