def delete_jrxml_child_file(path, jasper_all_sites):
	filename, extn = path.rsplit(".", 1)
	thumbnail_url = filename + "." + extn
	ppath = os.path.abspath(frappe.get_site_path("public", "files", thumbnail_url.lstrip("/")))
	if os.path.exists(ppath):
		os.remove(ppath)

	file_path = os.path.join(get_jasper_path(jasper_all_sites),path)
	if os.path.exists(file_path):
		os.remove(file_path)
def delete_jrxml_child_file(path, jasper_all_sites):
	filename, extn = path.rsplit(".", 1)
	thumbnail_url = filename + "." + extn
	ppath = os.path.abspath(frappe.get_site_path("public", "files", thumbnail_url.lstrip("/")))
	if os.path.exists(ppath):
		os.remove(ppath)

	file_path = os.path.join(get_jasper_path(jasper_all_sites),path)
	if os.path.exists(file_path):
		os.remove(file_path)
def get_email_other_path(data, file_name, reqId, sender):

	path_join = os.path.join
	rdoc = frappe.get_doc(data.get("doctype"), data.get('report_name'))
	for_all_sites = rdoc.jasper_all_sites_report
	jasper_path = get_jasper_path(for_all_sites)
	jasper_path_intern = path_join("jasper_sent_email", sender, reqId)
	outputPath = path_join(jasper_path, jasper_path_intern)
	frappe.create_folder(outputPath)
	file_path = path_join(outputPath, file_name)

	return file_path
Exemplo n.º 4
0
def get_email_other_path(data, file_name, reqId, sender):

    path_join = os.path.join
    rdoc = frappe.get_doc(data.get("doctype"), data.get('report_name'))
    for_all_sites = rdoc.jasper_all_sites_report
    jasper_path = get_jasper_path(for_all_sites)
    jasper_path_intern = path_join("jasper_sent_email", sender, reqId)
    outputPath = path_join(jasper_path, jasper_path_intern)
    frappe.create_folder(outputPath)
    file_path = path_join(outputPath, file_name)

    return file_path
def delete_file_jrxml_old(doc, event):
	dt = doc.attached_to_doctype
	if dt == "Jasper Reports":
		dn = doc.attached_to_name
		ext = get_extension(doc.file_name)
		jasper_all_sites_report = frappe.db.get_value(dt, dn, 'jasper_all_sites_report')
		file_path = os.path.join(get_jasper_path(jasper_all_sites_report), doc.file_url[1:])
		if os.path.exists(file_path) and ext == "jrxml":
			os.remove(file_path)
			delete_jrxml_images(dt, dn, jasper_all_sites_report)
			frappe.db.sql("""delete from `tab%s` where %s=%s """ % ("Jasper Parameter", "parent", '%s'),(dn), auto_commit=1)
			frappe.db.set_value(dt, dn, 'query', "")
		else:
			delete_jrxml_child_file(dt, jasper_all_sites_report)
	def __init__(self, dt, fname, content, parent):
		self.file_path = None
		self.dt = dt
		self.fname = fname
		self.content = content
		self.parent = parent
		self.dn = frappe.form_dict.docname
		self.autofilename = None
		self.ext = check_extension(self.fname)
		self.jasper_all_sites_report = frappe.db.get_value(self.dt, self.dn, 'jasper_all_sites_report')
		self.jasper_path = get_jasper_path(self.jasper_all_sites_report)
		self.compiled_path = get_compiled_path(self.jasper_path, self.dn)
		self.path_join = os.path.join
		self.scriptlet = None
		self.save_path = None
Exemplo n.º 7
0
 def __init__(self, dt, fname, content, parent):
     self.file_path = None
     self.dt = dt
     self.fname = fname
     self.content = content
     self.parent = parent
     self.dn = frappe.form_dict.docname
     self.autofilename = None
     self.ext = check_extension(self.fname)
     self.jasper_all_sites_report = frappe.db.get_value(
         self.dt, self.dn, 'jasper_all_sites_report')
     self.jasper_path = get_jasper_path(self.jasper_all_sites_report)
     self.compiled_path = get_compiled_path(self.jasper_path, self.dn)
     self.path_join = os.path.join
     self.scriptlet = None
     self.save_path = None
def getSubReportsQuery(xmlroot, doc):
	subquery = []
	check_for_report_images(xmlroot, doc)
	jasper_path = get_jasper_path(doc.jasper_all_sites_report)
	subreports = xmlroot.subreports
	for path_name in subreports:
		report_path = path_name.split("/",1)[1][:-6] + "jrxml"
		file_path = frappe.utils.get_path(doc.name, report_path, base=jasper_path)
		try:
			xmldoc = JasperXmlReport(file_path)
			subquery.append({"name": xmldoc.name, "query": xmldoc.queryString})
			subquery.extend(xmldoc.datasets)
			#check if the subreport has subreports too
			subquery.extend(getSubReportsQuery(xmldoc, doc))
		except:
			frappe.msgprint(_("Subreport %s is missing." % (report_path)), raise_exception=True)

	return subquery
Exemplo n.º 9
0
def delete_file_jrxml_old(doc, event):
    dt = doc.attached_to_doctype
    if dt == "Jasper Reports":
        dn = doc.attached_to_name
        ext = get_extension(doc.file_name)
        jasper_all_sites_report = frappe.db.get_value(
            dt, dn, 'jasper_all_sites_report')
        file_path = os.path.join(get_jasper_path(jasper_all_sites_report),
                                 doc.file_url[1:])
        if os.path.exists(file_path) and ext == "jrxml":
            os.remove(file_path)
            delete_jrxml_images(dt, dn, jasper_all_sites_report)
            frappe.db.sql("""delete from `tab%s` where %s=%s """ %
                          ("Jasper Parameter", "parent", '%s'), (dn),
                          auto_commit=1)
            frappe.db.set_value(dt, dn, 'query', "")
        else:
            delete_jrxml_child_file(dt, jasper_all_sites_report)
def delete_file_jrxml(doc, event):
	dt = doc.attached_to_doctype
	if dt == "Jasper Reports":
		dn = doc.attached_to_name
		ext = get_extension(doc.file_name)
		jasper_all_sites_report = frappe.db.get_value(dt, dn, 'jasper_all_sites_report')
		file_path = os.path.join(get_jasper_path(jasper_all_sites_report), doc.file_url[1:])
		path = os.path.normpath(os.path.join(file_path,".."))

		#don't remove directory if it is a subreport
		if ext == "jrxml":
			file_root_name, file_root_url = get_jrxml_root(dt,dn)
			if file_root_url == doc.file_url:
				from .file import remove_directory
				remove_directory(path)
				frappe.db.sql("""delete from `tab%s` where %s=%s """ % ("Jasper Parameter", "parent", '%s'),(dn), auto_commit=1)
				frappe.db.set_value(dt, dn, 'query', "")
		else:
			delete_jrxml_child_file(doc.file_url, jasper_all_sites_report)
Exemplo n.º 11
0
def getSubReportsQuery(xmlroot, doc):
    subquery = []
    check_for_report_images(xmlroot, doc)
    jasper_path = get_jasper_path(doc.jasper_all_sites_report)
    subreports = xmlroot.subreports
    for path_name in subreports:
        report_path = path_name[:-7] + ".jrxml"
        file_path = frappe.utils.get_path(doc.name,
                                          report_path,
                                          base=jasper_path)
        try:
            xmldoc = JasperXmlReport(file_path)
            subquery.append({"name": xmldoc.name, "query": xmldoc.queryString})
            subquery.extend(xmldoc.datasets)
            #check if the subreport has subreports too
            subquery.extend(getSubReportsQuery(xmldoc, doc))
        except:
            frappe.msgprint(_("Subreport %s is missing." % (report_path)),
                            raise_exception=True)

    return subquery
Exemplo n.º 12
0
def delete_file_jrxml(doc, event):
    dt = doc.attached_to_doctype
    if dt == "Jasper Reports":
        dn = doc.attached_to_name
        ext = get_extension(doc.file_name)
        jasper_all_sites_report = frappe.db.get_value(
            dt, dn, 'jasper_all_sites_report')
        file_path = os.path.join(get_jasper_path(jasper_all_sites_report),
                                 doc.file_url[1:])
        path = os.path.normpath(os.path.join(file_path, ".."))

        #don't remove directory if it is a subreport
        if ext == "jrxml":
            file_root_name, file_root_url = get_jrxml_root(dt, dn)
            if file_root_url == doc.file_url:
                from .file import remove_directory
                remove_directory(path)
                frappe.db.sql("""delete from `tab%s` where %s=%s """ %
                              ("Jasper Parameter", "parent", '%s'), (dn),
                              auto_commit=1)
                frappe.db.set_value(dt, dn, 'query', "")
        else:
            delete_jrxml_child_file(doc.file_url, jasper_all_sites_report)
def delete_file_jrxml(doc, event):
	print "delete file_name %s attach to doctype %s attech to name %s" % (doc.file_name, doc.attached_to_doctype, doc.attached_to_name)
	dt = doc.attached_to_doctype
	if dt == "Jasper Reports":
		if doc.is_folder:
			import shutil
			under = "Home/Attachments"
			parent_folder = os.path.join(doc.folder, doc.file_name)
			rel_path = os.path.relpath(parent_folder, under)
			path = os.path.abspath(frappe.get_site_path("public", "files", rel_path))
			print "removing directory %s" % path
			try:
				#os.remove(path)
				shutil.rmtree(path)
				return True
			except Exception, e:
				frappe.throw("Error: %s" % e)

		else:
			dn = doc.attached_to_name
			ext = get_extension(doc.file_name)
			jasper_all_sites_report = frappe.db.get_value(dt, dn, 'jasper_all_sites_report')
			#file_path = os.path.join(get_jasper_path(jasper_all_sites_report), doc.file_url[1:])
			file_path = os.path.join(get_jasper_path(jasper_all_sites_report), get_file_path(doc.file_url))
			path = os.path.normpath(os.path.join(file_path,".."))

			#don't remove directory if it is a subreport
			if ext == "jrxml":
				file_root_name, file_root_url = get_jrxml_root(dt,dn)
				if file_root_url == doc.file_url:
					from .file import remove_directory
					remove_directory(path)
					frappe.db.sql("""delete from `tab%s` where %s=%s """ % ("Jasper Parameter", "parent", '%s'),(dn), auto_commit=1)
					frappe.db.set_value(dt, dn, 'query', "")
			else:
				#delete_jrxml_child_file(doc.file_url.split("/files")[-1], jasper_all_sites_report)
				delete_jrxml_child_file(get_file_path(doc.file_url), jasper_all_sites_report)
def delete_file_jrxml(doc, event):
	print "delete file_name %s attach to doctype %s attech to name %s" % (doc.file_name, doc.attached_to_doctype, doc.attached_to_name)
	dt = doc.attached_to_doctype
	if dt == "Jasper Reports":
		if doc.is_folder:
			import shutil
			under = "Home/Attachments"
			parent_folder = os.path.join(doc.folder, doc.file_name)
			rel_path = os.path.relpath(parent_folder, under)
			path = os.path.abspath(frappe.get_site_path("public", "files", rel_path))
			print "removing directory %s" % path
			try:
				#os.remove(path)
				shutil.rmtree(path)
				return True
			except Exception, e:
				frappe.throw("Error: %s" % e)

		else:
			dn = doc.attached_to_name
			ext = get_extension(doc.file_name)
			jasper_all_sites_report = frappe.db.get_value(dt, dn, 'jasper_all_sites_report')
			#file_path = os.path.join(get_jasper_path(jasper_all_sites_report), doc.file_url[1:])
			file_path = os.path.join(get_jasper_path(jasper_all_sites_report), get_file_path(doc.file_url))
			path = os.path.normpath(os.path.join(file_path,".."))

			#don't remove directory if it is a subreport
			if ext == "jrxml":
				file_root_name, file_root_url = get_jrxml_root(dt,dn)
				if file_root_url == doc.file_url:
					from .file import remove_directory
					remove_directory(path)
					frappe.db.sql("""delete from `tab%s` where %s=%s """ % ("Jasper Parameter", "parent", '%s'),(dn), auto_commit=1)
					frappe.db.set_value(dt, dn, 'query', "")
			else:
				#delete_jrxml_child_file(doc.file_url.split("/files")[-1], jasper_all_sites_report)
				delete_jrxml_child_file(get_file_path(doc.file_url), jasper_all_sites_report)
Exemplo n.º 15
0
	def _run_report_async(self, path, doc, data=None, params=None, pformat="pdf", ncopies=1, for_all_sites=0):

		data = data or {}
		hashmap = jr.HashMap()
		pram, pram_server, copies = self.do_params(data, params, pformat, doc)
		pram_copy_index = copies.get("pram_copy_index", -1)
		pram_copy_page_index = copies.get("pram_copy_page_index", -1)

		path_join = os.path.join
		resp = []
		custom = doc.get("jasper_custom_fields")

		pram.extend(self.get_param_hook(doc, data, pram_server))

		self.populate_hashmap(pram, hashmap, doc.jasper_report_name)

		copies = [_("Original"), _("Duplicate"), _("Triplicate")]
		conn = ""
		if doc.query:
			conn = "jdbc:mysql://" + (frappe.conf.db_host or '127.0.0.1') + ":" + (frappe.conf.db_port or "3306") + "/" + frappe.conf.db_name + "?user="******"&password="******"report_name"))
			batch.outtype = print_format.index(pformat)
			batch.batchReport.setType(batch.outtype)
			batch.batchReport.setFileName(batch.reportName)
			reqId = uuid.uuid4().hex
			batch.outputPath = path_join(batch.compiled_path, reqId)
			frappe.create_folder(batch.outputPath)
			batch.batchReport.setOutputPath(batch.outputPath + os.sep + batch.reportName)
			batch.sessionId = "local_report_" + reqId

			res = self.prepareResponse({"reportURI": os.path.relpath(batch.outputPath, batch.jasper_path) + os.sep + batch.reportName + "." + pformat}, batch.sessionId)
			res["status"] = None
			res["report_name"] = data.get("report_name")
			resp.append(res)

			batch.batchReport.setTaskHandler(self.frappe_task)
			result = {"fileName": batch.reportName + "." + pformat, "uri":batch.outputPath + os.sep + batch.reportName + "." + pformat, "last_updated": res.get("reqtime"), 'session_expiry': utils.get_expiry_period(batch.sessionId)}
			self.insert_jasper_reqid_record(batch.sessionId, {"data":{"result":result, "report_name": data.get("report_name"), "last_updated": frappe.utils.now(),'session_expiry': utils.get_expiry_period()}})

			frappe.local.batch = batch

		lang = data.get("params", {}).get("locale", None) or "EN"
		cur_doctype = data.get("cur_doctype")
		ids = data.get('ids', [])[:]
		virtua = 0
		if doc.jasper_virtualizer:
			virtua = cint(frappe.db.get_value('JasperServerConfig', fieldname="jasper_virtualizer_pages")) or 0

		if custom and not frappe.local.fds:
			default = ['jasper_erpnext_report.jasper_reports.FrappeDataSource.JasperCustomDataSourceDefault']
			jds_method = utils.jasper_run_method_once_with_default("jasper_custom_data_source", data.get("report_name"), default)
			frappe.local.fds = jds_method

		for m in range(ncopies):
			if pram_copy_index != -1:
				values = pram[pram_copy_index].get("value","")
				pram_copy_name = pram[pram_copy_index].get("name","")
				if not values or not values[0]:
					hashmap.put(pram_copy_name, copies[m])
				else:
					hashmap.put(pram_copy_name, frappe.utils.strip(values[m], ' \t\n\r'))
			if pram_copy_page_index != -1:
				pram_copy_page_name = pram[pram_copy_page_index].get("name","")
				hashmap.put(pram_copy_page_name, str(m) + _(" of ") + str(ncopies))

			mparams = jr.HashMap()
			mparams.put("path_jasper_file", frappe.local.batch.compiled_path + os.sep)
			mparams.put("reportName", frappe.local.batch.reportName)
			mparams.put("outputPath", frappe.local.batch.outputPath + os.sep)
			mparams.put("params", hashmap)
			mparams.put("conn", conn)
			mparams.put("type", jr.Integer(frappe.local.batch.outtype))
			mparams.put("lang", lang)
			mparams.put("virtua", jr.Integer(virtua))
			#used for xml datasource
			mparams.put("numberPattern", frappe.db.get_default("number_format"))
			mparams.put("datePattern", frappe.db.get_default("date_format") + " HH:mm:ss")

			self._export_report(mparams, data.get("report_name"), data.get("grid_data"), frappe.local.batch.sessionId, cur_doctype, custom, ids, frappe.local.fds)
			if pram_copy_index != -1 and ncopies > 1:
				hashmap = jr.HashMap()
				self.populate_hashmap(pram, hashmap, doc.jasper_report_name)

		return resp
def delete_jrxml_child_file(path, jasper_all_sites):
	file_path = os.path.join(get_jasper_path(jasper_all_sites),path[1:])
	if os.path.exists(file_path):
		os.remove(file_path)
Exemplo n.º 17
0
def delete_jrxml_child_file(path, jasper_all_sites):
    file_path = os.path.join(get_jasper_path(jasper_all_sites), path[1:])
    if os.path.exists(file_path):
        os.remove(file_path)
def _get_jrxml_root_path(doc):
	jasper_path = get_jasper_path(doc.jasper_all_sites_report)
	root_jrxml_name, root_jrxml_url = get_jrxml_root(doc.doctype, doc.name)
	file_path = os.path.join(jasper_path, doc.name, root_jrxml_name)
	return file_path
Exemplo n.º 19
0
def _get_jrxml_root_path(doc):
    jasper_path = get_jasper_path(doc.jasper_all_sites_report)
    root_jrxml_name, root_jrxml_url = get_jrxml_root(doc.doctype, doc.name)
    file_path = os.path.join(jasper_path, doc.name, root_jrxml_name)
    return file_path
Exemplo n.º 20
0
    def _run_report_async(self,
                          path,
                          doc,
                          data=None,
                          params=None,
                          pformat="pdf",
                          ncopies=1,
                          for_all_sites=0):
        data = data or {}
        hashmap = jr.HashMap()
        pram, pram_server, copies = self.do_params(data, params, pformat)
        pram_copy_index = copies.get("pram_copy_index", -1)
        pram_copy_page_index = copies.get("pram_copy_page_index", -1)

        path_join = os.path.join
        resp = []
        custom = doc.get("jasper_custom_fields")

        pram.extend(self.get_param_hook(doc, data, pram_server))

        self.populate_hashmap(pram, hashmap, doc.jasper_report_name)

        copies = [_("Original"), _("Duplicate"), _("Triplicate")]
        conn = ""
        if doc.query:
            conn = "jdbc:mariadb://" + (frappe.conf.db_host or 'localhost') + ":" + (frappe.conf.db_port or "3306") + "/" + frappe.conf.db_name + "?user="******"&password="******"report_name"))
            batch.outtype = print_format.index(pformat)
            batch.batchReport.setType(batch.outtype)
            batch.batchReport.setFileName(batch.reportName)
            reqId = uuid.uuid4().hex
            batch.outputPath = path_join(batch.compiled_path, reqId)
            frappe.create_folder(batch.outputPath)
            batch.batchReport.setOutputPath(batch.outputPath + os.sep +
                                            batch.reportName)
            batch.sessionId = "local_report_" + reqId

            res = self.prepareResponse(
                {
                    "reportURI":
                    os.path.relpath(batch.outputPath, batch.jasper_path) +
                    os.sep + batch.reportName + "." + pformat
                }, batch.sessionId)
            res["status"] = None
            res["report_name"] = data.get("report_name")
            resp.append(res)
            result = {
                "fileName": batch.reportName + "." + pformat,
                "uri":
                batch.outputPath + os.sep + batch.reportName + "." + pformat,
                "last_updated": res.get("reqtime"),
                'session_expiry': utils.get_expiry_period(batch.sessionId)
            }
            self.insert_jasper_reqid_record(
                batch.sessionId, {
                    "data": {
                        "result": result,
                        "report_name": data.get("report_name"),
                        "last_updated": frappe.utils.now(),
                        'session_expiry': utils.get_expiry_period()
                    }
                })

            frappe.local.batch = batch

        lang = data.get("params", {}).get("locale", None) or "EN"
        cur_doctype = data.get("cur_doctype")
        ids = data.get('ids', [])[:]
        virtua = 0
        if doc.jasper_virtualizer:
            virtua = cint(
                frappe.db.get_value('JasperServerConfig',
                                    fieldname="jasper_virtualizer_pages")) or 0

        if custom and not frappe.local.fds:
            default = [
                'jasper_erpnext_report.jasper_reports.FrappeDataSource.JasperCustomDataSourceDefault'
            ]
            jds_method = utils.jasper_run_method_once_with_default(
                "jasper_custom_data_source", data.get("report_name"), default)
            frappe.local.fds = jds_method

        for m in range(ncopies):
            if pram_copy_index != -1:
                values = pram[pram_copy_index].get("value", "")
                pram_copy_name = pram[pram_copy_index].get("name", "")
                if not values or not values[0]:
                    hashmap.put(pram_copy_name, copies[m])
                else:
                    hashmap.put(pram_copy_name,
                                frappe.utils.strip(values[m], ' \t\n\r'))
            if pram_copy_page_index != -1:
                pram_copy_page_name = pram[pram_copy_page_index].get(
                    "name", "")
                hashmap.put(pram_copy_page_name,
                            str(m) + _(" of ") + str(ncopies))

            mparams = jr.HashMap()
            mparams.put("path_jasper_file",
                        frappe.local.batch.compiled_path + os.sep)
            mparams.put("reportName", frappe.local.batch.reportName)
            mparams.put("outputPath", frappe.local.batch.outputPath + os.sep)
            mparams.put("params", hashmap)
            mparams.put("conn", conn)
            mparams.put("type", jr.Integer(frappe.local.batch.outtype))
            mparams.put("lang", lang)
            mparams.put("virtua", jr.Integer(virtua))
            #used for xml datasource
            mparams.put("numberPattern",
                        frappe.db.get_default("number_format"))
            mparams.put("datePattern",
                        frappe.db.get_default("date_format") + " HH:mm:ss")

            self._export_report(mparams, data.get("report_name"),
                                data.get("grid_data",
                                         None), frappe.local.batch.sessionId,
                                cur_doctype, custom, ids, frappe.local.fds)
            if pram_copy_index != -1 and ncopies > 1:
                hashmap = jr.HashMap()
                self.populate_hashmap(pram, hashmap, doc.jasper_report_name)

        return resp