Discussions
Categories
Groups
Community Home
Categories
INTERNAL ENABLEMENT
POPULAR
THRUST SERVICES & TOOLS
CLOUD EDITIONS
Quick Links
MY LINKS
HELPFUL TIPS
Back to website
Home
Intelligence (Analytics)
How would I integrate BIRT with Python Django?
mkdz
Has anyone been able to do this? If so, how? I've gotten it work partway using the Python module <pre class='_prettyXprint _lang-auto _linenums:0'>requests</pre>, but I'm stuck now.
Find more posts tagged with
Comments
kclark
Are you doing this on Linux or BSD? Are you getting any errors you can post here? I work with BSD and Linux regularly but I need to set this up on my VM to test it.
mkdz
This is on CentOS Linux. I created a form in Django that lets the user input parameters to a report. When the form is submitted, the view takes the parameters and creates a request and sends it to the BIRT Tomcat server. Now I am trying to render the response from the server. This is what I have in my view:<br />
<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>def birt_report(request, report_id, report_url=None, template='report_parameters.html'):
if request.method == 'POST':
form = ReportParametersForm(request.POST)
if form.is_valid():
report_params = form.save()
form_id = report_params.id
url = "http://<hostname>/BIRT-Viewer/frameset?__report=" + report_url + ".rptdesign"
url += "¶m_id=" + str(form_id)
r = requests.get(url)
return HttpResponse(content=str(r.content),status=200,content_type='text/html; charset=utf-8')
else:
form = ReportParametersForm()
return render(request,template, {
'form': form,
'report_url': report_url,
'report_id': report_id,
})</pre>
<br />
Everything works up to the point where I try to render what the BIRT server sends back to me. I get the default BIRT web app toolbar. However, the report part of the page is blank. Here's what it looks like:<br />
<br />
<img src='
http://i.stack.imgur.com/4FFsZ.png'
alt='Posted Image' class='bbc_img' /><br />
<br />
I took a look at what was going on when the page was loading and I get this error in my Javascript console:<br />
<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>POST http://<hostname>/<Django_URL>/__sessionId=20130410_103510_658?__sessionId=20130410_103510_658 404 (NOT FOUND)
prototype.js:656
Ajax.Request.Object.extend.request
prototype.js:656
Ajax.Request.Object.extend.initialize
prototype.js:631
(anonymous function)
prototype.js:24
BirtCommunicationManager.connect
BirtCommunicationManager.js:58
BirtEventDispatcher.sendEvent
BirtEventDispatcher.js:179
BirtEventDispatcher.broadcastEvent
BirtEventDispatcher.js:141
Object.extend.__init_pag
e BirtNavigationBar.js:243
init
<hostname>:1604
onload
<hostname>:91</pre>
<br />
When I go to the report via the BIRT Viewer webapp that is included with BIRT, the Javascript file <strong class='bbc'>prototype.js:656</strong>, uses this URL:<br />
<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>http://<hostname>/BIRT-Viewer/frameset?__report=<report_name>.rptdesign¶m_id=1&__sessionId=20130410_103510_658</pre>
<br />
instead of:<br />
<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>http://<hostname>/<Django_URL>/__sessionId=20130410_103510_658?__sessionId=20130410_103510_658</pre>
<br />
The report gets generated properly in my Eclipse Report Designer preview.
kclark
Thanks for the info! I'll work on it and get back to you once I've got it up and running on my end.
mkdz
<blockquote class='ipsBlockquote' data-author="'kclark'" data-cid="115912" data-time="1365619672" data-date="10 April 2013 - 11:47 AM"><p>
Thanks for the info! I'll work on it and get back to you once I've got it up and running on my end.<br /></p></blockquote>
<br />
Sure thing. Thank you very much for helping!<br />
<br />
A couple other pieces of information I found:<br />
<br />
The actual generated part of the report is in this HTML element on the page:<br />
<br />
<pre class='_prettyXprint _lang-auto _linenums:0'><div id="Document" class="birtviewer_document_fragment" style="left: 0px; width: 1570px; height: 265px;">
</div></pre>
<br />
In the BIRT Viewer web app that works correctly, there are a lot of other HTML elements underneath this element.<br />
<br />
In my Django app, this is the innermost HTML element. There are no children beneath this element. It seems as is the <strong class='bbc'>prototype.js</strong> script retrieves the content that is supposed to be children of this element, and it seems this part is not working.
kclark
What version of BIRT are you using?
mkdz
<blockquote class='ipsBlockquote' data-author="'kclark'" data-cid="115921" data-time="1365626559" data-date="10 April 2013 - 01:42 PM"><p>
What version of BIRT are you using?<br /></p></blockquote>
<br />
4.2.1
kclark
I've got to the same point you're at now. It looks like there are two ways to do this. You can either redirect to the viewer after you have the data from the form. Or you can create some Java code that will generate the report in HTML returning that as a String to your view similar to what I did in my JSF blog post. You should be able to use Py4J to call the Java from your view.
mkdz
<blockquote class='ipsBlockquote' data-author="'kclark'" data-cid="115946" data-time="1365699465" data-date="11 April 2013 - 09:57 AM"><p>
I've got to the same point you're at now. It looks like there are two ways to do this. You can either redirect to the viewer after you have the data from the form. Or you can create some Java code that will generate the report in HTML returning that as a String to your view similar to what I did in my JSF blog post. You should be able to use Py4J to call the Java from your view.<br /></p></blockquote>
<br />
Ok thanks! I wasn't sure if I was missing something or not. I've been playing around with some ways to call Java code in Python (JCC and JPype) so I will continue down that path. <br />
<br />
Can you link me to your blog post? Thanks!
kclark
<a class='bbc_url' href='
http://www.birt-exchange.org/org/forum/index.php?app=blog&module=display§ion=blog&blogid=45&showentry=442'>Here's
the post</a> sorry, I forgot to link it. Let me know if you need any help.
kclark
I was able to get this working without using any Java code, I used an iFrame and HttpResponse(). Here's the view that I wrote:<br />
<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>def birtReport(request):
if 'lastName' in request.GET:
message = "http://10.10.1.73:8080/birt/frameset?__report=test.rptdesign&__format=html&sample=" + request.GET['lastName']
html = "<html><head><body><iframe height=300 width=600 src=" + message + "></iframe></body></html>"
return HttpResponse(html)
else:
message = 'You submitted an empty form.'
return HttpResponse(message)</pre>
<br />
You could probably put that iFrame in a template to make the code more dynamic.
mkdz
<blockquote class='ipsBlockquote' data-author="'kclark'" data-cid="115970" data-time="1365783923" data-date="12 April 2013 - 09:25 AM"><p>
I was able to get this working without using any Java code, I used an iFrame and HttpResponse(). Here's the view that I wrote:<br />
<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>def birtReport(request):
if 'lastName' in request.GET:
message = "http://10.10.1.73:8080/birt/frameset?__report=test.rptdesign&__format=html&sample=" + request.GET['lastName']
html = "<html><head><body><iframe height=300 width=600 src=" + message + "></iframe></body></html>"
return HttpResponse(html)
else:
message = 'You submitted an empty form.'
return HttpResponse(message)</pre>
<br />
You could probably put that iFrame in a template to make the code more dynamic.<br /></p></blockquote>
<br />
This is what I ended up doing. I have a parameters form. When "Submit" is pressed, it executes an Ajax request to retrieve the HTML with the iframe in it. Then I modify the page and display the iframe. Thanks for your help!
kclark
<blockquote class='ipsBlockquote' data-author="'mkdz'" data-cid="116108" data-time="1366292886" data-date="18 April 2013 - 06:48 AM"><p>
This is what I ended up doing. I have a parameters form. When "Submit" is pressed, it executes an Ajax request to retrieve the HTML with the iframe in it. Then I modify the page and display the iframe. Thanks for your help!<br /></p></blockquote>
<br />
I ended up getting a django view working with the BIRT API using py4j. I'm writing up a blog on it today with an example. I'll link you to it once it's published.
mkdz
<blockquote class='ipsBlockquote' data-author="'kclark'" data-cid="116460" data-time="1367606081" data-date="03 May 2013 - 11:34 AM"><p>
I ended up getting a django view working with the BIRT API using py4j. I'm writing up a blog on it today with an example. I link you to it once it's published.<br /></p></blockquote>
<br />
Holy ****, you didn't have to keep going with all this. I got the iframe way working to my satisfaction. <br />
<br />
I also made it work by using Python to call a script that ran the Java code to generate the report as an html file. Then I read the html file in my view and fed that html to my template. The only downside to this was that it didn't have the nice toolbar stuff at the top, but I could manipulate the html easier.<br />
<br />
This is much appreciated, thanks a bunch!
mkdz
<blockquote class='ipsBlockquote' data-author="'kclark'" data-cid="116460" data-time="1367606081" data-date="03 May 2013 - 11:34 AM"><p>
I ended up getting a django view working with the BIRT API using py4j. I'm writing up a blog on it today with an example. I'll link you to it once it's published.<br /></p></blockquote>
<br />
Did you ever get a chance to write this up and publish it?
bimu
<p>I got this problem when i try to redirent a url with none parameter, the js BirtUtility.js add the sessionId with this code </p><p> </p><div>addURLParameter : function ( url, parameterName, parameterValue )</div><div>{</div><div>var paramPart = encodeURI(parameterName) + "=" + encodeURI(parameterValue);</div><div> </div><div>var lastChar = url.charAt(url.length - 1); </div><div>if ( lastChar != "&" && lastChar != "?" )</div><div>{</div><div>if ( url.indexOf("?") > 0 )</div><div>{</div><div>paramPart = "&" + paramPart ;</div><div>}</div><div>else</div><div>{</div><div>paramPart += "?" + paramPart ;</div><div>}<span> </span></div><div>}</div><div> </div><div>var anchorPos = url.lastIndexOf("#");</div><div>if ( anchorPos >= 0 )</div><div>{</div><div>// insert the param part before the anchor</div><div>url = url.substr(url, anchorPos - 1) + paramPart + url.substr(anchorPos);</div><div>}</div><div>else</div><div>{</div><div>url += paramPart;</div><div>}</div><div>return url;</div><div>},</div><p> </p><p>it's wrong ,you can change this code to remove the wrong sessionId.</p>