Commit 499ff9a9 by Bridger Maxwell

Changed structure of wiki so that the base article is just '/'

--HG--
branch : bridgerwiki
parent 6660646f
......@@ -21,9 +21,7 @@ class Article(models.Model):
title = models.CharField(max_length=512, verbose_name=_('Article title'),
blank=False)
slug = models.SlugField(max_length=100, verbose_name=_('slug'),
help_text=_('Letters, numbers, underscore and hyphen.'
' Do not use reserved words \'create\','
' \'history\' and \'edit\'.'),
help_text=_('Letters, numbers, underscore and hyphen.'),
blank=True)
created_by = models.ForeignKey(User, verbose_name=_('Created by'), blank=True, null=True)
created_on = models.DateTimeField(auto_now_add = 1)
......@@ -50,16 +48,17 @@ class Article(models.Model):
except the very first time the wiki is loaded, in which
case the user is prompted to create this article."""
try:
return Article.objects.filter(parent__exact = None)[0]
return Article.objects.filter(slug__exact = "")[0]
except:
raise ShouldHaveExactlyOneRootSlug()
def get_url(self):
"""Return the Wiki URL for an article"""
if self.parent:
return self.parent.get_url() + '/' + self.slug
else:
return self.slug
url = self.slug + "/"
if (self.parent):
url = self.parent.get_url() + url
return url
def get_abs_url(self):
"""Return the absolute path for an article. This is necessary in cases
......@@ -247,7 +246,8 @@ class Revision(models.Model):
# Create pre-parsed contents - no need to parse on-the-fly
ext = WIKI_MARKDOWN_EXTENSIONS
ext += ["wikilinks(base_url=%s/)" % reverse('wiki_view', args=('',))]
# TODO: Replace with a real wikilinks module
# ext += ["wikilinks(base_url=%s/)" % reverse('wiki_view', args=('',))]
self.contents_parsed = markdown(self.contents,
extensions=ext,
safe_mode='escape',)
......
......@@ -89,7 +89,6 @@ WIKI_MARKDOWN_EXTENSIONS = getattr(settings, 'SIMPLE_WIKI_MARKDOWN_EXTENSIONS',
'abbr',
'toc',
'mathjax',
'camelcase', # CamelCase-style wikilinks
'video', # In-line embedding for YouTube, etc.
'circuit'
])
......
from django.conf.urls.defaults import *
urlpatterns = patterns('',
url(r'^(?:view/)?$', 'simplewiki.views.root_redirect', name='wiki_root'),
url(r'^view/([a-zA-Z\d/_-]*)/$', 'simplewiki.views.view', name='wiki_view'),
url(r'^edit/([a-zA-Z\d/_-]*)/$', 'simplewiki.views.edit', name='wiki_edit'),
url(r'^create/([a-zA-Z\d/_-]*)/$', 'simplewiki.views.create', name='wiki_create'),
url(r'^history/([a-zA-Z\d/_-]*)/([0-9]*)/$', 'simplewiki.views.history', name='wiki_history'),
url(r'^random/$', 'simplewiki.views.random_article', name='wiki_random'),
url(r'^search/$', 'simplewiki.views.search_articles', name='wiki_search_articles'),
url(r'^list/$', 'simplewiki.views.search_articles', name='wiki_list_articles'), #Just an alias for the search, but you usually don't submit a search term
url(r'^search_related/([a-zA-Z\d/_-]*)/$', 'simplewiki.views.search_add_related', name='search_related'),
url(r'^$', 'simplewiki.views.root_redirect', name='wiki_root'),
url(r'^view(/[a-zA-Z\d/_-]*)/?$', 'simplewiki.views.view', name='wiki_view'),
url(r'^edit(/[a-zA-Z\d/_-]*)/?$', 'simplewiki.views.edit', name='wiki_edit'),
url(r'^create(/[a-zA-Z\d/_-]*)/?$', 'simplewiki.views.create', name='wiki_create'),
url(r'^history(/[a-zA-Z\d/_-]*)/([0-9]*)/?$', 'simplewiki.views.history', name='wiki_history'),
url(r'^search_related(/[a-zA-Z\d/_-]*)/?$', 'simplewiki.views.search_add_related', name='search_related'),
url(r'^random/?$', 'simplewiki.views.random_article', name='wiki_random'),
url(r'^search/?$', 'simplewiki.views.search_articles', name='wiki_search_articles'),
url(r'^list/?$', 'simplewiki.views.search_articles', name='wiki_list_articles'), #Just an alias for the search, but you usually don't submit a search term
# url(r'^/?([a-zA-Z\d/_-]*)/_related/add/$', 'simplewiki.views.add_related', name='add_related'),
# url(r'^/?([a-zA-Z\d/_-]*)/_related/remove/(\d+)$', 'simplewiki.views.remove_related', name='wiki_remove_relation'),
# url(r'^/?([a-zA-Z\d/_-]*)/_add_attachment/$', 'simplewiki.views_attachments.add_attachment', name='add_attachment'),
......
......@@ -43,22 +43,10 @@ def view(request, wiki_url):
return render_to_response('simplewiki_view.html', d)
def root_redirect(request):
"""
Reason for redirecting:
The root article needs to to have a specific slug
in the URL, otherwise pattern matching in urls.py will get confused.
I've tried various methods to avoid this, but depending on Django/Python
versions, regexps have been greedy in two different ways.. so I just
skipped having problematic URLs like '/wiki/_edit' for editing the main page.
#benjaoming
"""
if not request.user.is_authenticated():
return redirect('/')
try:
root = Article.get_root()
if root.slug == "":
root.slug = "Home"
root.save()
except:
err = not_found(request, 'mainpage')
return err
......@@ -266,7 +254,7 @@ def search_articles(request):
# Need to throttle results by splitting them into pages...
results = Article.objects.all()
if results.count() == 1:
if results.count() == 1 and querystring:
return HttpResponseRedirect(reverse('wiki_view', args=(results[0].get_url(),)))
else:
d = {'wiki_search_results': results,
......@@ -400,7 +388,7 @@ def fetch_from_url(request, url):
path = Article.get_url_reverse(url_path, root)
if not path:
err = not_found(request, '/'.join([root.slug] + url_path))
err = not_found(request, '/' + '/'.join(url_path))
else:
article = path[-1]
return (article, path, err)
......
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