remove django-markdown and handle preview manually

This commit is contained in:
Élie Bouttier 2014-09-06 00:39:50 -07:00
parent 4995c19560
commit 7e3173c7c0
32 changed files with 335 additions and 16478 deletions

View file

@ -1,7 +1,6 @@
from django import forms
from bootstrap3_datetime.widgets import DateTimePicker
from django_markdown.widgets import MarkdownWidget
from tracker.models import *
@ -23,11 +22,11 @@ class ProjectForm(forms.ModelForm):
class IssueForm(forms.Form):
title = forms.CharField(max_length=128)
description = forms.CharField(widget=MarkdownWidget, required=False)
description = forms.CharField(widget=forms.Textarea, required=False)
class CommentForm(forms.Form):
comment = forms.CharField(widget=MarkdownWidget)
comment = forms.CharField(widget=forms.Textarea)
class LabelForm(forms.ModelForm):

View file

@ -0,0 +1,25 @@
var csrftoken = $.cookie('csrftoken');
function csrfSafeMethod(method) {
// these HTTP methods do not require CSRF protection
return (/^(GET|HEAD|OPTIONS|TRACE)$/.test(method));
}
$.ajaxSetup({
beforeSend: function(xhr, settings) {
if (!csrfSafeMethod(settings.type) && !this.crossDomain) {
xhr.setRequestHeader("X-CSRFToken", csrftoken);
}
}
});
$('a[href="#preview"]').on("show.bs.tab", function (e) {
$('#preview-content').html('Loading preview...');
var comment = $('#markdown-content').val();
$.post(markdown_preview_url, {'data': comment})
.done(function(data, textStatus) {
$('#preview-content').html(data);
})
.fail(function () {
$('#preview-content').html('Sorry, an error occured.');
});
})

View file

@ -0,0 +1,11 @@
from django import template
from tracker.utils import markdown_to_html
register = template.Library()
@register.filter
def markdown(value):
return markdown_to_html(value)

View file

@ -2,6 +2,7 @@ from django.conf.urls import url, include
urlpatterns = [
url(r'^markdown/$', 'tracker.views.markdown_preview', name='markdown'),
# Administration: redirect on first available admin page
url(r'^admin/$', 'tracker.views.admin', name='admin'),
# Settings

8
tracker/utils.py Normal file
View file

@ -0,0 +1,8 @@
from django.utils.safestring import mark_safe
from markdown import markdown
def markdown_to_html(value):
# set extensions here if needed
return mark_safe(markdown(value, safe_mode='escape'))

View file

@ -5,7 +5,9 @@ from django.contrib.auth.decorators import login_required
from django.views.decorators.http import require_http_methods
from django.conf import settings
from django.core.urlresolvers import reverse
from django.http import HttpResponse
from tracker.utils import markdown_to_html
from tracker.forms import *
from tracker.models import *
from tracker.notifications import *
@ -16,6 +18,16 @@ from permissions.decorators import project_perm_required
import shlex
####################
# Markdown preview #
####################
@login_required
def markdown_preview(request):
content = request.POST.get('data', '')
return HttpResponse(markdown_to_html(content))
#########
# Admin #
#########