コード例 #1
0
    def update(self, force_cache=False, force_db=False):
        """extend session expiry"""
        if frappe.session["user"] == "Guest":
            return

        now = frappe.utils.now()

        if force_cache:
            self.update_data_cache()
        else:
            self.data["data"]["last_updated"] = now

            # update session in db
        last_updated = utils.jaspersession_get_value("last_db_jasper_session_update")
        time_diff = frappe.utils.time_diff_in_seconds(now, last_updated) if last_updated else None

        # database persistence is secondary, don't update it too often
        updated_in_db = False
        if force_db or (time_diff == None) or (time_diff > 300):
            frappe.db.sql(
                """update tabJasperSessions set sessiondata=%s,
				lastupdate=NOW() where TIMEDIFF(NOW(), lastupdate) < TIME(%s) and status='Active'""",
                (str(self.data["data"]), utils.get_expiry_period()),
            )
            utils.jaspersession_set_value("last_db_jasper_session_update", now)
            updated_in_db = True
            frappe.db.commit()

            # set in memcache
        utils.jaspersession_set_value("jaspersession", self.data)

        return updated_in_db
コード例 #2
0
    def update(self, force_cache=False, force_db=False):
        """extend session expiry"""
        if (frappe.session['user'] == "Guest"):
            return

        now = frappe.utils.now()

        if force_cache:
            self.update_data_cache()
        else:
            self.data['data']['last_updated'] = now

        # update session in db
        last_updated = utils.jaspersession_get_value(
            "last_db_jasper_session_update")
        time_diff = frappe.utils.time_diff_in_seconds(
            now, last_updated) if last_updated else None

        # database persistence is secondary, don't update it too often
        updated_in_db = False
        if force_db or (time_diff == None) or (time_diff > 300):
            frappe.db.sql(
                """update tabJasperSessions set sessiondata=%s,
				lastupdate=NOW() where TIMEDIFF(NOW(), lastupdate) < TIME(%s) and status='Active'""",
                (str(self.data['data']), utils.get_expiry_period()))
            utils.jaspersession_set_value("last_db_jasper_session_update", now)
            updated_in_db = True
            frappe.db.commit()

        # set in memcache
        utils.jaspersession_set_value("jaspersession", self.data)

        return updated_in_db
コード例 #3
0
    def get_jasper_reqid_data_from_db(self, *reqId):
        #pos 0  must be request id
        rec = frappe.db.sql(
            """select reqid, data
			from tabJasperReqids where
			TIMEDIFF(NOW(), lastupdate) < TIME(%s) and reqid=%s""",
            (utils.get_expiry_period(reqId[0]), reqId[0]))
        return rec
コード例 #4
0
    def get_jasper_reqid_data_from_db(self, *reqId):
        # pos 0  must be request id
        rec = frappe.db.sql(
            """select reqid, data
			from tabJasperReqids where
			TIMEDIFF(NOW(), lastupdate) < TIME(%s) and reqid=%s""",
            (utils.get_expiry_period(reqId[0]), reqId[0]),
        )
        return rec
コード例 #5
0
    def _run_report_async(self,
                          path,
                          doc,
                          data=None,
                          params=None,
                          pformat="pdf",
                          ncopies=1,
                          for_all_sites=0):
        data = data or {}
        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)
        resp = []

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

        copies = [_("Original"), _("Duplicate"), _("Triplicate")]

        for m in range(ncopies):
            npram = copy.deepcopy(pram)
            if pram_copy_index != -1:
                values = pram[pram_copy_index].get("value", "")
                if not values or not values[0]:
                    npram[pram_copy_index]['value'] = [copies[m]]
                else:
                    npram[pram_copy_index]['value'] = [
                        frappe.utils.strip(values[m], ' \t\n\r')
                    ]

            if pram_copy_page_index != -1:
                npram[pram_copy_page_index]['value'] = [
                    str(m) + _(" of ") + str(ncopies)
                ]
            result = self.run_async(path,
                                    npram,
                                    data.get("report_name"),
                                    pformat=pformat)
            if result:
                requestId = result.get('requestId')
                reqDbObj = {
                    "data": {
                        "result": result,
                        "report_name": data.get("report_name"),
                        "last_updated": frappe.utils.now(),
                        'session_expiry': utils.get_expiry_period()
                    }
                }
                self.insert_jasper_reqid_record(requestId, reqDbObj)
                resp.append({
                    "requestId": requestId,
                    "report_name": data.get("report_name"),
                    "status": result.get('status')
                })
            else:
                frappe.msgprint(_("There was an error in report request."),
                                raise_exception=True)
        return resp
コード例 #6
0
 def make_internal_reqId(self, reqids, status, report_name):
     intern_reqId = "intern_reqid_" + uuid.uuid4().hex
     reqtime = frappe.utils.now()
     reqDbObj = {
         "data": {
             "reqids": reqids,
             "report_name": report_name,
             "last_updated": reqtime,
             "session_expiry": utils.get_expiry_period(intern_reqId),
             "db": frappe.conf.db_name,
             "site": frappe.local.site,
         }
     }
     self.insert_jasper_reqid_record(intern_reqId, reqDbObj)
     res = {"requestId": intern_reqId, "reqtime": reqtime, "status": status}
     return res
コード例 #7
0
 def make_internal_reqId(self, reqids, status, report_name):
     intern_reqId = "intern_reqid_" + uuid.uuid4().hex
     reqtime = frappe.utils.now()
     reqDbObj = {
         "data": {
             "reqids": reqids,
             "report_name": report_name,
             "last_updated": reqtime,
             'session_expiry': utils.get_expiry_period(intern_reqId),
             "db": frappe.conf.db_name,
             "site": frappe.local.site
         }
     }
     self.insert_jasper_reqid_record(intern_reqId, reqDbObj)
     res = {"requestId": intern_reqId, "reqtime": reqtime, "status": status}
     return res
コード例 #8
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
コード例 #9
0
	def createJasperSession(self):
		if self.user!="Guest":
			self.update_data_cache()
			self.data['data']['session_expiry'] = utils.get_expiry_period()
			self.insert_jasper_session_record()
			frappe.db.commit()
コード例 #10
0
	def createJasperSession(self):
		if self.user!="Guest":
			self.update_data_cache()
			self.data['data']['session_expiry'] = utils.get_expiry_period()
			self.insert_jasper_session_record()
			frappe.db.commit()
コード例 #11
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
コード例 #12
0
	def _run_report_async(self, path, doc, data=None, params=None, pformat="pdf", ncopies=1, for_all_sites=0):
		data = data or {}
		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)
		resp = []

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

		copies = [_("Original"), _("Duplicate"), _("Triplicate")]

		for m in range(ncopies):
			npram = copy.deepcopy(pram)
			if pram_copy_index != -1:
				values = pram[pram_copy_index].get("value","")
				if not values or not values[0]:
					npram[pram_copy_index]['value'] = [copies[m]]
				else:
					npram[pram_copy_index]['value'] = [frappe.utils.strip(values[m], ' \t\n\r')]

			if pram_copy_page_index != -1:
				npram[pram_copy_page_index]['value'] = [str(m) + _(" of ") + str(ncopies)]
			result = self.run_async(path, npram, data.get("report_name"), pformat=pformat)
			if result:
				requestId = result.get('requestId')
				reqDbObj = {"data":{"result": result, "report_name": data.get("report_name"), "last_updated": frappe.utils.now(),'session_expiry': utils.get_expiry_period()}}
				self.insert_jasper_reqid_record(requestId, reqDbObj)
				resp.append({"requestId":requestId, "report_name": data.get("report_name"), "status": result.get('status')})
			else:
				frappe.msgprint(_("There was an error in report request."),raise_exception=True)
		return resp