Browse Source

A single search result ends in a redirect to the page

master
Dirk Alders 1 month ago
parent
commit
a6277fc1e2
1 changed files with 12 additions and 9 deletions
  1. 12
    9
      pages/views.py

+ 12
- 9
pages/views.py View File

270
     if sr is None:
270
     if sr is None:
271
         django_messages.error(request, _('Invalid search pattern: %s') % repr(search_txt))
271
         django_messages.error(request, _('Invalid search pattern: %s') % repr(search_txt))
272
         sr = []
272
         sr = []
273
-    pl = page_list([PikiPage.objects.get(rel_path=rel_path) for rel_path in set(sr)])
274
-    #
275
-    context_adaption(
276
-        context,
277
-        request,
278
-        title=_("Searchresults"),
279
-        page_content=mycreole.render_simple(pl.creole_list())
280
-    )
281
-    return render(request, 'pages/page.html', context=context)
273
+    if len(sr) == 1:
274
+        return HttpResponseRedirect(url_page(sr[0]))
275
+    else:
276
+        pl = page_list([PikiPage.objects.get(rel_path=rel_path) for rel_path in set(sr)])
277
+        #
278
+        context_adaption(
279
+            context,
280
+            request,
281
+            title=_("Searchresults"),
282
+            page_content=mycreole.render_simple(pl.creole_list())
283
+        )
284
+        return render(request, 'pages/page.html', context=context)
282
 
285
 
283
 
286
 
284
 def helpview(request, page='main'):
287
 def helpview(request, page='main'):

Loading…
Cancel
Save