fix 500 on empty list returned

This commit is contained in:
Sanj 2012-06-12 02:10:24 +05:30
parent b3e477b9cf
commit 30b17f94a3
2 changed files with 21 additions and 11 deletions

View File

@ -288,11 +288,7 @@ class ItfModel(models.Model):
ret = []
page_no = options['page']
list_size = options['count']
try:
qset = kls.get_qset()
except:
qset = kls.objects.all()
qset = kls.get_qset()
search = options['search']
if search != '':
@ -320,6 +316,11 @@ class ItfModel(models.Model):
except:
pass
hasResults = True
if qset.count() == 0:
hasResults = False
qset = kls.get_qset()
'''
r0 = options['range'][0]
r1 = options['range'][1]
@ -343,6 +344,7 @@ class ItfModel(models.Model):
'has_next': results.has_next(),
'has_previous': results.has_previous(),
'page_no': page_no,
'has_results': hasResults,
'num_pages': paginator.num_pages,
'items': ret
}
@ -352,7 +354,7 @@ class ItfModel(models.Model):
'''
Override this method in your model class to define a custom queryset instead of objects.all(), for instance, to always exclude unpublished items.
'''
raise NotImplementedError
return kls.objects.all()
def getField(fields, name):
for f in fields:

View File

@ -112,12 +112,20 @@ def render_object(request, module_slug):
}
object_list = tab.get_list(list_options)
if object_id == 0:
if object_id == 0:
object_id = object_list['items'][0]['id']
obj = get_object_or_404(model_class, pk=object_id)
item_data = obj.insidepage_dict(request)
if object_list['has_results']:
obj = get_object_or_404(model_class, pk=object_id)
item_data = obj.insidepage_dict(request)
else: #Should be a better way to tell the template a search returned no result
obj = {
'get_title': 'No Results Found'
}
item_data = {
'html': 'The search query you entered did not return any results.'
}
context = RequestContext(request, {
'item': obj,
'item_data': item_data,