From 19b7815a937d87e2a518901128404efd80822005 Mon Sep 17 00:00:00 2001 From: Jannis Vamvas Date: Mon, 28 Sep 2015 12:37:29 +0200 Subject: [PATCH] Making the "canonical" part of canonical file URLs configurable --- docs/installation.rst | 11 ++++++++++- docs/settings.rst | 11 ++++++++++- filer/settings.py | 3 +++ filer/tests/models.py | 6 ++++++ filer/urls.py | 7 ++++++- test_settings.py | 1 + 6 files changed, 36 insertions(+), 3 deletions(-) diff --git a/docs/installation.rst b/docs/installation.rst index 280d81a8d..f140a6a48 100644 --- a/docs/installation.rst +++ b/docs/installation.rst @@ -126,7 +126,16 @@ Contrary to the file's actual URL, the canonical URL does not change if you uplo Thus, you can safely share the canonical URL. As long as the file exists, people will be redirected to its latest version. -The canonical URL is displayed in the "advanced" panel on the file's admin page. +The canonical URL is displayed in the "advanced" panel on the file's admin page. It has the form:: + + /filer/canonical/1442488644/12/ + +The "filer" part of the URL is configured in the project's URLconf as described above. The "canonical" part can be +changed with the setting ``FILER_CANONICAL_URL``, which defaults to ``'canonical/'``. Example:: + + # settings.py + + FILER_CANONICAL_URL = 'sharing/' debugging and logging diff --git a/docs/settings.rst b/docs/settings.rst index c884a3cf9..0ef5bdea3 100644 --- a/docs/settings.rst +++ b/docs/settings.rst @@ -143,4 +143,13 @@ Defaults to ``False`` Defines the dotted path to a custom Image model; please include the model name. Example: 'my.app.models.CustomImage' -Defaults to ``False`` \ No newline at end of file +Defaults to ``False`` + + +``FILER_CANONICAL_URL`` +----------------------- + +Defines the path element common to all canonical file URLs. + +Defaults to ``'canonical/'`` + diff --git a/filer/settings.py b/filer/settings.py index 88eba86c2..87f9f401c 100644 --- a/filer/settings.py +++ b/filer/settings.py @@ -219,3 +219,6 @@ def update_server_settings(settings, defaults, s, t): FILER_PRIVATEMEDIA_THUMBNAIL_SERVER = load_object(FILER_SERVERS['private']['thumbnails']['ENGINE'])(**FILER_SERVERS['private']['thumbnails']['OPTIONS']) FILER_DUMP_PAYLOAD = getattr(settings, 'FILER_DUMP_PAYLOAD', False) # Whether the filer shall dump the files payload + +FILER_CANONICAL_URL = getattr(settings, 'FILER_CANONICAL_URL', 'canonical/') + diff --git a/filer/tests/models.py b/filer/tests/models.py index e5483af30..b5fcdfe41 100644 --- a/filer/tests/models.py +++ b/filer/tests/models.py @@ -261,3 +261,9 @@ def test_canonical_url(self): image.save() os.remove(filename_2) + def test_canonical_url_settings(self): + image = self.create_filer_image() + image.save() + canonical = image.canonical_url + self.assertTrue(canonical.startswith('/filer/test-path/')) + diff --git a/filer/urls.py b/filer/urls.py index 0f326197a..d84fab8f3 100644 --- a/filer/urls.py +++ b/filer/urls.py @@ -1,8 +1,13 @@ #-*- coding: utf-8 -*- from django.conf.urls import url +from filer import settings as filer_settings from filer import views urlpatterns = [ - url(r'canonical/(?P[0-9]+)/(?P[0-9]+)/$', views.canonical, name='canonical'), + url( + filer_settings.FILER_CANONICAL_URL + r'(?P[0-9]+)/(?P[0-9]+)/$', + views.canonical, + name='canonical' + ), ] diff --git a/test_settings.py b/test_settings.py index 13238d1d6..8da9194be 100644 --- a/test_settings.py +++ b/test_settings.py @@ -54,6 +54,7 @@ 'FILE_UPLOAD_TEMP_DIR': mkdtemp(), 'FILER_IMAGE_MODEL': False, 'TEMPLATE_DIRS': (os.path.join(BASE_DIR, 'django-filer', 'filer', 'test_utils', 'templates'),), + 'FILER_CANONICAL_URL': 'test-path/', } if os.environ.get('CUSTOM_IMAGE', False):