Commits

Peter Nixon  committed 7d06018

an support for a wiki index page and associated editing

  • Participants
  • Parent commits fbdbff0

Comments (0)

Files changed (4)

File hgwiki/templates/hgwiki/index.html

-{% extends "base.html" %}
-
-{% block content %}
-<H1>Wiki Index</H1>
-<ul>
-    {% for page in pages %}
-    <li><a href="{{ page }}">{{ page }}</a></li>
-    {% endfor %}
-</ul>
-{% endblock %}

File hgwiki/templates/hgwiki/page_list.html

+{% extends "base.html" %}
+
+{% block content %}
+<H1>Wiki Index</H1>
+<ul>
+    {% for page in pages %}
+    <li><a href="{{ page }}">{{ page }}</a></li>
+    {% endfor %}
+</ul>
+{% endblock %}

File hgwiki/urls.py

 
 urlpatterns = patterns('hgwiki.views',
     url(r'^$', 'wiki_index', name="hgwiki_index"),
-    url(r'^(?P<slug>[-\w]+\.rst)$', 'wiki_page', name="hgwiki_page"),
-    url(r'^(?P<slug>[-\w]+\.rst)/edit/$', 'wiki_page_edit', name="hgwiki_page_edit"),
+    url(r'^(?P<slug>[-\w]+)$', 'wiki_page', name="hgwiki_page"),
+    url(r'^edit/$', 'wiki_page_edit_index', name="hgwiki_page_edit_index"),
+    url(r'^(?P<slug>[-\w]+)/edit/$', 'wiki_page_edit', name="hgwiki_page_edit"),
+    url(r'^list/$', 'wiki_page_list'),
 )

File hgwiki/views.py

 
 def wiki_index(request):
     """
+    Renders the wiki index if one exists otherwise redirects to the page list
+    """
+    wiki_dir = settings.HGWIKI_DIRECTORY_PATH
+
+    if os.path.isfile(os.path.join(wiki_dir, 'index.rst')) == True:
+        return wiki_page(request, 'index.rst')
+    elif os.path.isfile(os.path.join(wiki_dir, 'index.wiki')) == True:
+        return wiki_page(request, 'index.wiki')
+    else:
+        return HttpResponseRedirect('list/')
+
+
+def wiki_page_list(request):
+    """
     Renders a list of available wiki pages
     """
     # FIXME: Handle missing HGWIKI_DIRECTORY_PATH
     pages = listDirectory(settings.HGWIKI_DIRECTORY_PATH)
 
-    return render_to_response("hgwiki/index.html", {
+    return render_to_response("hgwiki/page_list.html", {
         "pages": pages,
     }, context_instance=RequestContext(request))
 
     }, context_instance=RequestContext(request))
 
 
+def wiki_page_edit_index(request):
+    if os.path.isfile(os.path.join(settings.HGWIKI_DIRECTORY_PATH, 'index.wiki')) == True:
+        filename = 'index.wiki'
+    else:
+        filename = 'index.rst'
+
+    return wiki_page_edit(request, filename)
+
 def wiki_page_edit(request, slug):
     file = os.path.join(settings.HGWIKI_DIRECTORY_PATH, slug)
+    #FIXME: Handle new files
     if os.path.isfile(file) == False:
       raise Http404