def upload(request): if request.method != "PUT": raise Http404("Unsupported request method") if request.META["CONTENT_TYPE"] != "text/plain": raise Http404("Unsupported content type") data = models.data() data.datetime = datetime.datetime.now() data.file = models.data_upload_to(data, None) data.format = "windows" path = data.file.path tmppath = path + ".tmp" (head,tail) = os.path.split(path) if not os.path.exists(head): os.makedirs(head) file = open(tmppath,"w") file.write(request.raw_post_data) file.close() os.rename(tmppath, path) data.save() return root(request)
def get_instance(self): instance = models.data() instance.datetime = datetime.datetime.now() return instance