From 1c88510391dacfc70bd35e18b1acf96eb35958dc Mon Sep 17 00:00:00 2001 From: Sanjay B Date: Mon, 12 Aug 2013 16:39:48 +0530 Subject: [PATCH] hacky fix for search results error --- itf/app/models.py | 10 ++++++++-- itf/templates/search/search.html | 9 +++++---- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/itf/app/models.py b/itf/app/models.py index ae441cf..145a728 100755 --- a/itf/app/models.py +++ b/itf/app/models.py @@ -145,7 +145,10 @@ class ItfModel(models.Model): #Get the ModuleTab object associated with this object. def get_tab(self): modelextra = self.get_modelextra() - tab = ModuleTab.objects.filter(model=modelextra)[0] + if modelextra: + tab = ModuleTab.objects.filter(model=modelextra)[0] + else: + tab = ModuleTab.objects.all()[0] #FIXME!!! return tab @@ -182,7 +185,10 @@ class ItfModel(models.Model): except:#FIXME: ideally catch only MultipleObjectsReturned (figure out where to import that from :/ ) #FUCKING way ugly hack to get clashing model ctype names with django internal models working (get_real_ctypes simply checks, if there are multiple content objects with the same 'module_name', which one is_itf_model, and returns that). ctype = get_real_ctype(self.__class__._meta.module_name) # modelextra = ModelExtra.objects.filter(model=ctype)[0] - modelextra = ctype.modelextra_set.all()[0] + try: + modelextra = ctype.modelextra_set.all()[0] + except: + modelextra = None return modelextra ''' diff --git a/itf/templates/search/search.html b/itf/templates/search/search.html index 2b01f32..21f16da 100755 --- a/itf/templates/search/search.html +++ b/itf/templates/search/search.html @@ -33,16 +33,17 @@

YOUR RESULTS:

{% for result in page.object_list %} - {{ result.object.title }} - {{ result.text|truncatewords:60|markdown|safe }} + + + {{ result.object }} + {{ result.text|truncatewords:60|markdown|striptags }}

- + {% empty %}

No results found.

{% endfor %} - {% else %} {# Show some example queries to run, maybe query syntax, something else? #} {% endif %}