Skip to content

Commit

Permalink
Making the "canonical" part of canonical file URLs configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
jvamvas committed Sep 28, 2015
1 parent f0f6d7b commit 19b7815
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 3 deletions.
11 changes: 10 additions & 1 deletion docs/installation.rst
Expand Up @@ -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
Expand Down
11 changes: 10 additions & 1 deletion docs/settings.rst
Expand Up @@ -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``
Defaults to ``False``


``FILER_CANONICAL_URL``
-----------------------

Defines the path element common to all canonical file URLs.

Defaults to ``'canonical/'``

3 changes: 3 additions & 0 deletions filer/settings.py
Expand Up @@ -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/')

6 changes: 6 additions & 0 deletions filer/tests/models.py
Expand Up @@ -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/'))

7 changes: 6 additions & 1 deletion 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<uploaded_at>[0-9]+)/(?P<file_id>[0-9]+)/$', views.canonical, name='canonical'),
url(
filer_settings.FILER_CANONICAL_URL + r'(?P<uploaded_at>[0-9]+)/(?P<file_id>[0-9]+)/$',
views.canonical,
name='canonical'
),
]
1 change: 1 addition & 0 deletions test_settings.py
Expand Up @@ -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):
Expand Down

0 comments on commit 19b7815

Please sign in to comment.