Skip to content

Commit

Permalink
Fix django-wiki#23 - move model registration from taking place within…
Browse files Browse the repository at this point in the history
… wiki.models to wiki.urls -- after all apps and models have been loaded
  • Loading branch information
benjaoming committed Jul 17, 2013
1 parent fcce3ce commit 384fb62
Show file tree
Hide file tree
Showing 9 changed files with 51 additions and 41 deletions.
2 changes: 1 addition & 1 deletion wiki/core/plugins/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,4 @@ def load(modname, verbose=False, failfast=False):
get_module(app, modname, verbose, failfast)

def load_wiki_plugins():
load('wiki_plugin', verbose=False)
load('wiki_plugin', verbose=True, failfast=False)
9 changes: 0 additions & 9 deletions wiki/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,6 @@
warnings.warn("django-wiki: No south in your INSTALLED_APPS. This is highly discouraged.")


######################
# PLUGINS
######################

from wiki.core.plugins.loader import load_wiki_plugins

load_wiki_plugins()


from django.core import urlresolvers

original_django_reverse = urlresolvers.reverse
Expand Down
15 changes: 15 additions & 0 deletions wiki/plugins/attachments/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from django.conf.urls import patterns, url

from wiki.plugins.attachments import views

urlpatterns = patterns('',
url(r'^$', views.AttachmentView.as_view(), name='attachments_index'),
url(r'^search/$', views.AttachmentSearchView.as_view(), name='attachments_search'),
url(r'^add/(?P<attachment_id>\d+)/$', views.AttachmentAddView.as_view(), name='attachments_add'),
url(r'^replace/(?P<attachment_id>\d+)/$', views.AttachmentReplaceView.as_view(), name='attachments_replace'),
url(r'^history/(?P<attachment_id>\d+)/$', views.AttachmentHistoryView.as_view(), name='attachments_history'),
url(r'^download/(?P<attachment_id>\d+)/$', views.AttachmentDownloadView.as_view(), name='attachments_download'),
url(r'^delete/(?P<attachment_id>\d+)/$', views.AttachmentDeleteView.as_view(), name='attachments_delete'),
url(r'^download/(?P<attachment_id>\d+)/revision/(?P<revision_id>\d+)/$', views.AttachmentDownloadView.as_view(), name='attachments_download'),
url(r'^change/(?P<attachment_id>\d+)/revision/(?P<revision_id>\d+)/$', views.AttachmentChangeRevisionView.as_view(), name='attachments_revision_change'),
)
31 changes: 15 additions & 16 deletions wiki/plugins/attachments/wiki_plugin.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
from django.conf.urls import patterns, url
from django.conf.urls import patterns, url, include
from django.utils.translation import ugettext as _

from wiki.core.plugins import registry
Expand All @@ -11,20 +11,13 @@
from wiki.plugins.notifications.settings import ARTICLE_EDIT
from wiki.plugins.notifications.util import truncate_title


class AttachmentPlugin(BasePlugin):

slug = settings.SLUG
urlpatterns = {
'article': patterns('',
url(r'^$', views.AttachmentView.as_view(), name='attachments_index'),
url(r'^search/$', views.AttachmentSearchView.as_view(), name='attachments_search'),
url(r'^add/(?P<attachment_id>\d+)/$', views.AttachmentAddView.as_view(), name='attachments_add'),
url(r'^replace/(?P<attachment_id>\d+)/$', views.AttachmentReplaceView.as_view(), name='attachments_replace'),
url(r'^history/(?P<attachment_id>\d+)/$', views.AttachmentHistoryView.as_view(), name='attachments_history'),
url(r'^download/(?P<attachment_id>\d+)/$', views.AttachmentDownloadView.as_view(), name='attachments_download'),
url(r'^delete/(?P<attachment_id>\d+)/$', views.AttachmentDeleteView.as_view(), name='attachments_delete'),
url(r'^download/(?P<attachment_id>\d+)/revision/(?P<revision_id>\d+)/$', views.AttachmentDownloadView.as_view(), name='attachments_download'),
url(r'^change/(?P<attachment_id>\d+)/revision/(?P<revision_id>\d+)/$', views.AttachmentChangeRevisionView.as_view(), name='attachments_revision_change'),
url('', include('wiki.plugins.attachments.urls')),
)
}

Expand All @@ -33,12 +26,18 @@ class AttachmentPlugin(BasePlugin):

# List of notifications to construct signal handlers for. This
# is handled inside the notifications plugin.
notifications = [{'model': models.AttachmentRevision,
'message': lambda obj: (_(u"A file was changed: %s") if not obj.deleted else _(u"A file was deleted: %s")) % truncate_title(obj.get_filename()),
'key': ARTICLE_EDIT,
'created': True,
'get_article': lambda obj: obj.attachment.article}
]
notifications = [{
'model': models.AttachmentRevision,
'message': lambda obj: (
_(u"A file was changed: %s")
if not obj.deleted
else
_(u"A file was deleted: %s")
) % truncate_title(obj.get_filename()),
'key': ARTICLE_EDIT,
'created': True,
'get_article': lambda obj: obj.attachment.article}
]

markdown_extensions = [AttachmentExtension()]

Expand Down
1 change: 1 addition & 0 deletions wiki/plugins/highlighter/THIS_PLUGIN_IS_JUST_A_TODO
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
nothing in here, don't use it!
12 changes: 5 additions & 7 deletions wiki/plugins/links/mdx/djangowikilinks.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
import markdown
from os import path as os_path

from wiki import models

try:
# Markdown 2.1.0 changed from 2.0.3. We try importing the new version first,
# but import the 2.0.3 version if it fails
Expand All @@ -35,9 +37,9 @@ class WikiPathExtension(markdown.Extension):
def __init__(self, configs):
# set extension defaults
self.config = {
'base_url' : ['/', 'String to append to beginning of URL.'],
'html_class' : ['wikipath', 'CSS hook. Leave blank for none.'],
'default_level' : [2, 'The level that most articles are created at. Relative links will tend to start at that level.']
'base_url' : ['/', 'String to append to beginning of URL.'],
'html_class' : ['wikipath', 'CSS hook. Leave blank for none.'],
'default_level' : [2, 'The level that most articles are created at. Relative links will tend to start at that level.']
}

# Override defaults with user settings
Expand All @@ -60,7 +62,6 @@ def __init__(self, pattern, config, **kwargs):
self.config = config

def handleMatch(self, m) :
from wiki import models
article_title = m.group('wikiTitle')
absolute = False
if article_title.startswith("/"):
Expand Down Expand Up @@ -131,6 +132,3 @@ def _getMeta(self):
def makeExtension(configs=None) :
return WikiPathExtension(configs=configs)

if __name__ == "__main__":
import doctest
doctest.testmod()
3 changes: 2 additions & 1 deletion wiki/plugins/links/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
from django.views.generic.base import View
from django.utils.decorators import method_decorator

from wiki import models

class QueryUrlPath(View):

# TODO: get_article does not actually support JSON responses
Expand All @@ -11,7 +13,6 @@ def dispatch(self, request, article, *args, **kwargs):
max_num = kwargs.pop('max_num', 20)
# TODO: Move this import when circularity issue is resolved
# https://github.com/benjaoming/django-wiki/issues/23
from wiki import models
query = request.GET.get('query', None)

if query:
Expand Down
8 changes: 1 addition & 7 deletions wiki/plugins/notifications/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from wiki.plugins.notifications.settings import ARTICLE_EDIT
from wiki.core.plugins.base import PluginSettingsFormMixin

from wiki.plugins.notifications import models

class SettingsModelChoiceField(forms.ModelChoiceField):
def label_from_instance(self, obj):
Expand All @@ -31,7 +32,6 @@ def label_from_instance(self, obj):
class SettingsModelForm(forms.ModelForm):
def __init__(self, *args, **kwargs):
super(SettingsModelForm, self).__init__(*args, **kwargs)
import models
instance = kwargs.get('instance', None)
self.__editing_instance = False
if instance:
Expand Down Expand Up @@ -120,9 +120,6 @@ class SubscriptionForm(PluginSettingsFormMixin, forms.Form):

def __init__(self, article, request, *args, **kwargs):

# This has to be here to avoid unresolved imports in wiki_plugins
from wiki.plugins.notifications import models

self.article = article
self.user = request.user
initial = kwargs.pop('initial', None)
Expand Down Expand Up @@ -160,9 +157,6 @@ def get_usermessage(self):

def save(self, *args, **kwargs):

# This has to be here to avoid unresolved imports in wiki_plugins
from wiki.plugins.notifications import models

cd = self.cleaned_data
if not self.changed_data:
return
Expand Down
11 changes: 11 additions & 0 deletions wiki/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,3 +144,14 @@ def get_pattern(app_name="wiki", namespace="wiki", url_config_class=None):
url_config_class = get_class_from_str(url_config_classname)
urlpatterns = url_config_class().get_urls()
return urlpatterns, app_name, namespace


######################
# PLUGINS
######################

from wiki.core.plugins.loader import load_wiki_plugins

load_wiki_plugins()


0 comments on commit 384fb62

Please sign in to comment.