Permalink
Browse files

Use WikiSite for wiki urls

  • Loading branch information...
rsalmaso committed Feb 24, 2018
1 parent 6d49b66 commit c35b09da5e2c99136cbe6d4202515c15d351e8c6
@@ -41,4 +41,35 @@ wiki. Add the following as ``wiki/base.html`` somewhere in your
</ul>
{% endblock %}
Site
----
You can override default django-wiki ``wiki.sites.site`` urls/views site implementation
with your own: override by setting the :attr:`~.WikiConfig.default_site` attribute
of a custom ``AppConfig`` to the dotted import path of either a ``WikiSite`` subclass
or a callable that returns a site instance.
.. code-block:: python
# myproject/sites.py
from wiki.sites import WikiSite
class MyWikiSite(admin.WikiSite):
...
.. code-block:: python
# myproject/apps.py
from wiki.apps import WikiConfig
class MyWikiConfig(WikiConfig):
default_site = 'myproject.sites.MyWikiSite'
.. code-block:: python
# myproject/settings.py
INSTALLED_APPS = [
...
'myproject.apps.MyWikiConfig', # replaces 'wiki.apps.WikiConfig'
...
]
@@ -160,10 +160,9 @@ following lines at the end of your project's ``urls.py``.
.. code-block:: python
from wiki.urls import get_pattern as get_wiki_pattern
urlpatterns += [
url(r'^notifications/', include('django_nyt.urls')),
url(r'', get_wiki_pattern())
url(r'', include('wiki.urls'))
]
@@ -19,12 +19,14 @@ Added
~~~~~
* Django 2 support :url-issue:`755` (Raffaele Salmaso & Mads Jensen)
* Added ``wiki.sites.WikiSite`` for easy customization :url-issue:`827`
Changed
~~~~~~~
* Use full path names for ``MARKDOWN_KWARGS['extensions']`` as short names
support wil be removed in ``Markdown 2.7`` :url-issue:`823`
* Support for ``include('wiki.urls')`` for urls instantiation :url-issue:`827`
Fixed
~~~~~
@@ -2,9 +2,15 @@
from wiki.compat import include, url
from wiki.conf import settings
from wiki.core.plugins import registry
from wiki import sites
from wiki.views import accounts, article, deleted_list
urlpatterns = [
url(r'^', sites.site.urls),
]
class WikiURLPatterns:
"""
@@ -4,7 +4,6 @@
from django.http.response import HttpResponse
from django.views.static import serve as static_serve
from wiki.compat import include, url
from wiki.urls import get_pattern as get_wiki_pattern
admin.autodiscover()
@@ -22,7 +21,7 @@
urlpatterns += [
url(r'^notify/', include('django_nyt.urls')),
url(r'', get_wiki_pattern())
url(r'', include('wiki.urls')),
]
handler500 = 'testproject.views.server_error'
@@ -0,0 +1,92 @@
from importlib import reload
from django.contrib.sites.models import Site
from django.test.testcases import TestCase
from wiki import sites, urls
from wiki.apps import WikiConfig
from wiki.compat import include, url
from wiki.models import Article, URLPath
from ..base import wiki_override_settings
class WikiCustomSite(sites.WikiSite):
def get_article_urls(self):
urlpatterns = [
url('^some-prefix/(?P<article_id>[0-9]+)/$', self.article_view, name='get'),
]
return urlpatterns
def get_article_path_urls(self):
urlpatterns = [
url('^some-other-prefix/(?P<path>.+/|)$', self.article_view, name='get'),
]
return urlpatterns
class WikiCustomConfig(WikiConfig):
default_site = "tests.core.test_sites.WikiCustomSite"
urlpatterns = [
url(r'^notify/', include('django_nyt.urls')),
url(r'', include('wiki.urls')),
]
@wiki_override_settings(
INSTALLED_APPS=[
'tests.testdata',
'django.contrib.auth.apps.AuthConfig',
'django.contrib.contenttypes.apps.ContentTypesConfig',
'django.contrib.sessions.apps.SessionsConfig',
'django.contrib.admin.apps.AdminConfig',
'django.contrib.humanize.apps.HumanizeConfig',
'django.contrib.sites.apps.SitesConfig',
'django_nyt.apps.DjangoNytConfig',
'mptt',
'sekizai',
'sorl.thumbnail',
'tests.core.test_sites.WikiCustomConfig',
'wiki.plugins.attachments.apps.AttachmentsConfig',
'wiki.plugins.notifications.apps.NotificationsConfig',
'wiki.plugins.images.apps.ImagesConfig',
'wiki.plugins.macros.apps.MacrosConfig',
'wiki.plugins.globalhistory.apps.GlobalHistoryConfig',
],
ROOT_URLCONF='tests.core.test_sites',
)
class CustomWikiSiteTest(TestCase):
def setUp(self):
# Reload wiki.urls since it may have already been instantiated by another test app.
self._old_site = sites.site
sites.site = sites.DefaultWikiSite()
reload(urls)
def tearDown(self):
sites.site = self._old_site
reload(urls)
def test_use_custom_wiki_site(self):
self.assertEqual(sites.site.__class__.__name__, 'WikiCustomSite')
def test_get_absolute_url_if_urlpath_set_is_not_exists__no_root_urlconf(self):
a = Article.objects.create()
self.assertEqual(a.get_absolute_url(), '/some-prefix/1/')
def test_get_absolute_url_if_urlpath_set_is_exists__no_root_urlconf(self):
a1 = Article.objects.create()
s1 = Site.objects.create(domain="something.com", name="something.com")
u1 = URLPath.objects.create(article=a1, site=s1)
a2 = Article.objects.create()
s2 = Site.objects.create(domain="somethingelse.com", name="somethingelse.com")
URLPath.objects.create(
article=a2,
site=s2,
parent=u1,
slug='test_slug'
)
self.assertEqual(a2.get_absolute_url(), '/some-other-prefix/test_slug/')
@@ -2,7 +2,6 @@
from django.contrib import admin
from django.contrib.staticfiles.urls import staticfiles_urlpatterns
from wiki.compat import include, url
from wiki.urls import get_pattern as get_wiki_pattern
urlpatterns = [
@@ -22,5 +21,5 @@
urlpatterns += [
url(r'^django_functest/', include('django_functest.urls')),
url(r'^notify/', include('django_nyt.urls')),
url(r'', get_wiki_pattern())
url(r'', include('wiki.urls')),
]

0 comments on commit c35b09d

Please sign in to comment.