Commit b69deb69 by Bridger Maxwell

Got the view page of the wiki rendering. Most of it is a styling mess.

parent 80026444
......@@ -14,6 +14,7 @@ _FIELDS = ['number', # 6.002x
'path', # /some/absolute/filepath/6.002x --> course.xml is in here.
'instructors', # ['Anant Agarwal']
'institution', # "MIT"
'wiki_namespace',
'grader', # a courseware.graders.CourseGrader object
#'start', # These should be datetime fields
......
......@@ -34,7 +34,7 @@ class ArticleAdminForm(forms.ModelForm):
model = Article
class ArticleAdmin(admin.ModelAdmin):
list_display = ('created_by', 'slug', 'modified_on', 'parent')
list_display = ('created_by', 'slug', 'modified_on', 'namespace')
search_fields = ('slug',)
prepopulated_fields = {'slug': ('title',) }
inlines = [RevisionInline]
......
......@@ -56,15 +56,7 @@ class Article(models.Model):
try:
return Article.objects.filter(slug__exact = "")[0]
except:
raise ShouldHaveExactlyOneRootSlug()
@models.permalink
def get_absolute_url(self):
return ('wiki_view', [self.slug])
def get_full_slug(self):
# TODO: Return namespace : slug
return self.slug
raise ShouldHaveExactlyOneRootSlug()
# @classmethod
# def get_url_reverse(cls, path, article, return_list=[]):
......
from django.conf.urls.defaults import *
urlpatterns = patterns('',
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_revision/([0-9]*)(/[a-zA-Z\d/_-]*)/?$', 'simplewiki.views.view_revision', name='wiki_view_revision'),
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'^revision_feed/([0-9]*)/?$', 'simplewiki.views.revision_feed', name='wiki_revision_feed'),
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'),
# url(r'^/?([a-zA-Z\d/_-]*)/_view_attachment/(.+)?$', 'simplewiki.views_attachments.view_attachment', name='wiki_view_attachment'),
# url(r'^(.*)$', 'simplewiki.views.encode_err', name='wiki_encode_err')
)
......@@ -4,7 +4,7 @@ from django.contrib.auth.decorators import login_required
from django.core.context_processors import csrf
from django.core.urlresolvers import reverse
from django.db.models import Q
from django.http import HttpResponse, HttpResponseRedirect
from django.http import HttpResponse, HttpResponseRedirect, Http404
from django.utils import simplejson
from django.utils.translation import ugettext_lazy as _
from mitxmako.shortcuts import render_to_response
......@@ -15,6 +15,14 @@ from models import Revision, Article, CreateArticleForm, RevisionFormWithTitle,
import wiki_settings
def view(request, course_id, slug, namespace=None):
try:
course = settings.COURSES_BY_ID[course_id]
if not namespace:
namespace = course.wiki_namespace
except KeyError:
raise Http404("Course not found")
(article, err) = get_article(request, slug, namespace if namespace else course_id )
if err:
return err
......@@ -27,9 +35,11 @@ def view(request, course_id, slug, namespace=None):
'wiki_write': article.can_write_l(request.user),
'wiki_attachments_write': article.can_attach(request.user),
'wiki_current_revision_deleted' : not (article.current_revision.deleted == 0),
'wiki_title' : article.title + " - MITX %s Wiki" % course_number
'wiki_title' : article.title + " - edX %s Wiki" % course.title,
'course' : course,
}
d.update(csrf(request))
print d
return render_to_response('simplewiki/simplewiki_view.html', d)
def view_revision(request, course_id, slug, revision_number, namespace=None):
......@@ -445,8 +455,8 @@ def get_article(request, slug, namespace):
article = None
try:
article = Article.objects.get(slug__exact == slug )#, namespace__name__exact = namespace)
except:
article = Article.objects.get( slug__exact = slug )#, namespace__name__exact = namespace)
except Article.DoesNotExist:
#TODO: We need to pass a url for creating the article here
err = not_found(request, slug)
......
......@@ -17,7 +17,7 @@ def url_class(url):
<li class="book"><a href="${reverse('book', args=[course.id])}" class="${url_class('book')}">Textbook</a></li>
<li class="discussion"><a href="${reverse('questions')}">Discussion</a></li>
% endif
<li class="wiki"><a href="${reverse('wiki_root')}" class="${url_class('wiki')}">Wiki</a></li>
<li class="wiki"><a href="${reverse('wiki_root', args=[course.id])}" class="${url_class('wiki')}">Wiki</a></li>
% if user.is_authenticated():
<li class="profile"><a href="${reverse('profile', args=[course.id])}" class="${url_class('profile')}">Profile</a></li>
% endif
......
##This file is based on the template from the SimpleWiki source which carries the GPL license
<%inherit file="main.html"/>
<%namespace name='static' file='static_content.html'/>
<%inherit file="../main.html"/>
<%namespace name='static' file='../static_content.html'/>
<%!
from django.core.urlresolvers import reverse
%>
## A convenience function that calls reverse with the kwargs course_id, namespace, and slug
<%def name="wiki_reverse(wiki_page)">
${reverse(wiki_page, kwargs={'course_id': course.id, 'namespace' : wiki_article.namespace.name, 'slug' : wiki_article.slug})}
</%def>
<%block name="headextra">
<script type="text/javascript" src="${static.url('js/simplewiki/bsn.AutoSuggest_c_2.0.js')}"></script>
<%!
from django.core.urlresolvers import reverse
%>
<script type="text/javascript">
function set_related_article_id(s) {
document.getElementById('wiki_related_input_id').value = s.id;
......@@ -19,7 +23,7 @@
var x = window.onload;
window.onload = function(){
var options = {
script: "${reverse("search_related", args=[wiki_article.get_url()] )}/?self=${wiki_article.pk}&",
script: "${ wiki_reverse('search_related')}/?self=${wiki_article.pk}&",
json: true,
varname: "query",
maxresults: 35,
......@@ -69,23 +73,17 @@
<%block name="bodyextra">
<%include file="course_navigation.html" args="active_page='wiki'" />
<%include file="../course_navigation.html" args="active_page='wiki'" />
<section class="main-content">
<div class="wiki-wrapper">
<%block name="wiki_panel">
<div aria-label="Wiki Navigation" id="wiki_panel">
<h2>Course Wiki</h2>
<%
if (wiki_article is not UNDEFINED):
baseURL = reverse("wiki_view", args=[wiki_article.get_url()])
else:
baseURL = reverse("wiki_view", args=["/"])
%>
<ul class="action">
<li>
<h3>
<a href="${reverse("wiki_list_articles", args=[])}">All Articles</a>
<a href="${reverse("wiki_list_articles", args=[course.id])}">All Articles</a>
</h3>
</li>
......@@ -95,12 +93,7 @@
</h3>
<div id="wiki_create_form">
<%
theaction = "this.wiki_article_name.value.replace(/([^a-zA-Z0-9\-])/g, '')"
baseURL = reverse("wiki_create", args=["/"])
%>
<form method="GET" onsubmit="this.action='${baseURL + "' + " + theaction};">
<form method="GET" action="${reverse("wiki_create", args=[course.id])}">
<div>
<label for="id_wiki_article_name">Title of article</label>
......@@ -121,7 +114,7 @@
</li>
<li class="search">
<form method="POST" action='${reverse("wiki_search_articles", args=[])}'>
<form method="POST" action='${reverse("wiki_search_articles", args=[course.id])}'>
<label class="wiki_box_title">Search</label>
<div style="display:none">
<input type="hidden" name="csrfmiddlewaretoken" value="${csrf_token}"/>
......@@ -148,15 +141,15 @@
<ul>
<li>
<input type="button" onclick="javascript:location.href='${reverse("wiki_view", args=[wiki_article.get_url()])}'" value="View" class="view" />
<a href="${ wiki_reverse('wiki_view')}" class="view">View</a>
</li>
<li>
<input type="button" onclick="javascript:location.href='${reverse("wiki_edit", args=[wiki_article.get_url()])}'" value="Edit" ${'disabled="true"' if not wiki_write else ""} class="edit"/>
<a href="${ wiki_reverse('wiki_edit')}" class="edit">Edit</a>
</li>
<li>
<input type="button" onclick="javascript:location.href='${reverse("wiki_history", args=[wiki_article.get_url(),1])}'" value="History" class="button history" />
<a href="${ wiki_reverse('wiki_history')}" class="history">History</a>
</li>
</ul>
</header>
......
......@@ -50,7 +50,6 @@ if settings.PERFSTATS:
if settings.COURSEWARE_ENABLED:
urlpatterns += (
url(r'^wiki/', include('simplewiki.urls')),
url(r'^masquerade/', include('masquerade.urls')),
url(r'^courseware/(?P<course>[^/]*)/(?P<chapter>[^/]*)/(?P<section>[^/]*)/(?P<position>[^/]*)$', 'courseware.views.index'),
# url(r'^courseware/(?P<course>[^/]*)/(?P<chapter>[^/]*)/(?P<section>[^/]*)/$', 'courseware.views.index', name="courseware_section"),
......@@ -82,6 +81,25 @@ if settings.COURSEWARE_ENABLED:
url(r'^courses/(?P<course_id>[^/]*)/about$', 'courseware.views.course_info', name="about_course"),
)
# Multicourse wiki
article_slug = r"(?:/(?P<namespace>[a-zA-Z\d_-]*))?/(?P<slug>[a-zA-Z\d_-]*)"
urlpatterns += (
url(r'^courses/(?P<course_id>[^/]*)/wiki/$', 'simplewiki.views.root_redirect', name='wiki_root'),
url(r'^courses/(?P<course_id>[^/]*)/wiki/view' + article_slug + r'/?$', 'simplewiki.views.view', name='wiki_view'),
url(r'^courses/(?P<course_id>[^/]*)/wiki/view_revision/([0-9]*)(/[a-zA-Z\d/_-]*)/?$', 'simplewiki.views.view_revision', name='wiki_view_revision'),
url(r'^courses/(?P<course_id>[^/]*)/wiki/edit' + article_slug + r'/?$', 'simplewiki.views.edit', name='wiki_edit'),
url(r'^courses/(?P<course_id>[^/]*)/wiki/create/?$', 'simplewiki.views.create', name='wiki_create'),
url(r'^courses/(?P<course_id>[^/]*)/wiki/history' + article_slug + r'(?:/([0-9]*))?/?$', 'simplewiki.views.history', name='wiki_history'),
url(r'^courses/(?P<course_id>[^/]*)/wiki/search_related' + article_slug + r'/?$', 'simplewiki.views.search_add_related', name='search_related'),
url(r'^courses/(?P<course_id>[^/]*)/wiki/random/?$', 'simplewiki.views.random_article', name='wiki_random'),
url(r'^courses/(?P<course_id>[^/]*)/wiki/revision_feed/([0-9]*)/?$', 'simplewiki.views.revision_feed', name='wiki_revision_feed'),
url(r'^courses/(?P<course_id>[^/]*)/wiki/search/?$', 'simplewiki.views.search_articles', name='wiki_search_articles'),
url(r'^courses/(?P<course_id>[^/]*)/wiki/list/?$', 'simplewiki.views.search_articles', name='wiki_list_articles'), #Just an alias for the search, but you usually don't submit a search term
)
if settings.ENABLE_MULTICOURSE:
urlpatterns += (url(r'^mitxhome$', 'multicourse.views.mitxhome'),)
......
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