Wondering what is causing this? Had me stumped for some time, everything checks out in console when running in pieces
as a side note: the template is using the same object in other places and displaying values - the object in template is also the same one loaded in the console below
error
'NoneType' object has no attribute 'source'
template
{% form_transaction prop %}
console value of prop
>>> prop = VacationHome.objects.get(pk=1)
>>> prop
<VacationHome: Samantha Dunn's vacation home at Close to Disney>
>>> prop.sell
0
>>> prop.rent
1
>>> count = 0
>>> string = ''
>>> type = []
>>> num = 0
>>> for tr in TRANSACTION_MODEL:
... if getattr(prop, tr, False):
... type.append(count+1)
... cur_count = count+1
... string += '<li><label for="id_transaction_%s"><input type="checkbox" name="transaction" value="%s" id="id_transaction_%s" />%s</label></li>' % (count, cur_count, count, TRANSACTION_TITLE[count][1])
... num += 1
... count += 1
...
>>> string
'<li><label for="id_transaction_1"><input type="checkbox" name="transaction" value="2" id="id_transaction_1" />Rental</label></li>'
DEFINITIONS
TRANSACTION_TITLE = (
(1, 'Purchase'),
(2, 'Rental'),
(3, 'Exchange'),
)
TRANSACTION_MODEL = ['sell', 'rent', 'exchange']
template tag
@register.tag
def prop_form_transaction(parser, token):
try:
tag_name, prop = token.split_contents()
count = 0
string = ''
type = []
num = 0
for tr in TRANSACTION_MODEL:
if getattr(prop, tr, False):
type.append(count+1)
cur_count = count+1
string += '<li><label for="id_transaction_%s"><input type="checkbox" name="transaction" value="%s" id="id_transaction_%s" />%s</label></li>' % (count, cur_count, count, TRANSACTION_TITLE[count][1])
num += 1
count += 1
if num:
if num > 1:
return string
else:
return '<input type="hidden" name="transaction" value="'#+str(type[0])+'" />'
except ValueError:
raise template.TemplateSyntaxError, "%r tag requires exactly one argument" % token.contents.split()[0]
views
def property_list_city(request, type, city):
city = str(city).replace('-', ' ')
if type == 'timeshare':
timeshares = Timeshare.objects.filter(resort__city__icontains=city).filter(available__icontains=True)
resorts = Resort.objects.filter(city__icontains=city)
objects = chain(timeshares, resorts)
elif type == 'vacation_home':
objects = VacationHome.objects.filter(city__icontains=city)
else:
objects = False
context = { #line 265
'properties' : objects,
'title' : city,
'type' : type,
}
return render_to_response('properties/properties_list.html', context_instance=RequestContext(request, context))
traceback
Environment:
Request Method: GET
Request URL: http://localhost:8000/properties/single/vacation_home/1/
Django Version: 1.1
Python Version: 2.6.4
Installed Applications:
['django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.humanize',
'properties',
'config',
'sorl.thumbnail',
'haystack',
'south',
'debug_toolbar']
Installed Middleware:
('django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'debug_toolbar.middleware.DebugToolbarMiddleware')
Traceback:
File "/usr/local/lib/python2.6/dist-packages/django/core/handlers/base.py" in get_response
92. response = callback(request, *callback_args, **callback_kwargs)
File "/home/alvin/workspace/timeshare/properties/views.py" in property_single
272. return property_single_context(request, type, property)
File "/home/alvin/workspace/timeshare/properties/views.py" in property_single_context
265. return render_to_response('properties/single.html', context, context_instance=RequestContext(request))
File "/usr/local/lib/python2.6/dist-packages/django/shortcuts/__init__.py" in render_to_response
20. return HttpResponse(loader.render_to_string(*args, **kwargs), **httpresponse_kwargs)
File "/usr/local/lib/python2.6/dist-packages/django/template/loader.py" in render_to_string
103. t = get_template(template_name)
File "/usr/local/lib/python2.6/dist-packages/django/template/loader.py" in get_template
82. template = get_template_from_string(source, origin, template_name)
File "/usr/local/lib/python2.6/dist-packages/django/template/loader.py" in get_template_from_string
90. return Template(source, origin, name)
File "/usr/local/lib/python2.6/dist-packages/django_debug_toolbar-0.8.1.alpha-py2.6.egg/debug_toolbar/panels/template.py" in new_template_init
28. old_template_init(self, template_string, origin, name)
File "/usr/local/lib/python2.6/dist-packages/django/template/__init__.py" in __init__
168. self.nodelist = compile_string(template_string, origin)
File "/usr/local/lib/python2.6/dist-packages/django/template/__init__.py" in compile_string
189. return parser.parse()
File "/usr/local/lib/python2.6/dist-packages/django/template/__init__.py" in parse
285. compiled_result = compile_func(self, token)
File "/usr/local/lib/python2.6/dist-packages/django/template/loader_tags.py" in do_extends
169. nodelist = parser.parse()
File "/usr/local/lib/python2.6/dist-packages/django/template/__init__.py" in parse
285. compiled_result = compile_func(self, token)
File "/usr/local/lib/python2.6/dist-packages/django/template/loader_tags.py" in do_block
147. nodelist = parser.parse(('endblock', 'endblock %s' % block_name))
File "/usr/local/lib/python2.6/dist-packages/django/template/__init__.py" in parse
289. self.extend_nodelist(nodelist, compiled_result, token)
File "/usr/local/lib/python2.6/dist-packages/django/template/debug.py" in extend_nodelist
56. node.source = token.source
Exception Type: AttributeError at /properties/single/vacation_home/1/
Exception Value: 'NoneType' object has no attribute 'source'
Any ideas for where to look in debugging this are welcomed - big huge thanks in advance if you happen to know what is causing the error