From e5dd857e870e02a27d6ad4ecd899cd7b2ef87e64 Mon Sep 17 00:00:00 2001 From: Oskar Hahn Date: Wed, 22 Aug 2018 06:22:28 +0200 Subject: [PATCH] New url schema --- CHANGELOG.rst | 10 ++++++- DEVELOPMENT.rst | 6 ++-- openslides/core/urls.py | 19 ++----------- openslides/old_urls.py | 37 +++++++++++++++++++++++++ openslides/urls.py | 40 ++++++++++++++++++++------- openslides/urls_apps.py | 13 +++++++++ tests/integration/users/test_views.py | 7 +++-- 7 files changed, 98 insertions(+), 34 deletions(-) create mode 100644 openslides/old_urls.py create mode 100644 openslides/urls_apps.py diff --git a/CHANGELOG.rst b/CHANGELOG.rst index ec57c0864..aa6b8d022 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -4,6 +4,14 @@ https://openslides.org/ +Version 3.0 (unreleased) +======================== + +Core: + - Change URL schema [#3798]. + - Update to channels2 + + Version 2.3 (unreleased) ======================== @@ -22,7 +30,7 @@ Motions: be edited [#3781]. - New config to show amendments also in motions table [#3792] - Core: +Core: - Python 3.4 is not supported anymore [#3777]. - Support Python 3.7 [#3786]. - Updated pdfMake to 0.1.37 [#3766]. diff --git a/DEVELOPMENT.rst b/DEVELOPMENT.rst index 696cc4613..8ccdd0de4 100644 --- a/DEVELOPMENT.rst +++ b/DEVELOPMENT.rst @@ -214,9 +214,6 @@ This is an example configuration for a single Daphne listen on port 8000:: server_name _; - location ~* ^/(?!ws|wss|webclient|core/servertime|core/version|users/whoami|users/login|users/logout|users/setpassword|motions/docxtemplate|agenda/docxtemplate|projector|real-projector|static|media|rest).*$ { - rewrite ^.*$ /static/templates/index.html; - } location ~* ^/projector.*$ { rewrite ^.*$ /static/templates/projector-container.html; } @@ -229,6 +226,9 @@ This is an example configuration for a single Daphne listen on port 8000:: location /static { alias /collected-static; } + location ~* ^/(?!ws|wss|media|rest|views).*$ { + rewrite ^.*$ /static/templates/index.html; + } location / { proxy_pass http://localhost:8000; diff --git a/openslides/core/urls.py b/openslides/core/urls.py index 826a18964..b087a5bbf 100644 --- a/openslides/core/urls.py +++ b/openslides/core/urls.py @@ -4,26 +4,11 @@ from . import views urlpatterns = [ - url(r'^core/servertime/$', + url(r'^servertime/$', views.ServerTime.as_view(), name='core_servertime'), - url(r'^core/version/$', + url(r'^version/$', views.VersionView.as_view(), name='core_version'), - - url(r'^webclient/(?Psite|projector)/$', - views.WebclientJavaScriptView.as_view(), - name='core_webclient_javascript'), - - # View for the projectors are handled by angular. - url(r'^projector/(\d+)/$', views.ProjectorView.as_view()), - - # Original view without resolutioncontrol for the projectors are handled by angular. - url(r'^real-projector/(\d+)/$', views.RealProjectorView.as_view()), - - # Main entry point for all angular pages. - # Has to be the last entry in the urls.py - url(r'^.*$', views.IndexView.as_view(), name="index"), - ] diff --git a/openslides/old_urls.py b/openslides/old_urls.py new file mode 100644 index 000000000..428e0347b --- /dev/null +++ b/openslides/old_urls.py @@ -0,0 +1,37 @@ +from django.conf import settings +from django.conf.urls import include, url +from django.contrib.staticfiles.urls import urlpatterns +from django.views.generic import RedirectView + +from openslides.core import views as core_views +from openslides.mediafiles.views import protected_serve +from openslides.utils.plugins import get_all_plugin_urlpatterns +from openslides.utils.rest_api import router + + +urlpatterns += get_all_plugin_urlpatterns() + +urlpatterns += [ + url(r'^%s(?P.*)$' % settings.MEDIA_URL.lstrip('/'), protected_serve, {'document_root': settings.MEDIA_ROOT}), + url(r'^(?P.*[^/])$', RedirectView.as_view(url='/%(url)s/', permanent=True)), + url(r'^rest/', include(router.urls)), + url(r'^agenda/', include('openslides.agenda.urls')), + url(r'^motions/', include('openslides.motions.urls')), + url(r'^users/', include('openslides.users.urls')), + url(r'^core/', include('openslides.core.urls')), + # The old angular webclient + # TODO: Change me or at least my comment + url(r'^webclient/(?Psite|projector)/$', + core_views.WebclientJavaScriptView.as_view(), + name='core_webclient_javascript'), + + # View for the projectors are handled by angular. + url(r'^projector/(\d+)/$', core_views.ProjectorView.as_view()), + + # Original view without resolutioncontrol for the projectors are handled by angular. + url(r'^real-projector/(\d+)/$', core_views.RealProjectorView.as_view()), + + # Main entry point for all angular pages. + # Has to be the last entry in the urls.py + url(r'^.*$', core_views.IndexView.as_view(), name="index"), +] diff --git a/openslides/urls.py b/openslides/urls.py index 0dd87defd..d3da9d09b 100644 --- a/openslides/urls.py +++ b/openslides/urls.py @@ -1,23 +1,43 @@ from django.conf import settings from django.conf.urls import include, url +from django.contrib.staticfiles.urls import urlpatterns from django.views.generic import RedirectView from openslides.mediafiles.views import protected_serve -from openslides.utils.plugins import get_all_plugin_urlpatterns from openslides.utils.rest_api import router +from .core import views as core_views -urlpatterns = get_all_plugin_urlpatterns() + +# Urls for /static/ are already in urlpatterns urlpatterns += [ + # URLs for /media/ url(r'^%s(?P.*)$' % settings.MEDIA_URL.lstrip('/'), protected_serve, {'document_root': settings.MEDIA_ROOT}), - url(r'^(?P.*[^/])$', RedirectView.as_view(url='/%(url)s/', permanent=True)), - url(r'^rest/', include(router.urls)), - url(r'^agenda/', include('openslides.agenda.urls')), - url(r'^motions/', include('openslides.motions.urls')), - url(r'^users/', include('openslides.users.urls')), - # The urls.py of the core app has to be the last entry. It contains the - # main entry points for OpenSlides' browser clients. - url(r'^', include('openslides.core.urls')), + # When a url without a leading slash is requested, redirect to the url with + # the slash. This line has to be after static and media files. + url(r'^(?P.*[^/])$', RedirectView.as_view(url='/%(url)s/', permanent=True)), + + # URLs for the rest system + url(r'^rest/', include(router.urls)), + + # Other urls defined by modules and plugins + url(r'^apps/', include('openslides.urls_apps')), + + # The old angular webclient + # TODO: Change me or at least my comment + url(r'^webclient/(?Psite|projector)/$', + core_views.WebclientJavaScriptView.as_view(), + name='core_webclient_javascript'), + + # View for the projectors are handled by angular. + url(r'^projector/(\d+)/$', core_views.ProjectorView.as_view()), + + # Original view without resolutioncontrol for the projectors are handled by angular. + url(r'^real-projector/(\d+)/$', core_views.RealProjectorView.as_view()), + + # Main entry point for all angular pages. + # Has to be the last entry in the urls.py + url(r'^.*$', core_views.IndexView.as_view(), name="index"), ] diff --git a/openslides/urls_apps.py b/openslides/urls_apps.py new file mode 100644 index 000000000..8ef1ef6ab --- /dev/null +++ b/openslides/urls_apps.py @@ -0,0 +1,13 @@ +from django.conf.urls import include, url + +from openslides.utils.plugins import get_all_plugin_urlpatterns + + +urlpatterns = get_all_plugin_urlpatterns() + +urlpatterns += [ + url(r'^core/', include('openslides.core.urls')), + url(r'^agenda/', include('openslides.agenda.urls')), + url(r'^motions/', include('openslides.motions.urls')), + url(r'^users/', include('openslides.users.urls')), +] diff --git a/tests/integration/users/test_views.py b/tests/integration/users/test_views.py index 8e006aa7a..c70a62ae9 100644 --- a/tests/integration/users/test_views.py +++ b/tests/integration/users/test_views.py @@ -1,12 +1,13 @@ import json +from django.urls import reverse from rest_framework.test import APIClient from openslides.utils.test import TestCase class TestWhoAmIView(TestCase): - url = '/users/whoami/' + url = reverse('user_whoami') def test_get_anonymous(self): response = self.client.get(self.url) @@ -32,7 +33,7 @@ class TestWhoAmIView(TestCase): class TestUserLogoutView(TestCase): - url = '/users/logout/' + url = reverse('user_logout') def test_get(self): response = self.client.get(self.url) @@ -55,7 +56,7 @@ class TestUserLogoutView(TestCase): class TestUserLoginView(TestCase): - url = '/users/login/' + url = reverse('user_login') def setUp(self): self.client = APIClient()