From 7262e392b65ca2454db3b3a27e6d1603954ba75d Mon Sep 17 00:00:00 2001 From: James Turk Date: Fri, 2 Apr 2010 17:40:56 -0400 Subject: [PATCH] more wiki-like * handle [[wiki style]] links * adjust markuptypes based on new 1.0.0b functionality * replace _ in names with ' ' on display --- README.rst | 10 +++++----- markupwiki/models.py | 11 ++++++++++- markupwiki/urls.py | 2 +- markupwiki/views.py | 2 +- 4 files changed, 17 insertions(+), 8 deletions(-) diff --git a/README.rst b/README.rst index 6b70a6f..4f3d396 100644 --- a/README.rst +++ b/README.rst @@ -14,15 +14,15 @@ might not be for you. Requirements ------------ -django-markupwiki depends on django 1.2+, django-markupfield and libraries -for whichever markup options you wish to include. +django-markupwiki depends on django 1.2+, django-markupfield 1.0.0b+ and +libraries for whichever markup options you wish to include. Settings ======== To best make use of MarkupField you should define the -``MARKUP_FIELD_TYPES`` setting, a dictionary of strings to callables that +``MARKUPWIKI_MARKUP_TYPES`` setting, a dictionary of strings to callables that 'render' a markup type:: import markdown @@ -32,12 +32,12 @@ To best make use of MarkupField you should define the parts = publish_parts(source=markup, writer_name="html4css1") return parts["fragment"] - MARKUP_FIELD_TYPES = { + MARKUPWIKI_MARKUP_TYPES = { 'markdown': markdown.markdown, 'ReST': render_rest, } -If you do not define a ``MARKUP_FIELD_TYPES`` then one is provided with the +If you do not define a ``MARKUPWIKI_MARKUP_TYPES`` then one is provided with the following markup types available: html: diff --git a/markupwiki/models.py b/markupwiki/models.py index 026c99d..7378845 100644 --- a/markupwiki/models.py +++ b/markupwiki/models.py @@ -5,9 +5,17 @@ from django.contrib.auth.models import User from django.core.cache import cache from django.core.urlresolvers import reverse from markupfield.fields import MarkupField +from markupfield import markup +from markupwiki.utils import wikify_markup_wrapper DEFAULT_MARKUP_TYPE = getattr(settings, 'MARKUPWIKI_DEFAULT_MARKUP_TYPE', 'plain') WRITE_LOCK_SECONDS = getattr(settings, 'MARKUPWIKI_WRITE_LOCK_SECONDS', 60) +MARKUP_TYPES = getattr(settings, 'MARKUPWIKI_MARKUP_TYPES', markup.DEFAULT_MARKUP_TYPES) + +# add make_wiki_links to MARKUP_TYPES +WIKI_MARKUP_TYPES = [] +for name, func in MARKUP_TYPES: + WIKI_MARKUP_TYPES.append((name, wikify_markup_wrapper(func))) PUBLIC, LOCKED, DELETED = range(3) ARTICLE_STATUSES = ( @@ -58,7 +66,8 @@ class ArticleVersion(models.Model): article = models.ForeignKey(Article, related_name='versions') author = models.ForeignKey(User, related_name='article_versions') number = models.PositiveIntegerField() - body = MarkupField(default_markup_type=DEFAULT_MARKUP_TYPE) + body = MarkupField(default_markup_type=DEFAULT_MARKUP_TYPE, + markup_choices=WIKI_MARKUP_TYPES) comment = models.CharField(max_length=200, blank=True) timestamp = models.DateTimeField(auto_now_add=True) diff --git a/markupwiki/urls.py b/markupwiki/urls.py index aca1376..e289523 100644 --- a/markupwiki/urls.py +++ b/markupwiki/urls.py @@ -1,6 +1,6 @@ from django.conf.urls.defaults import * -WIKI_REGEX = r'^(?P[\w\s]+)' +WIKI_REGEX = r'^(?P<title>[^/]+)' urlpatterns = patterns('markupwiki.views', url(WIKI_REGEX + '/$', 'view_article', name='view_article'), diff --git a/markupwiki/views.py b/markupwiki/views.py index d792973..8cb9816 100644 --- a/markupwiki/views.py +++ b/markupwiki/views.py @@ -50,7 +50,7 @@ def view_article(request, title, n=None): version = article.versions.latest() version.is_latest = True - # display title + # change article for display article.title = article.title.replace('_', ' ') # set editable flag on article