Re: Confused by attribute error

2009-03-27 Thread Briel

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

On 27 Mar., 22:52, Robocop  wrote:
> Hello again,
> So i'm working on some of my old code, and a previously (or so i
> remember) function no longer works.  When calling it my django page
> posts the error:
>
> AttributeError at /audit_sheets/TEST/
>
> 'list' object has no attribute 'user'
> Request Method:         POST
> Request URL:    http://support.mipscomputation.com/audit_sheets/TEST/
> Exception Type:         AttributeError
> Exception Value:
>
> 'list' object has no attribute 'user'
>
> Exception Location:     /usr/local/lib/python2.4/site-packages/django/
> contrib/auth/decorators.py in __call__, line 66
> Python Executable:      /usr/local/bin/python
> Python Version:         2.4.3
> Python Path:    ['/home/mipscomp/public_html/support', '/home/mipscomp/
> public_html/support', '/usr/local/lib/python2.4/site-packages/
> MySQL_python-1.2.2-py2.4-linux-i686.egg', '/usr/local/lib/python2.4/
> site-packages/flup-1.0.1-py2.4.egg', '/usr/local/lib/python2.4/site-
> packages/python_memcached-1.43-py2.4.egg', '/usr/local/lib/python2.4/
> site-packages/pycrypto-2.0.1-py2.4-linux-i686.egg', '/usr/local/lib/
> python2.4/site-packages/Reportlab-2.1.0001-py2.5.egg', '/usr/local/lib/
> python2.4/site-packages/django_registration-0.7-py2.4.egg', '/usr/
> local/lib/python2.4/site-packages/elementtree-1.2.7_20070827_preview-
> py2.4.egg', '/usr/local/lib/python2.4/site-packages/docutils-0.5-
> py2.4.egg', '/usr/local/lib/python2.4/site-packages/setuptools-0.6c9-
> py2.4.egg', '/usr/local/lib/python24.zip', '/usr/local/lib/python2.4',
> '/usr/local/lib/python2.4/plat-linux2', '/usr/local/lib/python2.4/lib-
> tk', '/usr/local/lib/python2.4/lib-dynload', '/usr/local/lib/python2.4/
> site-packages', '/usr/local/lib/python2.4/site-packages/PIL']
> Server time:    Fri, 27 Mar 2009 16:46:47 -0500
>
> The line in question is:
>
> #  timesheet_export(timesheets,date)
>
> where timesheet_export is my special lil function, and timesheets is a
> list of objects.  Now the error seems to directly come from this:
>
> /usr/local/lib/python2.4/site-packages/django/contrib/auth/
> decorators.py in __call__
>
>   59. update_wrapper(self, view_func)
>   60.
>   61. def __get__(self, obj, cls=None):
>   62. view_func = self.view_func.__get__(obj, cls)
>   63. return _CheckLogin(view_func, self.test_func, self.login_url,
> self.redirect_field_name)
>   64.
>   65. def __call__(self, request, *args, **kwargs):
>
>   66. if self.test_func(request.user): ...
>
>   67. return self.view_func(request, *args, **kwargs)
>   68. path = urlquote(request.get_full_path())
>   69. tup = self.login_url, self.redirect_field_name, path
>   70. return HttpResponseRedirect('%s?%s=%s' % tup)
>
> And right now i'm not sure what the decorators.py file is trying to do
> with regards to my function.  Considering i've never explored the
> inner workings of decorators.py, i'm not sure exactly what it's doing
> in this instance.  All i know is it's looking for user attributes in a
> list of totally unrelated objects.  Any thoughts or ridicule are
> always appreciated!
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: Confused by attribute error

2009-03-27 Thread Robocop



On Mar 27, 3:05 pm, Briel  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

Re: Confused by attribute error

2009-03-27 Thread Robocop


Also i don't comment until i put my code into production (bad habit,
yes i know :x), so let me know if you need me to throw in some dirty
comments to make it more readable.
On Mar 27, 3:21 pm, Robocop  wrote:
> On Mar 27, 3:05 pm, Briel  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
> 

Re: Confused by attribute error

2009-03-30 Thread Robocop

Sorry for the delay, i've been sidetracked multiple times in the last
few days.  The code is post here:

http://dpaste.com/21221/

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: Confused by attribute error

2009-03-30 Thread Robocop

So the fun continues.  I realized that i did not need to use the
login_required decorator on this function since it's just tossed
around in the backend, so i took that out thinking it would prevent
decorators.py from being called.  When i hit the function above now,
it posts the same error with a different request (can be viewed here
http://dpaste.com/21238/ ).  The string object it's having trouble
with is this:
'/home/mipscomp/public_html/support/helpdesk/exported/03_30_09.txt

I'm pretty confused at this point, as i've never seen this error
before.  And the last time i recall working with this code, it worked
flawlessly.  Ridicule and ideas are greatly appreciated.

On Mar 30, 10:33 am, Robocop  wrote:
> Sorry for the delay, i've been sidetracked multiple times in the last
> few days.  The code is post here:
>
> http://dpaste.com/21221/
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: Confused by attribute error

2009-03-30 Thread Karen Tracey
On Mon, Mar 30, 2009 at 2:23 PM, Robocop  wrote:

>
> So the fun continues.  I realized that i did not need to use the
> login_required decorator on this function since it's just tossed
> around in the backend, so i took that out thinking it would prevent
> decorators.py from being called.


Did you take it out before even posting the code for timesheet_export?
Because there is no evidence of that function being decorated with
login_required in what you posted, which is a bit puzzling.


> When i hit the function above now,
> it posts the same error with a different request (can be viewed here
> http://dpaste.com/21238/ ).  The string object it's having trouble
> with is this:
> '/home/mipscomp/public_html/support/helpdesk/exported/03_30_09.txt
>
> I'm pretty confused at this point, as i've never seen this error
> before.  And the last time i recall working with this code, it worked
> flawlessly.  Ridicule and ideas are greatly appreciated.
>

The traceback is not so big it can't be posted:

Traceback:
File "/usr/local/lib/python2.4/site-packages/django/core/handlers/base.py"
in get_response
86. response = callback(request, *callback_args, **callback_kwargs)
File
"/usr/local/lib/python2.4/site-packages/django/contrib/auth/decorators.py"
in __call__
67. return self.view_func(request, *args, **kwargs)
File "/home/mipscomp/public_html/support/helpdesk/projects/views.py" in
audit_sheets_test
580. response = send_file(path,None, None)
File
"/usr/local/lib/python2.4/site-packages/django/contrib/auth/decorators.py"
in __call__
66. if self.test_func(request.user):

Exception Type: AttributeError at /audit_sheets/TEST/
Exception Value: 'str' object has no attribute 'user'

So, your code appears to be thinking it's calling a function called
"send_file" and passing in a path argument (likely the string object you
list above, as that quite looks like a path) but instead it jumps into
decorator code.  And the decorator code, instead of getting the request
object it expects as its first arg, get this path string, and dies a
horrible death trying to treat a string as a request object.

So it looks like another case of improper decoration. You cannot just
decorate arbitrary functions with @login_requried -- it expects to be used
specifically with view functions, that always get request as their first
argument. If you decorate some other function that doesn't take a request as
a first argument, you get errors like what you are reporting.

Karen

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: Confused by attribute error

2009-03-30 Thread Robocop

Bingo!  Looks like i was lazy with my code and threw decorators on ALL
the functions, not just my views.  There was a lingering decorator on
the send_file function that i did not notice.  Thanks for pointing out
my sloppines;)  You saved me a ton of time today, double thanks!
On Mar 30, 12:02 pm, Karen Tracey  wrote:
> On Mon, Mar 30, 2009 at 2:23 PM, Robocop  wrote:
>
> > So the fun continues.  I realized that i did not need to use the
> > login_required decorator on this function since it's just tossed
> > around in the backend, so i took that out thinking it would prevent
> > decorators.py from being called.
>
> Did you take it out before even posting the code for timesheet_export?
> Because there is no evidence of that function being decorated with
> login_required in what you posted, which is a bit puzzling.
>
> > When i hit the function above now,
> > it posts the same error with a different request (can be viewed here
> >http://dpaste.com/21238/).  The string object it's having trouble
> > with is this:
> > '/home/mipscomp/public_html/support/helpdesk/exported/03_30_09.txt
>
> > I'm pretty confused at this point, as i've never seen this error
> > before.  And the last time i recall working with this code, it worked
> > flawlessly.  Ridicule and ideas are greatly appreciated.
>
> The traceback is not so big it can't be posted:
>
> Traceback:
> File "/usr/local/lib/python2.4/site-packages/django/core/handlers/base.py"
> in get_response
>     86. response = callback(request, *callback_args, **callback_kwargs)
> File
> "/usr/local/lib/python2.4/site-packages/django/contrib/auth/decorators.py"
> in __call__
>     67. return self.view_func(request, *args, **kwargs)
> File "/home/mipscomp/public_html/support/helpdesk/projects/views.py" in
> audit_sheets_test
>     580. response = send_file(path,None, None)
> File
> "/usr/local/lib/python2.4/site-packages/django/contrib/auth/decorators.py"
> in __call__
>     66. if self.test_func(request.user):
>
> Exception Type: AttributeError at /audit_sheets/TEST/
> Exception Value: 'str' object has no attribute 'user'
>
> So, your code appears to be thinking it's calling a function called
> "send_file" and passing in a path argument (likely the string object you
> list above, as that quite looks like a path) but instead it jumps into
> decorator code.  And the decorator code, instead of getting the request
> object it expects as its first arg, get this path string, and dies a
> horrible death trying to treat a string as a request object.
>
> So it looks like another case of improper decoration. You cannot just
> decorate arbitrary functions with @login_requried -- it expects to be used
> specifically with view functions, that always get request as their first
> argument. If you decorate some other function that doesn't take a request as
> a first argument, you get errors like what you are reporting.
>
> Karen
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---