nansencenter / django-geo-spaas-adas-viewer

Web GUI for searching ADAS
GNU Lesser General Public License v3.0
0 stars 1 forks source link

URLs are configured incorectly #10

Closed akorosov closed 4 years ago

akorosov commented 4 years ago

If url(r'', ... is specififed in urls.py then any URL after / will be accepted: '/adas', '/geometry', '/css', etc. That causes problems when adas viewer is on the root url. It should be path('', or re_path(r'^$', (since url is soon deprecated).

akorosov commented 4 years ago

Tests should be updated accordingly to check that only root url is working, not '/adas' like it is now.

akorosov commented 4 years ago

It is better to add geomtery to urls here as well. To make it self sufficient.

akorosov commented 4 years ago

It is actually better not to add geometry.

Django URLs to views should be defined only in the apps where the views are defined. So get_geometry_geojson is defined in geospaas.base_viewer.views, therefore the only place where a URL for it is defined is also in geospaas.base_viewer.urls.

The reason is that we also define url namespace which is used in templates. So in geospaas.base_viewer.urls we define app_name='base_viewer' and path(..., name='geometry_geojson'). Then it can be accessed from template using namespace: {% url 'base_viewer:geometry_geojson' %}.

In the tests and web-apps, however, paths both to geospaas.base_viewer and geospaas_adas_viewer should be given. And the order plays important role! Because both geospaas.base_viewer.urls and geospaas_adas_viewer.urls have empty path ('').

In this case:

urlpatterns = [
    path('', include('geospaas_adas_viewer.urls')),
    path('', include('geospaas.base_viewer.urls')),
]

AdasIndexView is used on root URL (host:port/) and get_geometry_geojson will be used on host:port/geometry.

If the order is swapped, then AdasIndexView will not be used, but the IndexView will be used istead.

@aperrin66 , that is also good to remember for configuration of URLs in deployment.

aperrin66 commented 4 years ago

This looks much cleaner indeed