On Mar 27, 3:05 pm, Briel <toppe...@gmail.com> wrote:
> Hi.
> It would be really helpful to be able to look at your function as
> well. My
> Guess is that the problem lies there, since this is happening when you
> call the function. Even if the problem is within django it would be a
> lot
> easier to find when looking through your function to see what it does.
> Also please post it at dphaste or some other simelar website.
>
> ~Jakob
>
I've avoided posting the function just because it's a little long to
read, and doesn't do anything particularly interesting, but here you
go (thanks for the help by the way):
def timesheet_export(timesheets,date):
labor={'network_software_service':'NETSFT',
'emergency_night':'EMERGN ','emergency_weekend':'EMERG
','drop_off_at_mips':'DRPMIPS','consulting_block':'CNSLTNG','delivery':'DELIVERY'}
year, month, day =date.strftime("%Y-%M-%d").split("-")
path = "/home/mipscomp/public_html/support/helpdesk/
exported/"+date.strftime("%m_%d_%y")+".txt"
output = open(path, "w")
counter_list=0
timesheets.sort(key= lambda i:(i.department, i.engagement, i.date,
i.start))
for timesheet in timesheets:
pad50 = lambda s: s.ljust(50)
if counter_list==0:
department_name=timesheet.department
department=Department.objects.get(name=department_name)
dep_code=department.code
length=len(dep_code)
cust_num='0'*(7-length)+dep_code
header_line_raw=date.strftime("%Y/%m/%d")+"\",\""+cust_num
progress_line_raw="Progress Billing - "+timesheet.date.strftime
("%B, %Y")
progress_line=pad50(progress_line_raw)
if timesheet.engagement=='':
engagment_line_raw="NO SPECIFIC ENGAGEMENT"
else:
engagement_line_raw=timesheet.engagement.upper() + "
ENGAGEMENT"
try:
engagement_line=pad50(engagement_line_raw)
except UnboundLocalError:
engagement_line_raw="NO SPECIFIC ENGAGEMENT"
engagement_line=pad50(engagement_line_raw)
output.write("H,\""+header_line_raw+"\"\n")
output.write("C,\"C \",\""+progress_line+"\"\n")
output.write("C,\"C \",\""+engagement_line+"\"\n")
else:
if timesheet.engagement!=timesheets[counter_list-1].engagement:
department_name=timesheet.department
department=Department.objects.get(name=department_name)
dep_code=department.code
length=len(dep_code)
cust_num='0'*(7-length)+dep_code
header_line_raw=date.strftime("%Y/%m/%d")+"\",\""+cust_num
progress_line_raw="Progress Billing - "+timesheet.date.strftime
("%B, %Y")
progress_line=pad50(progress_line_raw)
if timesheet.engagement=='':
engagment_line_raw="NO SPECIFIC ENGAGEMENT"
else:
engagement_line_raw=timesheet.engagement.upper() + "
ENGAGEMENT"
try:
engagement_line=pad50(engagement_line_raw)
except UnboundLocalError:
engagement_line_raw="NO SPECIFIC ENGAGEMENT"
engagement_line=pad50(engagement_line_raw)
output.write("H,\""+header_line_raw+"\"\n")
output.write("C,\"C \",\""+progress_line+"\"\n")
output.write("C,\"C \",\""+engagement_line+"\"\n")
if timesheet.technician != 'No Specific Tech': #This section
writes the technician and hours line
first, last= timesheet.technician.split(' ')
if first=="Danielle" and last=="St. Romain":
title="No Specific Title"
else:
tech=User.objects.get(Q(first_name=first) & Q(last_name=last))
userprof_id=(tech.id + 1)
userprof=UserProfile.objects.get(id=userprof_id)
if userprof.title=='':
title="No Specific Title"
else:
title=userprof.title
if timesheet.technician == 'No Specific Tech':
title='No Specific Title'
tech_hours_raw=title+": "+timesheet.technician+",
"+timesheet.date.strftime("%m/%d/%y")+", "+ str(timesheet.billtime) +"
hrs."
else:
tech_hours_raw=title+": "+first+" "+last+",
"+timesheet.date.strftime("%m/%d/%y")+", "+ str(timesheet.billtime) +"
hrs."
tech_hours_line=pad50(tech_hours_raw)
output.write("S, [Timesheet data for timesheet #"+str(timesheet.id)
+"]\n")
billtime_raw=str(timesheet.billtime)
blength=len(billtime_raw)
billtime='0'*(8-blength)+billtime_raw
if len(str(timesheet.labor_code))>7:
labor_code_raw=str(labor[timesheet.labor_code])
else:
labor_code_raw=str(timesheet.labor_code)
llength=len(labor_code_raw)
labor_code=labor_code_raw+' '*(7-llength)
billtime_line=labor_code+"\",\""+billtime
output.write("M,\""+billtime_line+"\"\n")
lines=[]
pre_parse = ''
pre_parse = str(timesheet.description)
if len(pre_parse)<50:
string=pad50(pre_parse)
lines.append(string)
lines.append(50*' ')
else:
lines = (map(pad50,textwrap.wrap(pre_parse,50)))
counter=0
for line in lines:
if counter % 2 == 0:
try:
if lines[counter+1]:
output.write("C,\"C \",\""+line+"\"")
except:
output.write("C,\"C \",\""+line+"\"\n")
else:
output.write(",\""+line+"\"\n")
counter+=1
output.write("C,\"C \",\""+tech_hours_line+"\"\n")
if timesheet.ctsytime > 0.00:
ctsy_time=str(timesheet.ctsytime)
clength=len(ctsy_time)
ctsy='0'*(8-clength)+ctsy_time
output.write("M,\"CTSY \",\""+ctsy+"\"\n")
counter_list+=1
return None
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---