comments now submit to own view

This commit is contained in:
James Turk 2009-02-26 12:41:07 -05:00
parent 09a0b5da5d
commit 04440d740b
3 changed files with 42 additions and 4 deletions

View File

@ -29,9 +29,24 @@
{% endfor %}
</ol>
{% get_comment_form for idea as comment_form %}
<form method="post" action="{% comment_form_target %}">
{{ comment_form.as_p }}
<form method="post" action="{% url submit_idea_comment %}">
<input name="idea_id" type="hidden" value="{{idea.id}}" />
<p>
<label for="name">Name</label>
<input id="name" class="text" type="text" name="name" size="50"/>
</p>
<p>
<label for="email">Email</label>
<input id="email" class="text" type="text" name="email" size="50"/>
</p>
<p>
<label for="url">URL</label>
<input id="url" class="text" type="text" name="url" size="50"/>
</p>
<p id="commentForm">
<label for="comment">Comment</label>
<textarea class="textarea" name="comment" cols="48" rows="12"></textarea>
</p>
<button class="btnSubmit" type="submit">Submit</button>
</form>
</div>

View File

@ -14,6 +14,7 @@ urlpatterns = patterns('',
)
urlpatterns += patterns('brainstorm.views',
url(r'^submit_comment/$', 'submit_comment', name='submit_idea_comment'),
url(r'^(?P<slug>[\w-]+)/$', 'idea_list', {'ordering': 'most_popular'}, name='subsite'),
url(r'^(?P<slug>[\w-]+)/latest/$', 'idea_list', {'ordering': 'latest'}, name='subsite_latest'),
url(r'^(?P<slug>[\w-]+)/(?P<id>\d+)/$', 'idea_detail', name='idea'),

View File

@ -1,7 +1,11 @@
import datetime
from django.template import RequestContext
from django.core.paginator import Paginator, InvalidPage, EmptyPage
from django.core.urlresolvers import reverse
from django.shortcuts import get_object_or_404, render_to_response
from django.http import HttpResponseRedirect
from django.contrib.comments.models import Comment
from django.contrib.contenttypes.models import ContentType
from django.views.decorators.http import require_POST
from brainstorm.models import Subsite, Idea
@ -36,7 +40,6 @@ def idea_detail(request, slug, id):
{'subsite':subsite, 'idea': idea},
context_instance=RequestContext(request))
@require_POST
def new_idea(request, slug):
subsite = get_object_or_404(Subsite, pk=slug)
@ -50,3 +53,22 @@ def new_idea(request, slug):
idea = Idea.objects.create(title=title, description=description,
user=user, subsite=subsite)
return HttpResponseRedirect(idea.get_absolute_url())
@require_POST
def submit_comment(request):
from django.conf import settings
content_type = ContentType.objects.get_for_model(Idea).id
site = settings.SITE_ID
object_pk = request.POST['idea_id']
name = request.POST.get('name', 'anonymous')
email = request.POST.get('email', '')
url = request.POST.get('url', '')
comment = request.POST['comment']
date = datetime.datetime.now()
ip = request.META['REMOTE_ADDR']
c = Comment.objects.create(user_name=name, user_email=email, user_url=url,
comment=comment, submit_date=date, ip_address=ip,
site_id=site, content_type_id=content_type, object_pk=object_pk)
idea = Idea.objects.get(pk=object_pk)
linkback = '%s#c%s' % (idea.get_absolute_url(), c.id)
return HttpResponseRedirect(linkback)