Commit 9405fc7b by Bridger Maxwell

Added wiki create and create_root. Fixed some mitxmako bugs.

parent 51768ef8
...@@ -23,7 +23,7 @@ class MakoLoader(object): ...@@ -23,7 +23,7 @@ class MakoLoader(object):
return self.load_template(template_name, template_dirs) return self.load_template(template_name, template_dirs)
def load_template(self, template_name, template_dirs=None): def load_template(self, template_name, template_dirs=None):
source, display_name = self.base_loader.load_template_source(template_name, template_dirs) source, display_name = self.load_template_source(template_name, template_dirs)
if source.startswith("## mako\n"): if source.startswith("## mako\n"):
# This is a mako template # This is a mako template
...@@ -42,9 +42,9 @@ class MakoLoader(object): ...@@ -42,9 +42,9 @@ class MakoLoader(object):
# not exist. # not exist.
return source, display_name return source, display_name
def load_template_source(self): def load_template_source(self, template_name, template_dirs=None):
# Just having this makes the template load as an instance, instead of a class. # Just having this makes the template load as an instance, instead of a class.
raise NotImplementedError return self.base_loader.load_template_source(template_name, template_dirs)
def reset(self): def reset(self):
self.base_loader.reset() self.base_loader.reset()
......
...@@ -53,6 +53,7 @@ class Template(MakoTemplate): ...@@ -53,6 +53,7 @@ class Template(MakoTemplate):
context_dictionary.update(d) context_dictionary.update(d)
context_dictionary['settings'] = settings context_dictionary['settings'] = settings
context_dictionary['MITX_ROOT_URL'] = settings.MITX_ROOT_URL context_dictionary['MITX_ROOT_URL'] = settings.MITX_ROOT_URL
context_dictionary['django_context'] = context_instance
return super(Template, self).render(**context_dictionary) return super(Template, self).render(**context_dictionary)
...@@ -3,7 +3,10 @@ from django.template.base import Template, Context ...@@ -3,7 +3,10 @@ from django.template.base import Template, Context
from django.template.loader import get_template, select_template from django.template.loader import get_template, select_template
def render_inclusion(func, file_name, *args, **kwargs): def render_inclusion(func, file_name, takes_context, django_context, *args, **kwargs):
if takes_context:
args = [django_context] + list(args)
_dict = func(*args, **kwargs) _dict = func(*args, **kwargs)
if isinstance(file_name, Template): if isinstance(file_name, Template):
t = file_name t = file_name
...@@ -15,6 +18,10 @@ def render_inclusion(func, file_name, *args, **kwargs): ...@@ -15,6 +18,10 @@ def render_inclusion(func, file_name, *args, **kwargs):
nodelist = t.nodelist nodelist = t.nodelist
new_context = Context(_dict) new_context = Context(_dict)
csrf_token = django_context.get('csrf_token', None)
if csrf_token is not None:
new_context['csrf_token'] = csrf_token
# **{ # **{
# 'autoescape': context.autoescape, # 'autoescape': context.autoescape,
# 'current_app': context.current_app, # 'current_app': context.current_app,
......
...@@ -274,6 +274,9 @@ djcelery.setup_loader() ...@@ -274,6 +274,9 @@ djcelery.setup_loader()
SIMPLE_WIKI_REQUIRE_LOGIN_EDIT = True SIMPLE_WIKI_REQUIRE_LOGIN_EDIT = True
SIMPLE_WIKI_REQUIRE_LOGIN_VIEW = False SIMPLE_WIKI_REQUIRE_LOGIN_VIEW = False
################################# WIKI ###################################
WIKI_ACCOUNT_HANDLING = False
################################# Jasmine ################################### ################################# Jasmine ###################################
JASMINE_TEST_DIRECTORY = PROJECT_ROOT + '/static/coffee' JASMINE_TEST_DIRECTORY = PROJECT_ROOT + '/static/coffee'
......
...@@ -65,5 +65,7 @@ DEBUG_TOOLBAR_PANELS = ( ...@@ -65,5 +65,7 @@ DEBUG_TOOLBAR_PANELS = (
# Django=1.3.1/1.4 where requests to views get duplicated (your method gets # Django=1.3.1/1.4 where requests to views get duplicated (your method gets
# hit twice). So you can uncomment when you need to diagnose performance # hit twice). So you can uncomment when you need to diagnose performance
# problems, but you shouldn't leave it on. # problems, but you shouldn't leave it on.
# 'debug_toolbar.panels.profiling.ProfilingDebugPanel', 'debug_toolbar.panels.profiling.ProfilingDebugPanel',
) )
#PIPELINE = True
...@@ -27,7 +27,7 @@ ${breadcrumbs.body(article, urlpath)} ...@@ -27,7 +27,7 @@ ${breadcrumbs.body(article, urlpath)}
</ul> </ul>
<div class="tab-content"> <div class="tab-content">
${ render_inclusion(wiki_render, 'wiki/includes/render.html', article ) } ${ render_inclusion(wiki_render, 'wiki/includes/render.html', False, django_context, article ) }
</div> </div>
</div> </div>
......
## mako
<%inherit file="../mako_base.html"/>
<%namespace name='static' file='../../static_content.html'/>
<%!
from wiki.templatetags.wiki_tags import wiki_form
from mitxmako.templatetag_helpers import django_template_include, render_inclusion
%>
<%block name="title"><title>Create root article</title></%block>
<%block name="wiki_headextra">
%for js in editor.Media.js:
<script type="text/javascript" src="${static.url(js)}"></script>
%endfor
%for media, srcs in editor.Media.css.items():
%for src in srcs:
<link rel="stylesheet" media="${ media }" href="${static.url(src)}" />
%endfor
%endfor
</%block>
<%block name="wiki_contents">
<h1>Congratulations!</h1>
<p class="lead"> You have django-wiki installed... but there are no articles. So it's time to create the first one, the root article. In the beginning, it will only be editable by administrators, but you can define permissions after.
</p>
<h2 class="page-header">Root article</h2>
<form method="POST" class="form-horizontal">
${ render_inclusion(wiki_form, 'wiki/includes/form.html', True, django_context, create_form ) }
<div class="form-actions">
<input type="submit" name="save_changes" value="Create root &raquo;" class="btn btn-primary btn-large" />
</div>
</form>
</%block>
## mako
<%inherit file="mako_base.html"/>
<%!
from django.core.urlresolvers import reverse
from mitxmako.templatetag_helpers import django_template_include, render_inclusion
from wiki.templatetags.wiki_tags import wiki_form
%>
<%block name="title"><title>Add new article</title></%block>
<%block name="wiki_contents">
${django_template_include("wiki/includes/editormedia.html", context)}
<h1 class="page-header">Add new article</h1>
<form method="POST" class="form-horizontal">
${ render_inclusion(wiki_form, 'wiki/includes/form.html', True, django_context, create_form ) }
<div class="form-actions">
<a href="${reverse('wiki:get', kwargs={'path' : parent_urlpath.path})}" class="btn btn-large">
<span class="icon-circle-arrow-left"></span>
Go back
</a>
<button type="submit" name="save_changes" class="btn btn-primary btn-large">
<span class="icon-plus"></span>
Create article
</button>
</div>
</form>
</%block>
...@@ -30,11 +30,11 @@ ${breadcrumbs.body(article, urlpath)} ...@@ -30,11 +30,11 @@ ${breadcrumbs.body(article, urlpath)}
<form method="POST" class="form-horizontal"> <form method="POST" class="form-horizontal">
${django_template_include("wiki/includes/editor.html", context)} ${django_template_include("wiki/includes/editor.html", context)}
<div class="form-actions"> <div class="form-actions">
<button type="submit" name="preview" value="1" class="btn btn-large" onclick="$('#previewModal').modal('show'); this.form.target='previewWindow'; this.form.action='${reverse('wiki:preview_url', kwargs={'path' : urlpath.path})}'"> <button type="submit" name="preview" value="1" class="btn btn-large" onclick="$('#previewModal').modal('show'); this.form.target='previewWindow'; this.form.action='${reverse('wiki:preview', kwargs={'path' : urlpath.path})}'">
<span class="icon-eye-open"></span> <span class="icon-eye-open"></span>
Preview Preview
</button> </button>
<button type="submit" name="save" value="1" class="btn btn-large btn-primary" onclick="this.form.target=''; this.form.action='${reverse('wiki:edit_url', kwargs={'path' : urlpath.path})}'"> <button type="submit" name="save" value="1" class="btn btn-large btn-primary" onclick="this.form.target=''; this.form.action='${reverse('wiki:edit', kwargs={'path' : urlpath.path})}'">
<span class="icon-ok"></span> <span class="icon-ok"></span>
Save changes Save changes
</button> </button>
...@@ -54,7 +54,7 @@ ${breadcrumbs.body(article, urlpath)} ...@@ -54,7 +54,7 @@ ${breadcrumbs.body(article, urlpath)}
<span class="icon-circle-arrow-left"></span> <span class="icon-circle-arrow-left"></span>
Back to editor Back to editor
</a> </a>
<button type="submit" name="save" value="1" class="btn btn-large btn-primary" onclick="this.form.target=''; this.form.action='${reverse('wiki:edit_url', kwargs={'path' : urlpath.path})}'"> <button type="submit" name="save" value="1" class="btn btn-large btn-primary" onclick="this.form.target=''; this.form.action='${reverse('wiki:edit', kwargs={'path' : urlpath.path})}'">
<span class="icon-ok"></span> <span class="icon-ok"></span>
Save changes Save changes
</button> </button>
......
...@@ -2,18 +2,11 @@ ...@@ -2,18 +2,11 @@
<%page args="selected, article, plugins" /> <%page args="selected, article, plugins" />
<%! from django.core.urlresolvers import reverse %> <%! from django.core.urlresolvers import reverse %>
<%
if urlpath:
tab_reverse = lambda name, kwargs={}: reverse(name, kwargs=dict({'path' : urlpath.path}, **kwargs))
else:
tab_reverse = lambda name, kwargs={}: reverse(name, kwargs=dict({'article_id' : article.id}, **kwargs))
%>
%for plugin in article_tabs:
%for plugin in plugins:
%if hasattr(plugin, "article_tab"): %if hasattr(plugin, "article_tab"):
<li class="pull-right{% if selected == plugin.slug %} active{% endif %}"> <li class="pull-right${"active" if selected == plugin.slug else ""}">
<a href="${tab_reverse('wiki:plugin_url', kwargs={'slug' : plugin.slug}) }"> <a href="${reverse('wiki:plugin', kwargs={'slug' : plugin.slug, 'article_id' : article.id, 'path' : urlpath.path}) }">
<span class="${plugin.article_tab[1]}"></span> <span class="${plugin.article_tab[1]}"></span>
${plugin.article_tab[0]} ${plugin.article_tab[0]}
</a> </a>
...@@ -25,26 +18,26 @@ ...@@ -25,26 +18,26 @@
<li class="pull-right${"active" if selected == "settings" else ""}"> <li class="pull-right${"active" if selected == "settings" else ""}">
%if not user.is_anonymous: %if not user.is_anonymous:
<a href="${tab_reverse('wiki:settings_url')}"> <a href="${reverse('wiki:settings', kwargs={'article_id' : article.id, 'path' : urlpath.path})}">
<span class="icon-wrench"></span> <span class="icon-wrench"></span>
Settings Settings
</a> </a>
%endif %endif
</li> </li>
<li class="pull-right${"active" if selected == "history" else ""}"> <li class="pull-right${"active" if selected == "history" else ""}">
<a href="${tab_reverse('wiki:history_url')}"> <a href="${reverse('wiki:history', kwargs={'article_id' : article.id, 'path' : urlpath.path})}">
<span class="icon-time"></span> <span class="icon-time"></span>
Changes Changes
</a> </a>
</li> </li>
<li class="pull-right${"active" if selected == "edit" else ""}"> <li class="pull-right${"active" if selected == "edit" else ""}">
<a href="${tab_reverse('wiki:edit_url')}"> <a href="${reverse('wiki:edit', kwargs={'article_id' : article.id, 'path' : urlpath.path})}">
<span class="icon-edit"></span> <span class="icon-edit"></span>
Edit Edit
</a> </a>
</li> </li>
<li class="pull-right${"active" if selected == "view" else ""}"> <li class="pull-right${"active" if selected == "view" else ""}">
<a href="${tab_reverse('wiki:get_url')}"> <a href="${reverse('wiki:get', kwargs={'article_id' : article.id, 'path' : urlpath.path})}">
<span class="icon-home"></span> <span class="icon-home"></span>
View View
</a> </a>
......
...@@ -6,10 +6,10 @@ ...@@ -6,10 +6,10 @@
<ul class="breadcrumb pull-left" class=""> <ul class="breadcrumb pull-left" class="">
%for ancestor in urlpath.get_ancestors(): %for ancestor in urlpath.get_ancestors():
<span class="divider">/</span> <span class="divider">/</span>
<li><a href="${reverse('wiki:get_url', ancestor.path)}">${ ancestor.article.current_revision.title }</a></li> <li><a href="${reverse('wiki:get', ancestor.path)}">${ ancestor.article.current_revision.title }</a></li>
%endfor %endfor
<span class="divider">/</span> <span class="divider">/</span>
<li class="active"><a href="${reverse('wiki:get_url', kwargs={'path' : urlpath.path})}">${ article.current_revision.title }</a></li> <li class="active"><a href="${reverse('wiki:get', kwargs={'path' : urlpath.path})}">${ article.current_revision.title }</a></li>
<span class="divider">/</span> <span class="divider">/</span>
</ul> </ul>
<div class="pull-left" style="margin-left: 10px;"> <div class="pull-left" style="margin-left: 10px;">
...@@ -22,7 +22,7 @@ ...@@ -22,7 +22,7 @@
%if len(urlpath.get_children()) > 0: %if len(urlpath.get_children()) > 0:
%for child in urlpath.get_children(): %for child in urlpath.get_children():
<li> <li>
<a href="${reverse('wiki:get_url', child.path)}"> <a href="${reverse('wiki:get', child.path)}">
${child.article.current_revision.title} ${child.article.current_revision.title}
</a> </a>
</li> </li>
...@@ -38,7 +38,7 @@ ...@@ -38,7 +38,7 @@
</div> </div>
</div> </div>
<div class="pull-left" style="margin-left: 10px;"> <div class="pull-left" style="margin-left: 10px;">
<a class="btn" href="${reverse('wiki:create_url', kwargs={'path' : urlpath.path})}" style="padding: 7px;"> <a class="btn" href="${reverse('wiki:create', kwargs={'path' : urlpath.path})}" style="padding: 7px;">
<span class="icon-plus"></span> <span class="icon-plus"></span>
Add article Add article
</a> </a>
......
...@@ -4,6 +4,9 @@ ...@@ -4,6 +4,9 @@
<%block name="headextra"> <%block name="headextra">
<%static:css group='course'/> <%static:css group='course'/>
<%block name="wiki_headextra" />
</%block> </%block>
<%block name="bodyextra"> <%block name="bodyextra">
......
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