Add support for editing posts
This commit is contained in:
@@ -10,6 +10,8 @@ urlpatterns = patterns('forums',
|
||||
url(r'^sticky/(?P<topicID>.*)', 'views.stickyTopic'),
|
||||
url(r'^reply/(?P<topicID>.*)', 'views.reply'),
|
||||
url(r'^reply$', 'views.reply'),
|
||||
url(r'^edit/(?P<postID>.*)', 'views.editPost'),
|
||||
url(r'^edit$', 'views.editPost'),
|
||||
url(r'^post/(?P<id>.*)$', 'views.post'),
|
||||
url(r'^preview$', 'views.preview'),
|
||||
)
|
||||
|
@@ -7,6 +7,7 @@ from django.shortcuts import render_to_response
|
||||
from django.http import HttpResponseRedirect
|
||||
from django.template import RequestContext
|
||||
from django.core.urlresolvers import reverse
|
||||
from django.core.exceptions import PermissionDenied
|
||||
from notification import models as notification
|
||||
|
||||
def index(request):
|
||||
@@ -44,7 +45,7 @@ def reply(request, topicID=None):
|
||||
notification.send([reply.parent.user], "forum_reply", {"reply": reply, 'notice_url': reverse('forums.views.post', kwargs={'id':reply.id}), 'notice_description': reply.topic().title})
|
||||
messages.info(request, "Reply successful")
|
||||
return HttpResponseRedirect(reverse('forums.views.post', kwargs={"id":reply.id}))
|
||||
return render_to_response('forums/reply.html', {"post":parentPost, "form":form}, context_instance = RequestContext(request))
|
||||
return render_to_response('forums/reply.html', {"parent":parentPost, "form":form}, context_instance = RequestContext(request))
|
||||
|
||||
@login_required
|
||||
def newTopic(request, forumID=None):
|
||||
@@ -83,6 +84,25 @@ def newTopic(request, forumID=None):
|
||||
return HttpResponseRedirect(reverse('forums.views.post', kwargs={'id': reply.id}))
|
||||
return render_to_response('forums/newTopic.html', {"forum":parentForum, "replyForm":replyForm, "topicForm": topicForm}, context_instance = RequestContext(request))
|
||||
|
||||
@login_required
|
||||
def editPost(request, postID=None):
|
||||
post = models.Post.objects.get(id__exact=postID)
|
||||
if post.user != request.user and not request.user.has_perm('edit_posts'):
|
||||
raise PermissionDenied
|
||||
if request.method == 'POST':
|
||||
form = forms.ReplyForm(request.POST)
|
||||
else:
|
||||
form = forms.ReplyForm(instance=post)
|
||||
|
||||
if form.is_valid():
|
||||
post.body = form.cleaned_data['body']
|
||||
post.save()
|
||||
messages.info(request, "Post updated.")
|
||||
return HttpResponseRedirect(reverse('forums.views.post',
|
||||
kwargs={"id":post.id}))
|
||||
return render_to_response('forums/edit.html', {"post": post, "parent":
|
||||
post.parent, "form": form}, context_instance = RequestContext(request))
|
||||
|
||||
@permission_required('forums.delete_topic')
|
||||
def deleteTopic(request, topicID):
|
||||
topic = models.Topic.objects.get(id__exact=topicID)
|
||||
|
@@ -15,5 +15,8 @@ Edited {{post.updated}}
|
||||
<br style="clear:both"/>
|
||||
<a href="{% url forums.views.post id=post.id%}">permalink</a>
|
||||
<a href="{%url forums.views.reply post.id%}">Reply »</a>
|
||||
{% if post.user == user or perms.forums.edit_posts %}
|
||||
<a href="{%url forums.views.editPost post.id%}">Edit »</a>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
|
10
templates/forums/edit.html
Normal file
10
templates/forums/edit.html
Normal file
@@ -0,0 +1,10 @@
|
||||
{% extends "forums/reply.html" %}
|
||||
|
||||
{% block form %}
|
||||
{{post}}
|
||||
<form method="POST" action="{% url forums.views.editPost postID=post.pk %}">
|
||||
{% csrf_token %}
|
||||
{{form.as_p}}
|
||||
<input type="submit" value="Submit"/>
|
||||
</form>
|
||||
{% endblock %}
|
@@ -19,16 +19,20 @@ $(function() {
|
||||
{% endblock %}
|
||||
|
||||
{%block content%}
|
||||
{% if parent %}
|
||||
<div class="item">
|
||||
<h2>Replying to:</h2>
|
||||
{% include 'forums/_reply.html' with post=post %}
|
||||
{% include 'forums/_reply.html' with post=parent%}
|
||||
</div>
|
||||
{% endif %}
|
||||
<div class="item">
|
||||
{% block form %}
|
||||
<form method="POST" action="{%url forums.views.reply post.id %}">
|
||||
{% csrf_token %}
|
||||
{{form.as_p}}
|
||||
<input type="submit" value="Submit"/>
|
||||
</form>
|
||||
{% endblock %}
|
||||
</div>
|
||||
<div class="item" id="forum-preview">
|
||||
</div>
|
||||
|
Reference in New Issue
Block a user