def search(request): if request.GET['q']: name="All Sections" section="all" query=request.GET['q'] if 'section' in request.GET: section=request.GET['section'] if section=="all": results=watson.search(query) else: sec=[] model=get_model(section) name=get_name(section) sec.append(model) results=watson.search(query,models=tuple(sec)) else: results=watson.search(query) else: return HttpResponseRedirect(reverse('home')) length=len(results) paginator = Paginator(results,10) page = request.GET.get('page') try: obj=paginator.page(page) except: obj=paginator.page(1) context = {'name':name,'obj':obj,'section':section,'length':length,'range':range(1,obj.paginator.num_pages+1),'query':query} return render(request,'search.html',context)
def search(request): if request.GET['q']: name="All Sections" section="all" query=request.GET['q'] if 'section' in request.GET: section=request.GET['section'] if section=="all": results=watson.search(query) elif section=="tl": name="Teach and Learn" results=watson.search(query,models=tuple([Tutorial,EducationalResource,Wiki,Snippet])) elif section=="forum": name="Forum" results=watson.search(query,models=tuple([Announcement,Event,Blog,News])) else: sec=[] model=get_model(section) name=get_name(section) sec.append(model) results=watson.search(query,models=tuple(sec)) else: results=watson.search(query) else: return HttpResponseRedirect(reverse('home')) length=len(results) paginator = Paginator(results,15) page = request.GET.get('page') try: obj=paginator.page(page) except: obj=paginator.page(1) context = {'name':name,'obj':obj,'section':section,'length':length,'range':range(1,obj.paginator.num_pages+1),'query':query} return render(request,'search.html',context)
def search_idb(request): query = request.GET.get('q', '') #returns string of args from search q_list = [] search_results = watson.search(query) #AND search q_list.append(search_results) arg_list = query.split() #split on whitespace to get search terms if len(arg_list) > 1: #OR search for each individual term for search_term in arg_list: more_results = (watson.search(search_term)) q_list.append(more_results) list_of_models = [] for item in q_list: for result in item: if result not in list_of_models: list_of_models.append(result) count = len(list_of_models) context = RequestContext(request, {'query': query, 'count': count,'results': search_results, 'list': list_of_models}) t = loader.get_template('watson/search.html') return HttpResponse(t.render(context))
def search(request): if request.GET['q']: name = "All Sections" section = "all" query = request.GET['q'] if 'section' in request.GET: section = request.GET['section'] if section == "all": results = watson.search(query) else: sec = [] model = get_model(section) name = get_name(section) sec.append(model) results = watson.search(query, models=tuple(sec)) else: results = watson.search(query) else: return HttpResponseRedirect(reverse('home')) length = len(results) paginator = Paginator(results, 10) page = request.GET.get('page') try: obj = paginator.page(page) except: obj = paginator.page(1) context = { 'name': name, 'obj': obj, 'section': section, 'length': length, 'range': range(1, obj.paginator.num_pages + 1), 'query': query } return render(request, 'search.html', context)
def testSearchEmailParts(self): with watson.update_index(): self.test11.content = "*****@*****.**" self.test11.save() self.assertEqual(watson.search("fooo").count(), 1) self.assertEqual(watson.search("baar.com").count(), 1) self.assertEqual(watson.search("*****@*****.**").count(), 1)
def get_search_results(query, slug): if slug not in SEARCH_PARAMS: raise Http404('Invalid search slug.') models = SEARCH_PARAMS[slug] object_list = list(watson.search(query, models=models)) # Perform the search with the rest of the models: if models: object_list += list(watson.search(query, exclude=models)) return object_list
def testBuildWatsonCommand(self): # Hack a change into the model using a bulk update, which doesn't send signals. WatsonTestModel1.objects.filter(id=self.test11.id).update(title="fooo") # Test that no update has happened. self.assertEqual(watson.search("fooo").count(), 0) # Run the rebuild command. call_command("buildwatson", verbosity=0) # Test that the update is now applies. self.assertEqual(watson.search("fooo").count(), 1)
def search(request): context = RequestContext(request) query = "" query_words = [] if ('q' in request.GET) and request.GET['q'].strip(): query = request.GET['q'] query_items = query.split() and_search = watson.search(query, ranking=True) for a in and_search: print(a.url) print(a) results = list(and_search) for item in query_items: or_search = list(watson.search(item, ranking=True)) for o in or_search: if not o in results: results.append(o) snippets = [] for i in range(0, len(results)): final_sentence = "" sentences = splitParagraph(results[i].content) for s in list(sentences): if(s.lower().find(query.lower()) != -1): sentences.remove(s) s = s.lower().replace(query.lower(), "<B class='search_term'>"+query.lower()+"</B>") final_sentence += " " + s break for q_item in query_items: for s in list(sentences): if(s.lower().find(query.lower()) != -1): sentences.remove(s) s = s.lower().replace(query.lower(), "<B class='search_term'>"+query.lower()+"</B>") final_sentence += " " + s break final_sentence += " " snippets.append(final_sentence) zipped = None if len(results) > 0: zipped = zip(results, snippets) length_results = len(results) return render_to_response('search.html', {"query": query, "length_results": length_results, "results": zipped}, context)
def testNestedUpdateInSkipContext(self): with watson.skip_index_update(): self.test21.title = "baar" self.test21.save() with watson.update_index(): self.test11.title = "fooo" self.test11.save() # We should get "fooo", but not "baar" self.assertEqual(watson.search("fooo").count(), 1) self.assertEqual(watson.search("baar").count(), 0)
def testUnpublishedModelsNotFound(self): # Make sure that there are four to find! self.assertEqual(watson.search("tItle Content Description").count(), 4) # Unpublish two objects. self.test11.is_published = False self.test11.save() self.test21.is_published = False self.test21.save() # This should return 4, but two of them are unpublished. self.assertEqual(watson.search("tItle Content Description").count(), 2)
def testBuildWatsonCommand(self): # This update won't take affect, because no search context is active. self.test11.title = "fooo" self.test11.save() # Test that no update has happened. self.assertEqual(watson.search("fooo").count(), 0) # Run the rebuild command. call_command("buildwatson", verbosity=0) # Test that the update is now applies. self.assertEqual(watson.search("fooo").count(), 1)
def testUpdateSearchIndex(self): # Update a model and make sure that the search results match. self.test11.title = "fooo" self.test11.save() # Test a search that should get one model. exact_search = watson.search("fooo") self.assertEqual(len(exact_search), 1) self.assertEqual(exact_search[0].title, "fooo") # Delete a model and make sure that the search results match. self.test11.delete() self.assertEqual(watson.search("fooo").count(), 0)
def search(request): context = RequestContext(request) query = "" query_words = [] if ('q' in request.GET) and request.GET['q'].strip(): query = request.GET['q'] query_words = query.split() and_results = watson.search(query, ranking=True) results = list(and_results) for wd in query_words: or_results = list(watson.search(wd, ranking=True)) for r in or_results: if not r in results: results.append(r) snippets = [] for i in range(0, len(results)): final_sentence = "" sentences = splitParagraph(results[i].content) #First highlight terms in sentences matching the phrase for s in list(sentences): if(s.lower().find(query.lower()) != -1): sentences.remove(s) s = s.lower().replace(query.lower(), "<B class='search_term'>"+query.lower()+"</B>") final_sentence += "..." + s break #Then highlight the separate words of a query separately for q_wd in query_words: for s in list(sentences): if (s.lower().find(q_wd.lower()) != -1): sentences.remove(s) s = s.lower().replace(q_wd.lower(), "<B class='search_term'>"+q_wd.lower()+"</B>") final_sentence += "..." + s break final_sentence += "..." snippets.append(final_sentence) zipped = None if len(results) > 0: zipped = zip(results, snippets) length_results = len(results) return render_to_response('mythos/search.html', {"query": query, "length_results": length_results, "results": zipped}, context)
def docs_buscador(request): import watson query = request.GET.get('q', '') resultados = [] if query: resultados = watson.search(query) return {'resultados': resultados, 'query': query}
def place_recommendations(self): import watson out = [] for i in xrange(len(self.data_objects)): out.append( watson.search(self.data_objects[i])[0].object) return out
def tag_search(request, klass, template): """Search subset of models with the given tag. Usess ``watson`` for the full-text search. """ # Generate a queryset from a model, manager or queryset: form = SearchForm(request.GET) page_no = pagination.get_page_no(request.GET) if form.is_valid(): queryset = get_queryset(klass) object_list = watson.search( form.cleaned_data['q'], models=(queryset, )) pagination_qs = '&%s' % urlencode({'q': form.cleaned_data['q']}) else: object_list = [] pagination_qs = '' page = pagination.get_page(object_list, page_no) page.object_list_top = [o.object for o in page.object_list_top] page.object_list_bottom = [o.object for o in page.object_list_bottom] context = { 'page': page, 'form': form, 'pagination_qs': pagination_qs, } return TemplateResponse(request, template, context)
def testSearchWithLeadingApostrophe(self): WatsonTestModel1.objects.create( title = "title model1 instance12", content = "'content model1 instance13", description = "description model1 instance13", ) self.assertTrue(watson.search("'content").exists()) # Some database engines ignore leading apostrophes, some count them.
def testSearchWithApostrophe(self): WatsonTestModel1.objects.create( title = "title model1 instance12", content = "content model1 instance13 d'Argent", description = "description model1 instance13", ) self.assertEqual(watson.search("d'Argent").count(), 1)
def testSearchWithApostrophe(self): WatsonTestModel1.objects.create( title="title model1 instance12", content="content model1 instance13 d'Argent", description="description model1 instance13", ) self.assertEqual(watson.search("d'Argent").count(), 1)
def testSearchWithAccent(self): WatsonTestModel1.objects.create( title="title model1 instance12", content="content model1 instance13 café", description="description model1 instance13", ) self.assertEqual(watson.search("café").count(), 1)
def testSearchWithAccent(self): WatsonTestModel1.objects.create( title = "title model1 instance12", content = "content model1 instance13 café", description = "description model1 instance13", ) self.assertEqual(watson.search("café").count(), 1)
def search(user_id, search_term, offset=0, limit=10): """Offload the expensive part of search to avoid blocking the web interface""" email_subquery = models.Email.objects.filter( flags=F("flags").bitand(~models.Email.flags.deleted), inbox__flags=F("inbox__flags").bitand(~models.Inbox.flags.deleted), inbox__user_id=user_id, ) inbox_subquery = models.Inbox.objects.filter( flags=F("flags").bitand(~models.Inbox.flags.deleted), user_id=user_id) user = get_user_model().objects.get(id=user_id) search_qs = watson.search(search_term, models=(email_subquery, inbox_subquery)) limit = offset + limit results = { "emails": list( search_qs.filter(content_type__model="email").values_list( "id", flat=True)[offset:limit]), "inboxes": list( search_qs.filter(content_type__model="inbox").values_list( "id", flat=True)[offset:limit]), } key = "{0}-{1}".format(user.username, search_term) key = urllib.quote(key) cache.set(key, results) return results
def testCanOverridePublication(self): # Unpublish two objects. with watson.update_index(): self.test11.is_published = False self.test11.save() # This should still return 4, since we're overriding the publication. self.assertEqual(watson.search("tItle Content Description", models=(WatsonTestModel2, WatsonTestModel1._base_manager.all(),)).count(), 4)
def get_context_data(self, **kwargs): context = super(SearchView, self).get_context_data(**kwargs) kwargs = self.request.GET query = kwargs.get("q", "") pacotes = watson.search(query) context["object_list"] = [i.object for i in pacotes] context["query"] = query return context
def testExcludedModelQuerySet(self): # Test a search that should get all models. self.assertEqual(watson.search("TITLE", exclude=(WatsonTestModel1.objects.filter(title__icontains="FOOO"), WatsonTestModel2.objects.filter(title__icontains="FOOO"),)).count(), 4) # Test a search that should get two models. self.assertEqual(watson.search("MODEL1", exclude=(WatsonTestModel1.objects.filter( title__icontains = "INSTANCE21", description__icontains = "INSTANCE22", ),)).count(), 2) self.assertEqual(watson.search("MODEL2", exclude=(WatsonTestModel2.objects.filter( title__icontains = "INSTANCE11", description__icontains = "INSTANCE12", ),)).count(), 2) # Test a search that should get one model. self.assertEqual(watson.search("INSTANCE11", exclude=(WatsonTestModel1.objects.filter( title__icontains = "MODEL2", ),)).count(), 1) self.assertEqual(watson.search("INSTANCE21", exclude=(WatsonTestModel2.objects.filter( title__icontains = "MODEL1", ),)).count(), 1) # Test a search that should get no models. self.assertEqual(watson.search("INSTANCE11", exclude=(WatsonTestModel1.objects.filter( title__icontains = "MODEL1", ),)).count(), 0) self.assertEqual(watson.search("INSTANCE21", exclude=(WatsonTestModel2.objects.filter( title__icontains = "MODEL2", ),)).count(), 0)
def get_queryset(self): """Returns the initial queryset.""" # return watson.search(self.query, models=self.get_models(), # exclude=self.get_exclude()) search_results = watson.search(self.query) if search_results: search_results = search_results.prefetch_related("object") return search_results
def post(self, *args, **kwargs): search_query = self.request.POST.get('search','') print search_query search_results = watson.search(search_query) return self.render_to_response({'form': self.form_class(self.request.POST), 'results': search_results})
def search(): # watson.register(Image) # watson.register(ImageText) # print watson.get_registered_models() for item in watson.search('irish'): print item.object.title
def testSearchWithLeadingApostrophe(self): WatsonTestModel1.objects.create( title="title model1 instance12", content="'content model1 instance13", description="description model1 instance13", ) self.assertTrue( watson.search("'content").exists() ) # Some database engines ignore leading apostrophes, some count them.
def testSearchIndexUpdateAbandonedOnError(self): try: with watson.update_index(): self.test11.title = "fooo" self.test11.save() raise Exception("Foo") except: pass # Test a search that should get not model. self.assertEqual(watson.search("fooo").count(), 0)
def search(request): """ Display Product search results """ query = request.GET.get('term', '') results = watson.search(query) return render(request, 'search_results.html', { 'results': results, 'search_term': query })
def testCanOverridePublication(self): # Unpublish two objects. self.test11.is_published = False self.test11.save() # This should still return 4, since we're overriding the publication. self.assertEqual( watson.search("tItle Content Description", models=( WatsonTestModel2, WatsonTestModel1._base_manager.all(), )).count(), 4)
def search_videos(request): query = None search_results = None if request.method == 'GET': query = request.GET.get('query', None) token = request.GET.get('token', None) try: page = request.GET.get('page', 1) except PageNotAnInteger: page = 1 if query: videos = watson.search(query, models=(Video, )) if len(videos) < MINIMUM_TOTAL_RESULTS: # Attempt to meet MINIMUM_TOTAL_RESULTS by querying YouTube. if not token: count = MINIMUM_TOTAL_RESULTS - len(videos) yt, token = find_video_by_keyword(query, results=count) else: yt, token = find_video_by_keyword(query, results=RESULTS_PER_PAGE, next_page_token=token) # Update search, since find_video_by_keyword # stores a copy in our db. videos = watson.search(query, models=(Video, )) # Paginate results. video_paginator = Paginator(videos, RESULTS_PER_PAGE, request=request) search_results = video_paginator.page(page) return render_to_response('search/videos.html', { 'query': query, 'token': token, 'search_results': search_results, }, context_instance=RequestContext(request))
def get_queryset(self): """ Return the list of items for this view. The return value must be an iterable and may be an instance of `QuerySet` in which case `QuerySet` specific behavior will be enabled. """ query_string = self.request.GET.get('q') if query_string: result = watson.search(query_string, models=self.get_models()) return result # return empty query set return models.Entry.objects.none()
def testKitchenSink(self): """For sanity, let's just test everything together in one giant search of doom!""" self.assertEqual(watson.search( "INSTANCE11", models = ( WatsonTestModel1.objects.filter(title__icontains="INSTANCE11"), WatsonTestModel2.objects.filter(title__icontains="TITLE"), ), exclude = ( WatsonTestModel1.objects.filter(title__icontains="MODEL2"), WatsonTestModel2.objects.filter(title__icontains="MODEL1"), ) ).get().title, "title model1 instance11")
def searchLayers(request): querystring = request.GET.get('q', None) print querystring search_results = watson.search(querystring) resultobj = [] counter = 1 for result in search_results: resultobj.append({"subject": result.object.subject, "keyid":result.object.issue.keyid + "+" + result.object.keyid}) if counter > 10: break counter +=1 return HttpResponse(json.dumps(resultobj), content_type="application/json")
def search_parents(request, term=None, exclude_resource=None): if term is not None: _term = term else: _term = request.GET.get("q") if _term is None: search_results = [] # print 'search_parents _term: ', _term _my_search_results = watson.search(_term, models=(Resources.objects.filter(author=request.user),), exclude=(Resources.objects.filter(~Q(author=request.user),is_home=True),Resources.objects.filter(id=exclude_resource))) # print 'search_parents my_search_results', _my_search_results my_search_results = [] if len(_my_search_results) > 0: for sr in _my_search_results: my_search_results.append({'object_id_int':sr.object_id_int, 'object':sr.object}) # my_search_results = my_search_results.values('object_id_int','object') # Search everything else _other_search_results = watson.search(_term, exclude=(Resources.objects.filter(~Q(author=request.user),is_home=True),Resources.objects.filter(id=exclude_resource),Resources.objects.filter(id__in=[s['object_id_int'] for s in my_search_results]))) # Exclude alreayd searched else: _other_search_results = watson.search(_term, exclude=(Resources.objects.filter(~Q(author=request.user),is_home=True),Resources.objects.filter(id=exclude_resource))) # print 'search_parents _other_search_results', _other_search_results other_search_results = [] if len(_other_search_results) > 0: for sr in _other_search_results: other_search_results.append({'object_id_int':sr.object_id_int, 'object':sr.object}) # other_search_results = other_search_results.values('object_id_int','object') search_results = my_search_results + other_search_results # print 'autocomplete_search search_results: ', search_results return {'resource_list':search_results}
def search(request): context = {} q = "" try: if request.POST: q = request.POST['q'] else: q = request.GET['q'] except MultiValueDictKeyError: pass context['query'] = q context['search_entry_list'] = watson.search(q) return render(request, 'search.html', context)
def search(request): search_results = '' if ('q' in request.GET) and request.GET['q'].strip(): query_string = request.GET['q'] search_results = watson.search(query_string) return render_to_response('static/search.html', {'search_results': search_results}, context_instance=RequestContext(request)) return render_to_response('static/search.html', context_instance=RequestContext(request))
def questions(request): if request.GET: search_form = SearchForm(request.GET) if search_form.is_valid(): results = watson.search(search_form.cleaned_data['q']) return render(request, "question/question_meta_list.html", { 'search_form': search_form, 'results': results}) return render(request, "question/question_meta_list.html", { 'search_form': SearchForm(), 'qms': QuestionMeta.objects.filter(status=QuestionMeta.PUBLISHED)})
def search(request): q = request.GET.get('q', '') offset = request.GET.get('offset', 0) limit = request.GET.get('limit', 20) next_offset = offset + limit previous_offset = offset - limit watson_results = watson.search(q) show_only_post_results = [] for result in watson_results: if isinstance(result.object, Image): post = result.object.post elif isinstance(result.object, Post): post = result.object elif isinstance(result.object, Credit): post = result.object.post show_only_post_results.append(post) objects = [ this_post.to_json() for this_post in list(set(show_only_post_results)) ] paginated_objects = objects[offset:offset + limit] has_next_page = len(objects[next_offset:]) > 0 has_previous_page = previous_offset >= 0 next_page = None previous_page = None if has_next_page: next_page = reverse('search', query_kwargs={ 'limit': limit, 'offset': next_offset, 'q': q }) if has_previous_page: previous_page = reverse('search', query_kwargs={ 'limit': limit, 'offset': previous_offset, 'q': q }) meta = { 'count': len(objects), 'next': next_page, 'previous': previous_page, 'keyword': q } response = {'meta': meta, 'objects': paginated_objects} return HttpResponse(json.dumps(response), content_type='application/json')
def questions(request): if request.GET: search_form = SearchForm(request.GET) if search_form.is_valid(): results = watson.search(search_form.cleaned_data['q']) return render(request, "question/question_meta_list.html", { 'search_form': search_form, 'results': results }) return render( request, "question/question_meta_list.html", { 'search_form': SearchForm(), 'qms': QuestionMeta.objects.filter(status=QuestionMeta.PUBLISHED) })
def searchLayers(request): querystring = request.GET.get('q', None) print querystring search_results = watson.search(querystring) resultobj = [] counter = 1 for result in search_results: resultobj.append({ "subject": result.object.subject, "keyid": result.object.issue.keyid + "+" + result.object.keyid }) if counter > 10: break counter += 1 return HttpResponse(json.dumps(resultobj), content_type="application/json")
def search(request): query = request.GET.get('q', '') scholars = [] if query: results = watson.search(query) for result in results: if isinstance(result.object, McUser): if result.object not in scholars: scholars.append(result.object) elif (isinstance(result.object, Degree) or isinstance(result.object, Experience) or isinstance(result.object, StudyAbroad)): if result.object.user not in scholars: scholars.append(result.object.user) context = {'scholars': scholars} # go straight to scholar if only one result if len(scholars) == 1: return redirect('profile', scholars[0].get_link_name()) return render(request, 'core/scholars.html', context)
def testBuildWatsonForModelCommand(self): # Hack a change into the model using a bulk update, which doesn't send signals. WatsonTestModel1.objects.filter(id=self.test11.id).update(title="fooo1_selective") WatsonTestModel2.objects.filter(id=self.test21.id).update(title="fooo2_selective") # Test that no update has happened. self.assertEqual(watson.search("fooo1_selective").count(), 0) self.assertEqual(watson.search("fooo2_selective").count(), 0) # Run the rebuild command. call_command("buildwatson", "WatsonTestModel1", verbosity=0) # Test that the update is now applied to selected model. self.assertEqual(watson.search("fooo1_selective").count(), 1) self.assertEqual(watson.search("fooo2_selective").count(), 0) call_command("buildwatson", "WatsonTestModel1", "WatsonTestModel2", verbosity=0) # Test that the update is now applied to multiple selected models. self.assertEqual(watson.search("fooo1_selective").count(), 1) self.assertEqual(watson.search("fooo2_selective").count(), 1)
def search_users(request): query = None search_results = None if request.method == 'GET': query = request.GET.get('query', None) try: page = request.GET.get('page', 1) except PageNotAnInteger: page = 1 if query: users = watson.search(query, models=(UserProfile, )) user_paginator = Paginator(users, 6, request=request) search_results = user_paginator.page(page) return render_to_response('search/users.html', { 'query': query, 'search_results': search_results, }, context_instance=RequestContext(request))
def get_q(self): # Get filters as a q object q = self._get_filters_from_queryset() model = self.queryset.model if self.query_string is not None: could_search = False for m in watson.get_registered_models(): if issubclass(m, model): could_search = True if could_search: query_subset = () for m in watson.get_registered_models(): query_subset += (m.objects.filter(q), ) return watson.search(self.query_string, models=query_subset) #return watson.search(self.query_string) return model.objects.none()
def search_conversations(request): query = None search_results = None if request.method == 'GET': query = request.GET.get('query', None) try: page = request.GET.get('page', 1) except PageNotAnInteger: page = 1 if query: conversations = watson.search(query, models=(MPTTComment, )) total = RESULTS_PER_PAGE - 1 convo_paginator = Paginator(conversations, total, request=request) search_results = convo_paginator.page(page) return render_to_response('search/conversations.html', { 'query': query, 'search_results': search_results, }, context_instance=RequestContext(request))
def simple_search(request): ip_addresses = [] dashes = [] query = [] tests = None findings = None products = None clean_query = '' cookie = False terms = '' form = SimpleSearchForm() if request.method == 'GET' and "query" in request.GET: form = SimpleSearchForm(request.GET) if form.is_valid(): cookie = True clean_query = form.cleaned_data['query'] tag_list = re.findall(r"[\w']+", clean_query) tags = Tag.objects.filter(name__in=tag_list) if request.user.is_staff: findings = watson.search(clean_query, models=(Finding, )) tests = watson.search(clean_query, models=(Test, )) products = watson.search(clean_query, models=(Product, )) tagged_findings = TaggedItem.objects.get_by_model( Finding, tags) tagged_tests = TaggedItem.objects.get_by_model(Test, tags) tagged_products = TaggedItem.objects.get_by_model( Product, tags) tagged_endpoints = TaggedItem.objects.get_by_model( Endpoint, tags) tagged_engagements = TaggedItem.objects.get_by_model( Engagement, tags) else: findings = watson.search( clean_query, models=(Finding.objects.filter( test__engagement__product__authorized_users__in=[ request.user ]), )) tests = watson.search( clean_query, models=(Test.objects.filter( engagement__product__authorized_users__in=[ request.user ]), )) products = watson.search( clean_query, models=(Product.objects.filter( authorized_users__in=[request.user]), )) tagged_findings = TaggedItem.objects.get_by_model( Finding.objects.filter( test__engagement__product__authorized_users__in=[ request.user ]), tags) tagged_tests = TaggedItem.objects.get_by_model( Test.objects.filter( engagement__product__authorized_users__in=[ request.user ]), tags) tagged_products = TaggedItem.objects.get_by_model( Product.objects.filter( authorized_users__in=[request.user]), tags) tagged_endpoints = TaggedItem.objects.get_by_model( Endpoint.objects.filter( product__authorized_users__in=[request.user]), tags) tagged_engagements = TaggedItem.objects.get_by_model( Engagement.objects.filter( product__authorized_users__in=[request.user]), tags) else: form = SimpleSearchForm() add_breadcrumb(title="Simple Search", top_level=True, request=request) response = render( request, 'dojo/simple_search.html', { 'clean_query': clean_query, 'tests': tests, 'findings': findings, 'products': products, 'tagged_tests': tagged_tests, 'tagged_findings': tagged_findings, 'tagged_products': tagged_products, 'tagged_endpoints': tagged_endpoints, 'tagged_engagements': tagged_engagements, 'name': 'Simple Search', 'metric': False, 'user': request.user, 'form': form }) if cookie: response.set_cookie("highlight", value=clean_query, max_age=None, expires=None, path='/', secure=True, httponly=False) else: response.delete_cookie("highlight", path='/') return response