1234567891011121314151617181920212223242526272829303132333435363738 |
- def publisher_upload(request, pub_name):
- """Display the publishers upload.html template on a GET of the page.
- If the view is POSTed to, the pass the uploaded data to the publisher.
- """
- pub = models.Publisher.objects.get(name=pub_name)
- if request.method == "POST":
- meta = request.POST.dict()
- files = list(request.FILES.values())
- if len(files) == 0:
- return render_to_json({"error": "Error: No file selected for upload"})
- else:
- try:
- meta["username"] = request.user.username
- upload, async_task = edit_upload(pub, files[0], json.dumps(meta))
- return render_to_json({"status": upload.status, "id": upload.id})
- except Exception as e:
- return render_to_json({"error": str(e)})
- else:
- action = request.get_full_path()
- error = ""
- contents = ""
- try:
- path = os.path.join(pub.path, "upload.html")
- with open(path, "r") as f:
- contents = f.read()
- except Exception:
- error = "Error: Unable to read %s" % path
- ctx = RequestContext(
- request, {"contents": contents, "action": action, "error": error}
- )
- return render_to_response(
- "rundb/configure/modal_publisher_upload.html", context_instance=ctx
- )
|