Merge pull request #429 from nephila/feature/urlconf_settings
Add apphook config urlconf to settings
This commit is contained in:
commit
ae4b930963
6 changed files with 85 additions and 2 deletions
|
@ -14,7 +14,7 @@ from .settings import get_setting
|
|||
@apphook_pool.register
|
||||
class BlogApp(AutoCMSAppMixin, CMSConfigApp):
|
||||
name = _('Blog')
|
||||
_urls = ['djangocms_blog.urls']
|
||||
_urls = [get_setting('URLCONF')]
|
||||
app_name = 'djangocms_blog'
|
||||
app_config = BlogConfig
|
||||
_menus = [BlogCategoryMenu]
|
||||
|
@ -30,9 +30,12 @@ class BlogApp(AutoCMSAppMixin, CMSConfigApp):
|
|||
},
|
||||
}
|
||||
|
||||
def get_urls(self, page=None, language=None, **kwargs):
|
||||
return [get_setting('URLCONF')]
|
||||
|
||||
@property
|
||||
def urls(self):
|
||||
return self._urls
|
||||
return self.get_urls()
|
||||
|
||||
@property
|
||||
def menus(self):
|
||||
|
|
|
@ -53,6 +53,7 @@ def get_setting(name):
|
|||
'upscale': False
|
||||
}),
|
||||
|
||||
'BLOG_URLCONF': getattr(settings, 'BLOG_URLCONF', 'djangocms_blog.urls'),
|
||||
'BLOG_PAGINATION': getattr(settings, 'BLOG_PAGINATION', 10),
|
||||
'BLOG_LATEST_POSTS': getattr(settings, 'BLOG_LATEST_POSTS', 5),
|
||||
'BLOG_POSTS_LIST_TRUNCWORDS_COUNT': getattr(
|
||||
|
|
|
@ -31,6 +31,22 @@ Notice that the last permalink type is no longer present.
|
|||
Then, pick any of the three remaining permalink types in the layout section of the apphooks config
|
||||
linked ot the home page (see http://yoursite.com/admin/djangocms_blog/blogconfig/).'
|
||||
|
||||
.. _blog-custom-urlconf:
|
||||
|
||||
************************
|
||||
Provide a custom URLConf
|
||||
************************
|
||||
|
||||
It's possible to completely customize the urlconf by setting ``BLOG_URLCONF`` to the dotted path of
|
||||
the new urlconf.
|
||||
|
||||
Example::
|
||||
|
||||
BLOG_URLCONF = 'my_project.blog_urls.py'
|
||||
|
||||
The custom urlconf can be created by copying the existing urlconf in `djangocms_blog/urls.py`,
|
||||
saving it to a new file `my_project.blog_urls.py` and editing it according to the custom needs.
|
||||
|
||||
|
||||
.. _multisite:
|
||||
|
||||
|
|
|
@ -68,6 +68,7 @@ Global Settings
|
|||
* BLOG_AVAILABLE_PERMALINK_STYLES: Choices of permalinks styles;
|
||||
* BLOG_PERMALINK_URLS: URLConf corresponding to
|
||||
BLOG_AVAILABLE_PERMALINK_STYLES;
|
||||
* BLOG_URLCONF: Apphoo URLConf; (default: ``'djangocms_blog.urls'``);
|
||||
* BLOG_DEFAULT_OBJECT_NAME: Default name for Blog item (used in django CMS Wizard);
|
||||
* BLOG_AUTO_SETUP: Enable the blog **Auto setup** feature; (default: ``True``)
|
||||
* BLOG_AUTO_HOME_TITLE: Title of the home page created by **Auto setup**;
|
||||
|
|
45
tests/test_utils/blog_urls.py
Normal file
45
tests/test_utils/blog_urls.py
Normal file
|
@ -0,0 +1,45 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from __future__ import absolute_import, print_function, unicode_literals
|
||||
|
||||
from django.conf.urls import url
|
||||
|
||||
from djangocms_blog.feeds import FBInstantArticles, LatestEntriesFeed, TagFeed
|
||||
from djangocms_blog.settings import get_setting
|
||||
from djangocms_blog.views import (
|
||||
AuthorEntriesView, CategoryEntriesView, PostArchiveView, PostDetailView, PostListView,
|
||||
TaggedListView,
|
||||
)
|
||||
|
||||
|
||||
def get_urls():
|
||||
urls = get_setting('PERMALINK_URLS')
|
||||
details = []
|
||||
for urlconf in urls.values():
|
||||
details.append(
|
||||
url(urlconf, PostDetailView.as_view(), name='post-detail'),
|
||||
)
|
||||
return details
|
||||
|
||||
|
||||
detail_urls = get_urls()
|
||||
|
||||
urlpatterns = [
|
||||
url(r'^latests/$',
|
||||
PostListView.as_view(), name='posts-latest'),
|
||||
url(r'^feed/$',
|
||||
LatestEntriesFeed(), name='posts-latest-feed'),
|
||||
url(r'^feed/fb/$',
|
||||
FBInstantArticles(), name='posts-latest-feed-fb'),
|
||||
url(r'^(?P<year>\d{4})/$',
|
||||
PostArchiveView.as_view(), name='posts-archive'),
|
||||
url(r'^(?P<year>\d{4})/(?P<month>\d{1,2})/$',
|
||||
PostArchiveView.as_view(), name='posts-archive'),
|
||||
url(r'^author/(?P<username>[\w\.@+-]+)/$',
|
||||
AuthorEntriesView.as_view(), name='posts-author'),
|
||||
url(r'^category/(?P<category>[\w\.@+-]+)/$',
|
||||
CategoryEntriesView.as_view(), name='posts-category'),
|
||||
url(r'^tag/(?P<tag>[-\w]+)/$',
|
||||
TaggedListView.as_view(), name='posts-tagged'),
|
||||
url(r'^tag/(?P<tag>[-\w]+)/feed/$',
|
||||
TagFeed(), name='posts-tagged-feed'),
|
||||
] + detail_urls
|
|
@ -2,21 +2,25 @@
|
|||
from __future__ import absolute_import, print_function, unicode_literals
|
||||
|
||||
import os.path
|
||||
import sys
|
||||
|
||||
from aldryn_apphooks_config.utils import get_app_instance
|
||||
from cms.api import add_plugin
|
||||
from cms.appresolver import APP_RESOLVERS, get_app_patterns
|
||||
from cms.toolbar.items import ModalItem
|
||||
from cms.utils.apphook_reload import reload_urlconf
|
||||
from django.contrib.auth.models import AnonymousUser
|
||||
from django.core.exceptions import ImproperlyConfigured
|
||||
from django.core.urlresolvers import reverse
|
||||
from django.http import Http404
|
||||
from django.test import override_settings
|
||||
from django.utils.timezone import now
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
from parler.tests.utils import override_parler_settings
|
||||
from parler.utils.conf import add_default_language_settings
|
||||
from parler.utils.context import smart_override, switch_language
|
||||
|
||||
from djangocms_blog.cms_appconfig import BlogConfig
|
||||
from djangocms_blog.feeds import FBInstantArticles, FBInstantFeed, LatestEntriesFeed, TagFeed
|
||||
from djangocms_blog.models import BLOG_CURRENT_NAMESPACE
|
||||
from djangocms_blog.settings import get_setting
|
||||
|
@ -31,6 +35,19 @@ from .base import BaseTest
|
|||
|
||||
class ViewTest(BaseTest):
|
||||
|
||||
@override_settings(BLOG_URLCONF='tests.test_utils.blog_urls')
|
||||
def test_post_list_view_custom_urlconf(self):
|
||||
pages = self.get_pages()
|
||||
self.get_posts()
|
||||
self.get_request(pages[1], 'en', AnonymousUser())
|
||||
self.assertEqual(reverse('sample_app:posts-latest'), '/en/page-two/latests/')
|
||||
|
||||
def test_post_list_view_base_urlconf(self):
|
||||
pages = self.get_pages()
|
||||
self.get_posts()
|
||||
self.get_request(pages[1], 'en', AnonymousUser())
|
||||
self.assertEqual(reverse('sample_app:posts-latest'), '/en/page-two/')
|
||||
|
||||
def test_post_list_view(self):
|
||||
pages = self.get_pages()
|
||||
posts = self.get_posts()
|
||||
|
|
Loading…
Reference in a new issue