Raja
unread,Mar 17, 2008, 2:26:06 AM3/17/08Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to cherrypy-users
Hi all,
I face aproblem in cherrypy.
Following is my code.
import cherrypy
import os
from cherrypy.lib import static
class ReturnFile():
def index(self,path):
cherrypy.response.headers['Content-Type']= "text/javascript"
f = open(path, "rb")
contents = f.read()
f.close()
return contents
index.exposed = True
class root:
def index( self ):
return '''
<HTML>
<BODY>
<FORM name=login_page action="/ReportBuilder/"
enctype="multipart/form-data" method="POST">
<TABLE bgcolor=lightsteelblue align=center >
<TR>
<TD colspan=2 align=middle><INPUT type="submit" value="Login"></TD>
</TR>
</TABLE>
</FORM>
</BODY>
</HTML>'''
index.exposed = True
def ReportBuilder(self):
return '''<HTML><HEAD>
<script language="javascript" type="text/javascript" src="/
return_file/?path=script/cal.js"></script>
<style>
.today {COLOR: black; FONT-FAMILY: sans-serif; FONT-SIZE: 10pt;
FONT-WEIGHT: bold}
.days {COLOR: navy; FONT-FAMILY: sans-serif; FONT-SIZE: 10pt;
FONT-WEIGHT: bold; TEXT-ALIGN: center}
.dates {COLOR: black; FONT-FAMILY: sans-serif; FONT-SIZE: 10pt}
</style>
<TITLE>Report Builder</TITLE>
</HEAD>
<BODY>
<FORM name=report_form action="/showReport/" enctype="multipart/
form-data" method="post">
<TABLE align=center bgcolor=lightsteelblue style="WIDTH: 838px;
HEIGHT: 64px">
<TR>
<TD >
Assignee:
</TD>
<TD>
<SELECT name=assignee_name style="WIDTH: 157px">
<OPTION value="01">01</OPTION>
<OPTION value="02">02</OPTION>
<OPTION value="03">03</OPTION>
<OPTION value="04">04</OPTION>
</SELECT>
</TD>
<TD>Log Date From:</TD>
<TD>
<input id=log_date_from name=log_date_from type="text" size="25"
value="00-00-0000" readOnly>
<a href="javascript:toggleCalendar('log_date_from')">
<img src="/showimage/?path=images/calendar.gif" width="16"
height="16" border="0" alt="Pick a date"></a>
</TD>
</TR>
<TR>
<TD>Log Date To:</TD>
<TD>
<input id=log_date_to name=log_date_to type="text" size="25"
value="00-00-0000" readOnly>
<a href="javascript:toggleCalendar('log_date_to')">
<img src="/showimage/?path=images/calendar.gif" width="16"
height="16" border="0" alt="Pick a date"></a>
</TD>
<TD>
Submitter:
</TD>
<TD>
<SELECT name=submitter_name style="WIDTH: 156px">
<OPTION value="01">01</OPTION>
<OPTION value="02">02</OPTION>
<OPTION value="03">03</OPTION>
<OPTION value="04">04</OPTION>
</SELECT>
</TD>
</TR>
<TR>
<TD>
Priority:
</TD>
<TD> <SELECT id=select4 name=priority_value >
<OPTION value="00" selected ></OPTION>
<OPTION value="Low">Low</OPTION>
<OPTION value="Medium">Medium</OPTION>
<OPTION value="High">High</OPTION>
</SELECT>
</TD>
</TR>
<TR>
<TD>
Status:
</TD>
<TD> <SELECT id=select5 name=status_value >
<OPTION value="00" selected ></OPTION>
<OPTION value="Open">Open</OPTION>
<OPTION value="Closed">Closed</OPTION>
</SELECT>
</TD>
<TD>Fix Date From:</TD>
<TD>
<input id=fix_date_from name=fix_date_from type="text" size="25"
value="00-00-0000" readOnly>
<a href="javascript:toggleCalendar('fix_date_from')">
<img src="/showimage/?path=images/calendar.gif" width="16"
height="16" border="0" alt="Pick a date"></a>
</TD>
</TR>
<TR>
<TD>
Graph Type:
</TD>
<TD> <SELECT id=select6 name=graph_type >
<OPTION value="00" selected ></OPTION>
<OPTION value="Bar">Bar</OPTION>
<OPTION value="Pie">Pie</OPTION>
<OPTION value="Line">Line</OPTION>
</SELECT>
</TD>
<TD>Fix Date To:</TD>
<TD>
<input id=fix_date_to name=fix_date_to type="text" size="25"
value='00-00-0000' readOnly>
<a href="javascript:toggleCalendar('fix_date_to')">
<img src="/showimage/?path=images/calendar.gif" width="16"
height="16" border="0" alt="Pick a date"></a>
</TD>
</TR>
<BR>
<TR align=center>
<TD colspan=4 align=center>
<INPUT type="submit" value=Submit ></FONT>
</TD>
</TR>
</TABLE>
</FORM>
<TABLE bgcolor=Bisque border=1 cellPadding=0 cellSpacing=3
id=calendar style="DISPLAY: none; POSITION=absolute"
bordercolor=DarkSlateGray bordercolordark=OliveDrab>
<TR>
<TD class=today colSpan=6 id=todayday onclick=getTodayDay()
bgcolor=SteelBlue ></TD>
<TD align=right bgcolor=#ea0000 ><IMG
onclick="javascript:HideCalendar()" src="/showimage/?path=images/
close.gif" alt="Close" style="CURSOR: hand"/></TD>
</TR>
<TR>
<TD colSpan=7 vAlign=center>
<!-- Month combo box -->
<SELECT id=month onchange=newCalendar()>
<SCRIPT language=JavaScript>
// Output months into the document.
// Select current month.
for (var intLoop = 0; intLoop < months.length; intLoop++)
document.write('<OPTION ' + (today.month == intLoop ?
'Selected' : '') + '>' + months[intLoop]);
</SCRIPT>
</SELECT>
<!-- Year combo box -->
<SELECT id=year onchange=newCalendar()>
<SCRIPT language=JavaScript>
// Output years into the document.
// Select current year.
for (var intLoop = 1900; intLoop < 2028; intLoop++)
document.write('<OPTION ' + (today.year == intLoop ?
'Selected' : '') + '>' + intLoop);
</SCRIPT>
</SELECT>
</TD>
</TR>
<TR class=days>
<!-- Generate column for each day. -->
<SCRIPT language=JavaScript>
// Output days.
for (var intLoop = 0; intLoop < days.length; intLoop++)
document.write("<TD >" + days[intLoop] + "</TD>");
</SCRIPT>
</TR>
<TBODY class=dates id=dayList onclick="getDate('')" vAlign=center>
<!-- Generate grid for individual days. -->
<SCRIPT language=JavaScript>
for (var intWeeks = 0; intWeeks < 6; intWeeks++)
{
document.write("<TR>");
for (var intDays = 0; intDays < days.length; intDays++)
document.write("<TD style='CURSOR: hand'></TD>");
document.write("</TR>");
}
</SCRIPT></TBODY></TABLE></BODY></HTML>'''
ReportBuilder.exposed = True
def showReport( self, assignee_name, submitter_name,
log_date_from, log_date_to, fix_date_from, fix_date_to,
priority_value, status_value, graph_type ):
return '''
<HTML>
<BODY>
WELCOME...
</HTML>
</BODY>'''
showReport.exposed = True
class ShowImage:
def index(self,path):
cherrypy.response.headers['Content-Type']= "image/jpg"
f = open(path, "rb")
contents = f.read()
f.close()
return contents
index.exposed = True
rt = root()
root.showimage = ShowImage()
root.return_file = ReturnFile()
cherrypy.tree.mount(rt)
if __name__ == '__main__':
cherrypy.config.update(os.path.join(os.path.dirname(__file__),
'tutorial.conf'))
current_dir = os.path.dirname(os.path.abspath(__file__))
cherrypy.config.update({'environment': 'production',
'log.error_file': 'site.log',
'log.screen': True})
cherrypy.server.quickstart()
cherrypy.engine.start()
-----------------------------------------------------------------------------------------------------------------------------------------
If u want to run this code, please create a "tutorial.conf" file in
the same directory from where u run the code.
In the "tutorial.conf" file add the following contents, save it and
then run the code.
[global]
server.socket_port = 80
server.thread_pool = 10
tools.sessions.on = True
Also please create a folder in same directory and name it as "script".
Inside the script folder create a file "cal.js" and paste the
underlying code.
-----------------------------------------------------------------------------------------------------------------------------------------
Now, if you run the code and see the results in browser you would get
a login button and when you click that button you would get a report
builder page.
There you can see "Log Date To" column and also you can find a small
square box by the side of it. If u click this it is expected to pop-up
a calendar.
As expected it is popping-up the calendar. But the problem is the
calendar overlaps with the under-lying combo-boxes. it overlaps with
only combo-boxes and not with text boxes.
I don't know why it is happening...
I think I am not making any mistakes in code... am I???
Could you please tell me a solution for this?????
----------------------------------------------------------------------------------------------------------------------------------------
Code for cal.js
----------------------
var months = new Array("January", "February", "March", "April", "May",
"June", "July", "August", "September", "October", "November",
"December");
var daysInMonth = new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31,
30, 31);
var days = new Array("S", "M", "T", "W", "T", "F", "S");
today = new getToday();
var element_id;
function getDays(month, year)
{
// Test for leap year when February is selected.
if (1 == month)
return ((0 == year % 4) && (0 != (year % 100))) ||
(0 == year % 400) ? 29 : 28;
else
return daysInMonth[month];
}
function getToday()
{
// Generate today's date.
this.now = new Date();
this.year = this.now.getFullYear() ; // Returned year XXXX
this.month = this.now.getMonth();
this.day = this.now.getDate();
}
function newCalendar()
{
var parseYear = parseInt(document.all.year
[document.all.year.selectedIndex].text);
var newCal = new Date(parseYear , document.all.month.selectedIndex,
1);
var day = -1;
var startDay = newCal.getDay();
var daily = 0;
today = new getToday(); // 1st call
if ((today.year == newCal.getFullYear() ) && (today.month ==
newCal.getMonth()))
day = today.day;
// Cache the calendar table's tBody section, dayList.
var tableCal = document.all.calendar.tBodies.dayList;
var intDaysInMonth =
getDays(newCal.getMonth(), newCal.getFullYear() );
for (var intWeek = 0; intWeek < tableCal.rows.length; intWeek++)
for (var intDay = 0;
intDay < tableCal.rows[intWeek].cells.length;
intDay++)
{
var cell = tableCal.rows[intWeek].cells[intDay];
// Start counting days.
if ((intDay == startDay) && (0 == daily))
daily = 1;
// Highlight the current day.
cell.style.color = (day == daily) ? "red" : "";
if(day == daily)
{
document.all.todayday.innerText= "Today: " + day + "/" +
(newCal.getMonth()+1) + "/" + newCal.getFullYear() ;
}
// Output the day number into the cell.
if ((daily > 0) && (daily <= intDaysInMonth))
cell.innerText = daily++;
else
cell.innerText = "";
}
}
function getTodayDay()
{
document.all[element_id].value = today.day + "/" + (today.month
+1) +
"/" + today.year;
//document.all.calendar.style.visibility="hidden";
//vivek: document.all.calendar.style.display="none";
document.all.year.selectedIndex =100;
document.all.month.selectedIndex = today.month;
}
function getDate()
{
// This code executes when the user clicks on a day
// in the calendar.
if ("TD" == event.srcElement.tagName)
// Test whether day is valid.
if ("" != event.srcElement.innerText)
{
var mn = document.all.month.selectedIndex+1;
var Year = document.all.year
[document.all.year.selectedIndex].text;
document.all[element_id].value=event.srcElement.innerText+"-"+mn
+"-" +Year;
//document.all.calendar.style.visibility="hidden";
document.all.calendar.style.display="none";
}
}
function GetBodyOffsetX(el_name, shift)
{
var x;
var y;
x = 0;
y = 0;
var elem = document.all[el_name];
do
{
x += elem.offsetLeft;
y += elem.offsetTop;
if (elem.tagName == "BODY")
break;
elem = elem.offsetParent;
} while (1 > 0);
shift[0] = x;
shift[1] = y;
return x;
}
function SetCalendarOnElement(el_name)
{
if (el_name=="")
el_name = element_id;
var shift = new Array(2);
GetBodyOffsetX(el_name, shift);
document.all.calendar.style.pixelLeft = shift[0]; // -
document.all.calendar.offsetLeft;
document.all.calendar.style.pixelTop = shift[1] + 25 ;
}
function ShowCalendar(elem_name)
{
if (elem_name=="")
elem_name = element_id;
element_id = elem_name; // element_id is global variable
newCalendar();
SetCalendarOnElement(element_id);
//document.all.calendar.style.visibility = "visible";
document.all.calendar.style.display="inline";
}
function HideCalendar()
{
//document.all.calendar.style.visibility="hidden";
document.all.calendar.style.display="none";
}
function toggleCalendar(elem_name)
{
//if (document.all.calendar.style.visibility == "hidden")
if(document.all.calendar.style.display=="none")
ShowCalendar(elem_name);
else
HideCalendar();
}
-------------------------------------------------------------------------------------------------------------------------------------------
Regards,
Raja