Skip to content

Commit

Permalink
OPEN-3126: Better handling of root URL views
Browse files Browse the repository at this point in the history
  • Loading branch information
thriuin committed Feb 9, 2024
1 parent f40c17f commit 84024fd
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
1 change: 1 addition & 0 deletions oc_search/settings-sample.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@
SEARCH_FR_HOSTNAME = ''
SEARCH_HOST_PATH = ''
SEARCH_LANG_USE_PATH = True
DEFAULT_SEARCH_TYPE = ''

# Active CDTS Version

Expand Down
4 changes: 3 additions & 1 deletion oc_search/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
urlpatterns += [
path('', DefaultView.as_view(), name="HomePage"),
path('search/', DefaultView.as_view(), name="HomePage"),
path('rechercher/', DefaultView.as_view(), name="HomePage"),
path('search/<str:lang>/', HomeView.as_view(), name="HomePage"),
path('search/<str:lang>/<str:search_type>/', SearchView.as_view(), name="SearchForm"),
path('rechercher/<str:lang>/<str:search_type>/', SearchView.as_view(), name="SearchForm"),
Expand All @@ -55,7 +56,8 @@
]
else:
urlpatterns += [
path(settings.SEARCH_HOST_PATH, DefaultView.as_view(), name="HomePage"),
path('', DefaultView.as_view(), name="HomePage"),
path(settings.SEARCH_HOST_PATH, HomeView.as_view(), name="HomePage"),
path(settings.SEARCH_HOST_PATH + '<str:search_type>/', SearchView.as_view(), name="SearchForm"),
path(settings.SEARCH_HOST_PATH + 'record/<str:search_type>/<str:record_id>', RecordView.as_view(),
name='RecordForm'),
Expand Down
22 changes: 20 additions & 2 deletions search/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -1039,6 +1039,24 @@ class DefaultView(View):

def get(self, request: HttpRequest):
if settings.SEARCH_LANG_USE_PATH:
return redirect('/search/{0}/'.format(request.LANGUAGE_CODE) )
if request.LANGUAGE_CODE == 'fr':
if settings.DEFAULT_SEARCH_TYPE:
return redirect(f'/rechecher/fr/{settings.DEFAULT_SEARCH_TYPE}')
else:
return redirect('/rechecher/fr/')
else:
if settings.DEFAULT_SEARCH_TYPE:
return redirect(f'/search/{request.LANGUAGE_CODE}/{settings.DEFAULT_SEARCH_TYPE}/')
else:
return redirect('/search/{0}/'.format(request.LANGUAGE_CODE) )
else:
return redirect('/search/')
if request.LANGUAGE_CODE == 'fr':
if settings.DEFAULT_SEARCH_TYPE:
return redirect(f'/rechercher/{settings.DEFAULT_SEARCH_TYPE}/')
else:
return redirect('/rechercher/')
else:
if settings.DEFAULT_SEARCH_TYPE:
return redirect(f'/search/{settings.DEFAULT_SEARCH_TYPE}/')
else:
return redirect('/search/')

0 comments on commit 84024fd

Please sign in to comment.