Fix news preview with CSRF and AJAX in Django 1.2.5

Signed-off-by: Dan McGee <dan@archlinux.org>
This commit is contained in:
Dan McGee 2011-03-20 15:51:02 -05:00
parent aca7700dd7
commit b9c6451f88
2 changed files with 12 additions and 10 deletions

View File

@ -71,16 +71,18 @@ if (typeof $.tablesorter !== 'undefined') {
/* news/add.html */
function enablePreview() {
$('#previewbtn').click(function(event) {
$('#news-preview-button').click(function(event) {
event.preventDefault();
$.post('/news/preview/',
{ data: $('#id_content').val() },
$.post('/news/preview/', {
data: $('#id_content').val(),
csrfmiddlewaretoken: $('#newsform input[name=csrfmiddlewaretoken]').val()
},
function(data) {
$('#previewdata').html(data);
$('.news-article').show();
$('#news-preview-data').html(data);
$('#news-preview').show();
}
);
$('#previewtitle').html($('#id_title').val());
$('#news-preview-title').html($('#id_title').val());
});
}

View File

@ -23,14 +23,14 @@ <h2>News: Add Article</h2>
<p>
<label></label>
<input title="Save changes" type="submit" value="Save" />
<input id="previewbtn" title="Preview" type="button" value="Preview" />
<input id="news-preview-button" title="Preview" type="button" value="Preview" />
</p>
</form>
</div>
<div class="news-article box" style="display:none;">
<h2>News Preview: <span id="previewtitle"></span></h2>
<div id="previewdata" class="article-content"></div>
<div id="news-preview" class="news-article box" style="display:none;">
<h2>News Preview: <span id="news-preview-title"></span></h2>
<div id="news-preview-data" class="article-content"></div>
</div>
{% load cdn %}{% jquery %}
<script type="text/javascript" src="/media/archweb.js"></script>