Commit 384fb620 by benjaoming

Fix #23 - move model registration from taking place within wiki.models to…

Fix #23 - move model registration from taking place within wiki.models to wiki.urls -- after all apps and models have been loaded
parent fcce3ce9
......@@ -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)
......@@ -43,15 +43,6 @@ if not 'south' in django_settings.INSTALLED_APPS:
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
......
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'),
)
\ No newline at end of file
# -*- 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
......@@ -11,20 +11,13 @@ from wiki.plugins.attachments.markdown_extensions import AttachmentExtension
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')),
)
}
......@@ -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()]
......
nothing in here, don't use it!
\ No newline at end of file
......@@ -24,6 +24,8 @@ Dependencies:
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
......@@ -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
......@@ -60,7 +62,6 @@ class WikiPath(markdown.inlinepatterns.Pattern):
self.config = config
def handleMatch(self, m) :
from wiki import models
article_title = m.group('wikiTitle')
absolute = False
if article_title.startswith("/"):
......@@ -131,6 +132,3 @@ class WikiPath(markdown.inlinepatterns.Pattern):
def makeExtension(configs=None) :
return WikiPathExtension(configs=configs)
if __name__ == "__main__":
import doctest
doctest.testmod()
......@@ -2,6 +2,8 @@ from wiki.decorators import json_view, get_article
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
......@@ -11,7 +13,6 @@ class QueryUrlPath(View):
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:
......
......@@ -10,6 +10,7 @@ from django.utils.safestring import mark_safe
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):
......@@ -31,7 +32,6 @@ class ArticleSubscriptionModelMultipleChoiceField(forms.ModelMultipleChoiceField
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:
......@@ -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)
......@@ -160,9 +157,6 @@ class SubscriptionForm(PluginSettingsFormMixin, forms.Form):
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
......
......@@ -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()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment