Commit b694183d by Bridger Maxwell

Merge

parents ef1c465d 499ff9a9
...@@ -21,9 +21,7 @@ class Article(models.Model): ...@@ -21,9 +21,7 @@ class Article(models.Model):
title = models.CharField(max_length=512, verbose_name=_('Article title'), title = models.CharField(max_length=512, verbose_name=_('Article title'),
blank=False) blank=False)
slug = models.SlugField(max_length=100, verbose_name=_('slug'), slug = models.SlugField(max_length=100, verbose_name=_('slug'),
help_text=_('Letters, numbers, underscore and hyphen.' help_text=_('Letters, numbers, underscore and hyphen.'),
' Do not use reserved words \'create\','
' \'history\' and \'edit\'.'),
blank=True) blank=True)
created_by = models.ForeignKey(User, verbose_name=_('Created by'), blank=True, null=True) created_by = models.ForeignKey(User, verbose_name=_('Created by'), blank=True, null=True)
created_on = models.DateTimeField(auto_now_add = 1) created_on = models.DateTimeField(auto_now_add = 1)
...@@ -50,16 +48,17 @@ class Article(models.Model): ...@@ -50,16 +48,17 @@ class Article(models.Model):
except the very first time the wiki is loaded, in which except the very first time the wiki is loaded, in which
case the user is prompted to create this article.""" case the user is prompted to create this article."""
try: try:
return Article.objects.filter(parent__exact = None)[0] return Article.objects.filter(slug__exact = "")[0]
except: except:
raise ShouldHaveExactlyOneRootSlug() raise ShouldHaveExactlyOneRootSlug()
def get_url(self): def get_url(self):
"""Return the Wiki URL for an article""" """Return the Wiki URL for an article"""
if self.parent: url = self.slug + "/"
return self.parent.get_url() + '/' + self.slug if (self.parent):
else: url = self.parent.get_url() + url
return self.slug
return url
def get_abs_url(self): def get_abs_url(self):
"""Return the absolute path for an article. This is necessary in cases """Return the absolute path for an article. This is necessary in cases
...@@ -247,7 +246,8 @@ class Revision(models.Model): ...@@ -247,7 +246,8 @@ class Revision(models.Model):
# Create pre-parsed contents - no need to parse on-the-fly # Create pre-parsed contents - no need to parse on-the-fly
ext = WIKI_MARKDOWN_EXTENSIONS 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, self.contents_parsed = markdown(self.contents,
extensions=ext, extensions=ext,
safe_mode='escape',) safe_mode='escape',)
......
...@@ -89,7 +89,6 @@ WIKI_MARKDOWN_EXTENSIONS = getattr(settings, 'SIMPLE_WIKI_MARKDOWN_EXTENSIONS', ...@@ -89,7 +89,6 @@ WIKI_MARKDOWN_EXTENSIONS = getattr(settings, 'SIMPLE_WIKI_MARKDOWN_EXTENSIONS',
'abbr', 'abbr',
'toc', 'toc',
'mathjax', 'mathjax',
'camelcase', # CamelCase-style wikilinks
'video', # In-line embedding for YouTube, etc. 'video', # In-line embedding for YouTube, etc.
'circuit' 'circuit'
]) ])
......
from django.conf.urls.defaults import * from django.conf.urls.defaults import *
urlpatterns = patterns('', urlpatterns = patterns('',
url(r'^(?:view/)?$', 'simplewiki.views.root_redirect', name='wiki_root'), url(r'^$', 'simplewiki.views.root_redirect', name='wiki_root'),
url(r'^view/([a-zA-Z\d/_-]*)/$', 'simplewiki.views.view', name='wiki_view'), 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'^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'^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'^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_related(/[a-zA-Z\d/_-]*)/?$', 'simplewiki.views.search_add_related', name='search_related'),
url(r'^search/$', 'simplewiki.views.search_articles', name='wiki_search_articles'), url(r'^random/?$', 'simplewiki.views.random_article', name='wiki_random'),
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/?$', 'simplewiki.views.search_articles', name='wiki_search_articles'),
url(r'^search_related/([a-zA-Z\d/_-]*)/$', 'simplewiki.views.search_add_related', name='search_related'), 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/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/_-]*)/_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'), # url(r'^/?([a-zA-Z\d/_-]*)/_add_attachment/$', 'simplewiki.views_attachments.add_attachment', name='add_attachment'),
......
...@@ -43,27 +43,15 @@ def view(request, wiki_url): ...@@ -43,27 +43,15 @@ def view(request, wiki_url):
return render_to_response('simplewiki_view.html', d) return render_to_response('simplewiki_view.html', d)
def root_redirect(request): 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(): if not request.user.is_authenticated():
return redirect('/') return redirect('/')
try: try:
root = Article.get_root() root = Article.get_root()
if root.slug == "":
root.slug = "Home"
root.save()
except: except:
err = not_found(request, 'mainpage') err = not_found(request, '/')
return err return err
return HttpResponseRedirect(reverse('wiki_view', args=(root.slug,))) return HttpResponseRedirect(reverse('wiki_view', args=(root.get_url())))
def create(request, wiki_url): def create(request, wiki_url):
if not request.user.is_authenticated(): if not request.user.is_authenticated():
...@@ -104,7 +92,7 @@ def create(request, wiki_url): ...@@ -104,7 +92,7 @@ def create(request, wiki_url):
#except ShouldHaveExactlyOneRootSlug, (e): #except ShouldHaveExactlyOneRootSlug, (e):
except: except:
if Article.objects.filter(parent=None).count() > 0: if Article.objects.filter(parent=None).count() > 0:
return HttpResponseRedirect(reverse('wiki_view', args=('',))) return HttpResponseRedirect(reverse('wiki_view', args=('/',)))
# Root not found... # Root not found...
path = [] path = []
url_path = [""] url_path = [""]
...@@ -266,7 +254,7 @@ def search_articles(request): ...@@ -266,7 +254,7 @@ def search_articles(request):
# Need to throttle results by splitting them into pages... # Need to throttle results by splitting them into pages...
results = Article.objects.all() results = Article.objects.all()
if results.count() == 1: if results.count() == 1 and querystring:
return HttpResponseRedirect(reverse('wiki_view', args=(results[0].get_url(),))) return HttpResponseRedirect(reverse('wiki_view', args=(results[0].get_url(),)))
else: else:
d = {'wiki_search_results': results, d = {'wiki_search_results': results,
...@@ -392,7 +380,7 @@ def fetch_from_url(request, url): ...@@ -392,7 +380,7 @@ def fetch_from_url(request, url):
try: try:
root = Article.get_root() root = Article.get_root()
except: except:
err = not_found(request, '') err = not_found(request, '/')
return (article, path, err) return (article, path, err)
if url_path and root.slug == url_path[0]: if url_path and root.slug == url_path[0]:
...@@ -400,7 +388,7 @@ def fetch_from_url(request, url): ...@@ -400,7 +388,7 @@ def fetch_from_url(request, url):
path = Article.get_url_reverse(url_path, root) path = Article.get_url_reverse(url_path, root)
if not path: if not path:
err = not_found(request, '/'.join([root.slug] + url_path)) err = not_found(request, '/' + '/'.join(url_path))
else: else:
article = path[-1] article = path[-1]
return (article, path, err) 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