コード例 #1
0
def get_context(context):
    if frappe.local.session['sid'] == 'Guest':
        return {
            "message": _("Please login first."),
            "doc_title": _("Not Permitted")
        }

    jasper_report_path = frappe.form_dict.jasper_doc_path
    if not jasper_report_path:
        return {
            "message": _("Switch to Desk to see the list of reports."),
            "doc_title": _("Not Permitted")
        }

    filename = jasper_report_path.rsplit("/", 1)[1]
    doc_title = jasper_report_path.split("/", 1)[0]
    ext = get_extension(filename)

    if "pdf" == ext:
        viewer = viewer_pdf
    elif "html" == ext:
        viewer = viewer_html
    else:
        return {
            "message": _("Switch to Desk to see the list of reports."),
            "doc_title": _("Not Permitted")
        }

    context.children = get_all_email_reports()
    context.pathname = "Jasper Reports?jasper_doc_path=" + jasper_report_path
    return viewer(doc_title)
コード例 #2
0
	def process_childs(self):
		docs = frappe.get_all("File", fields=["file_name", "file_url"], filters={"attached_to_name": self.dn, "attached_to_doctype": self.dt, "name": self.parent})
		if not docs:
			frappe.msgprint(_("Add a report first."), raise_exception=True)
		for doc in docs:
			jrxml_ext = get_extension(doc.file_name)
			if jrxml_ext == "jrxml":
				#jrxml_os_path = self.path_join(self.jasper_path, doc.file_url[1:])
				jrxml_os_path = self.path_join(self.jasper_path, get_file_path(doc.file_url))
				xmldoc = JasperXmlReport(jrxml_os_path)
				if (self.ext!="properties" and self.ext != "xml"):
					image_path = xmldoc.get_image_path_from_jrxml(self.fname)
					self.file_path= self.path_join(self.compiled_path, os.path.normpath(image_path))
				elif (self.ext == "xml"):
					xmlname = xmldoc.getProperty("XMLNAME")
					if xmlname:
						xname = xmlname + ".xml"
						if xname != self.fname:
							frappe.msgprint(_("This report does't have %s as file source." % (self.fname,)),raise_exception=True)
						self.file_path = self.path_join(self.compiled_path, os.path.normpath(self.fname))
					else:
						frappe.msgprint(_("This report does't have %s as file source." % (self.fname,)),raise_exception=True)
				else:
					value = xmldoc.get_attrib("resourceBundle")
					if not value or value not in self.fname:
						frappe.msgprint(_("This report does't have %s as properties." % (self.fname,)),raise_exception=True)
					self.file_path = self.path_join(self.compiled_path, os.path.normpath(self.fname))
				break
			else:
				frappe.msgprint(_("Add a file for this report first."),raise_exception=True)
コード例 #3
0
	def process_childs(self):
		docs = frappe.get_all("File", fields=["file_name", "file_url"], filters={"attached_to_name": self.dn, "attached_to_doctype": self.dt, "name": self.parent})
		if not docs:
			frappe.msgprint(_("Add a report first."), raise_exception=True)
		for doc in docs:
			jrxml_ext = get_extension(doc.file_name)
			if jrxml_ext == "jrxml":
				#jrxml_os_path = self.path_join(self.jasper_path, doc.file_url[1:])
				jrxml_os_path = self.path_join(self.jasper_path, get_file_path(doc.file_url))
				xmldoc = JasperXmlReport(jrxml_os_path)
				if (self.ext!="properties" and self.ext != "xml"):
					image_path = xmldoc.get_image_path_from_jrxml(self.fname)
					self.file_path= self.path_join(self.compiled_path, os.path.normpath(image_path))
				elif (self.ext == "xml"):
					xmlname = xmldoc.getProperty("XMLNAME")
					if xmlname:
						xname = xmlname + ".xml"
						if xname != self.fname:
							frappe.msgprint(_("This report does't have %s as file source." % (self.fname,)),raise_exception=True)
						self.file_path = self.path_join(self.compiled_path, os.path.normpath(self.fname))
					else:
						frappe.msgprint(_("This report does't have %s as file source." % (self.fname,)),raise_exception=True)
				else:
					value = xmldoc.get_attrib("resourceBundle")
					if not value or value not in self.fname:
						frappe.msgprint(_("This report does't have %s as properties." % (self.fname,)),raise_exception=True)
					self.file_path = self.path_join(self.compiled_path, os.path.normpath(self.fname))
				break
			else:
				frappe.msgprint(_("Add a file for this report first."),raise_exception=True)
コード例 #4
0
def check_if_jrxml_exists_db(dt, dn, fname, parent=None):

	docs = frappe.get_all("File", fields=["file_name"], filters={"attached_to_name": dn, "attached_to_doctype": dt, "name": parent})
	for doc in docs:
		jrxml_ext = get_extension(doc.file_name)
		if not (jrxml_ext == "jrxml"):
			return doc.file_name
		return doc.file_name if fname == doc.file_name else None
	return None
コード例 #5
0
def check_if_jrxml_exists_db(dt, dn, fname, parent=None):

	docs = frappe.get_all("File", fields=["file_name"], filters={"attached_to_name": dn, "attached_to_doctype": dt, "name": parent})
	for doc in docs:
		jrxml_ext = get_extension(doc.file_name)
		if not (jrxml_ext == "jrxml"):
			return doc.file_name
		return doc.file_name if fname == doc.file_name else None
	return None
コード例 #6
0
def get_all_email_reports():
	approved_childs = []
	user_email = frappe.db.get_value("User", frappe.session.user, "email")
	crit = "`tabJasper Email Report`.jasper_email_sent_to='%s'" % (user_email,)
	childrens = frappe.get_all("Jasper Email Report", filters=[crit], fields=["jasper_report_path", "jasper_email_report_name", "jasper_file_name", "jasper_email_date"], order_by="jasper_email_date ASC", limit_page_length=10)
	for child in childrens:
		ext = get_extension(child.jasper_file_name)
		if ext == "pdf" or ext == "html":
			approved_childs.append(child)

	return approved_childs
コード例 #7
0
def get_all_email_reports():
	approved_childs = []
	user_email = frappe.db.get_value("User", frappe.session.user, "email")
	crit = "`tabJasper Email Report`.jasper_email_sent_to='%s'" % (user_email,)
	childrens = frappe.get_all("Jasper Email Report", filters=[crit], fields=["jasper_report_path", "jasper_email_report_name", "jasper_file_name", "jasper_email_date"], order_by="jasper_email_date ASC", limit_page_length=10)
	for child in childrens:
		ext = get_extension(child.jasper_file_name)
		if ext == "pdf" or ext == "html":
			approved_childs.append(child)

	return approved_childs
コード例 #8
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)
コード例 #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)
コード例 #10
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)
コード例 #11
0
def get_context(context):
	if frappe.local.session['sid'] == 'Guest':
		return {"message":_("Please login first."), "doc_title":_("Not Permitted")}

	jasper_report_path = frappe.form_dict.jasper_doc_path
	if not jasper_report_path:
		return {"message":_("Switch to Desk to see the list of reports."), "doc_title":_("Not Permitted")}

	filename = jasper_report_path.rsplit("/",1)[1]
	doc_title = jasper_report_path.split("/",1)[0]
	ext = get_extension(filename)

	if "pdf" == ext:
		viewer = viewer_pdf
	elif "html" == ext:
		viewer = viewer_html
	else:
		return {"message":_("Switch to Desk to see the list of reports."), "doc_title":_("Not Permitted")}

	context.children = get_all_email_reports()
	context.pathname = "Jasper Reports?jasper_doc_path=" + jasper_report_path
	return viewer(doc_title)
コード例 #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)
コード例 #13
0
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)
コード例 #14
0
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)
コード例 #15
0
    def get_report_server(self, data):
        #check if this requestId is older than last timeout
        self.validate_ticket(data)
        d = self.get_jasper_reqid_data(data.get('requestId'))
        report_name = d['data'].get("report_name")
        if not d:
            frappe.throw(_("Report Not Found."))
        """
		reqids represent the ids of documents.
		Example:
		if my document is of type (Report for) form and in list view i check more than one document, say n,
		then it will ask the server for n documents at once
		and for every document it will ask for one, two or tree copies
		as may have single, duplicated or triplicated checked.
		"""
        reqids = d['data'].get('reqids')
        content = []
        fileName = None
        try:
            for ids in reqids:
                """
				ask the server for one, two or tree documents if single, duplicated or triplicated respectively
				"""
                for id in ids:
                    report = self.get_jasper_reqid_data(id)
                    rdata = report.get('data').get('result')
                    reqId = [rdata.get("requestId")]
                    expId = rdata.get("ids")
                    fileName = expId[0].get("fileName", None)
                    file_ext = get_extension(fileName)
                    #this is for another situation
                    rid_len = 1
                    if not any("local_report" in r for r in reqId):
                        eid_len = len(expId)
                        self.get_server("server")
                        if not self.jps.is_login:
                            frappe.msgprint(_("Jasper Server, login error."))
                            return
                        #if lens not equal then process only the first
                        if rid_len == eid_len:
                            for i in range(rid_len):
                                c = self.jps.getReport(reqId[i],
                                                       expId[i].get('id'))
                                content.append(c)
                                if file_ext == "html":
                                    hash_obj = hashlib.md5(c)
                                    self.html_hash = hash_obj.hexdigest()
                                    self.getAttachments(
                                        reqId[i], expId[i].get('id'), expId[i],
                                        report_name)
                                    break

                        else:
                            """
							This situation only occurs when i get multiples sub documents (len expId > 1) for one request (document).
							This is jasper issue and it is here for future updates
							"""
                            c = self.jps.getReport(reqId[0],
                                                   expId[0].get('id'))
                            content.append(c)
                            if file_ext == "html":
                                hash_obj = hashlib.md5(c)
                                self.html_hash = hash_obj.hexdigest()
                                self.getAttachments(reqId[0],
                                                    expId[0].get('id'),
                                                    expId[0], report_name)
                    else:
                        self.get_server("local")
                        for i in range(rid_len):
                            c = self.jpl.getLocalReport(reqId[i])
                            content.append(c)
                            if file_ext == "html":
                                hash_obj = hashlib.md5(c)
                                self.html_hash = hash_obj.hexdigest()
                                break
        except Exception as e:
            return frappe.msgprint(
                _("There is no report, try again later. Error: {}".format(e)))

        return fileName, content, report_name
コード例 #16
0
	def get_report_server(self, data):
		#check if this requestId is older than last timeout
		self.validate_ticket(data)
		d = self.get_jasper_reqid_data(data.get('requestId'))
		print "get_report_server %s" % d
		report_name = d['data'].get("report_name")
		if not d:
			frappe.throw(_("Report Not Found."))
		"""
		reqids represent the ids of documents.
		Example:
		if my document is of type (Report for) form and in list view i check more than one document, say n,
		then it will ask the server for n documents at once
		and for every document it will ask for one, two or tree copies
		as may have single, duplicated or triplicated checked.
		"""
		reqids = d['data'].get('reqids')
		content = []
		fileName = None
		try:
			for ids in reqids:
				"""
				ask the server for one, two or tree documents if single, duplicated or triplicated respectively
				"""
				for id in ids:
					report = self.get_jasper_reqid_data(id)
					print "get_report_server id report %s" % report
					rdata = report.get('data').get('result')
					reqId = [rdata.get("requestId")]
					expId = rdata.get("ids")
					fileName = expId[0].get("fileName", None)
					file_ext = get_extension(fileName)
					#this is for another situation
					rid_len = 1
					if not any("local_report" in r for r in reqId):
						eid_len = len(expId)
						self.get_server("server")
						if not self.jps.is_login:
							frappe.msgprint(_("Jasper Server, login error."))
							return
						#if lens not equal then process only the first
						if rid_len == eid_len:
							for i in range(rid_len):
								c = self.jps.getReport(reqId[i], expId[i].get('id'))
								content.append(c)
								if file_ext == "html":
									hash_obj = hashlib.md5(c)
									self.html_hash = hash_obj.hexdigest()
									self.getAttachments(reqId[i], expId[i].get('id'), expId[i], report_name)
									break

						else:
							"""
							This situation only occurs when i get multiples sub documents (len expId > 1) for one request (document).
							This is jasper issue and it is here for future updates
							"""
							c = self.jps.getReport(reqId[0], expId[0].get('id'))
							content.append(c)
							if file_ext == "html":
								hash_obj = hashlib.md5(c)
								self.html_hash = hash_obj.hexdigest()
								self.getAttachments(reqId[0], expId[0].get('id'), expId[0], report_name)
					else:
						self.get_server("local")
						for i in range(rid_len):
							c = self.jpl.getLocalReport(reqId[i])
							content.append(c)
							if file_ext == "html":
								hash_obj = hashlib.md5(c)
								self.html_hash = hash_obj.hexdigest()
								break
		except Exception as e:
			return frappe.msgprint(_("There is no report, try again later. Error: {}".format(e)))

		return fileName, content, report_name