예제 #1
0
    def insert_report_doc(self, dn=None):
        file_data = {}
        file_size = check_max_file_size(self.content)
        content_hash = get_content_hash(self.content)

        file_data.update({
            "doctype": "File Data",
            "attached_to_report_name": self.parent,
            "attached_to_doctype": self.dt,
            "attached_to_name": dn,
            "file_size": file_size,
            "content_hash": content_hash,
            'file_name': os.path.basename(self.rel_path),
            'file_url': os.sep + self.rel_path.replace('\\', '/'),
        })

        f = frappe.get_doc(file_data)
        try:
            f.insert(ignore_permissions=True)
            if self.ext == "jrxml":
                self.make_content_jrxml(f.name)

        except frappe.DuplicateEntryError:
            return frappe.get_doc("File Data", f.duplicate_entry)
        return f
	def insert_report_doc(self, dn=None):
		file_data = {}
		file_size = check_max_file_size(self.content)
		content_hash = get_content_hash(self.content)

		file_data.update({
			"doctype": "File",
			"attached_to_report_name": self.parent,
			"attached_to_doctype": self.dt,
			"attached_to_name": dn,
			"file_size": file_size,
			"content_hash": content_hash,
			'file_name': os.path.basename(self.rel_path),
			'file_url': os.sep + self.rel_path.replace('\\','/'),
		})

		f = frappe.get_doc(file_data)
		try:
			f.insert(ignore_permissions=True)
			if self.ext == "jrxml":
				self.make_content_jrxml(f.name)

		except frappe.DuplicateEntryError:
			return frappe.get_doc("File", f.duplicate_entry)
		return f
	def insert_report_doc(self, dn=None):
		file_data = {}
		file_size = check_max_file_size(self.content)
		content_hash = get_content_hash(self.content)


		file_name = os.path.basename(self.rel_path)
		image = False

		file_url = os.sep + self.rel_path.replace('\\','/')
		try:
			Image.open(StringIO.StringIO(self.content)).verify()
			file_url = os.sep + "files" + os.sep + self.rel_path.replace('\\','/')
			image = True
		except Exception:
			pass


		file_data.update({
			"doctype": "File",
			"attached_to_report_name": self.parent,
			"attached_to_doctype": self.dt,
			"attached_to_name": dn,
			"file_size": file_size,
			"content_hash": content_hash,
			'file_name': file_name,
			'file_url': file_url,
		})

		f = frappe.get_doc(file_data)
		f.flags.ignore_file_validate = True
		if image:
			self.make_thumbnail(file_url, f, dn)

		under = "Home/Attachments"
		f.folder = under + os.path.dirname(file_url.replace("/files", ""))
		self.create_new_folder(file_url, dn)

		try:
			f.insert(ignore_permissions=True)
			if self.ext == "jrxml":
				self.make_content_jrxml(f.name)
		except frappe.DuplicateEntryError:
			return frappe.get_doc("File", f.duplicate_entry)
		return f
	def insert_report_doc(self, dn=None):
		file_data = {}
		file_size = check_max_file_size(self.content)
		content_hash = get_content_hash(self.content)


		file_name = os.path.basename(self.rel_path)
		image = False

		file_url = os.sep + self.rel_path.replace('\\','/')
		try:
			Image.open(StringIO.StringIO(self.content)).verify()
			file_url = os.sep + "files" + os.sep + self.rel_path.replace('\\','/')
			image = True
		except Exception:
			pass


		file_data.update({
			"doctype": "File",
			"attached_to_report_name": self.parent,
			"attached_to_doctype": self.dt,
			"attached_to_name": dn,
			"file_size": file_size,
			"content_hash": content_hash,
			'file_name': file_name,
			'file_url': file_url,
		})

		f = frappe.get_doc(file_data)
		f.flags.ignore_file_validate = True
		if image:
			self.make_thumbnail(file_url, f, dn)

		under = "Home/Attachments"
		f.folder = under + os.path.dirname(file_url.replace("/files", ""))
		self.create_new_folder(file_url, dn)

		try:
			f.insert(ignore_permissions=True)
			if self.ext == "jrxml":
				self.make_content_jrxml(f.name)
		except frappe.DuplicateEntryError:
			return frappe.get_doc("File", f.duplicate_entry)
		return f