Commits

funkybob  committed 6e0edf0

Include relevant fields in comment form
Re-order postmixin to take precedence
Fixed META parameter name
Set IP on comment save

  • Participants
  • Parent commits daf8f33

Comments (0)

Files changed (2)

File gnocchi_blog/forms.py

         return data
 
 class CommentForm(recaptcha.RecaptchaForm):
+    user_name = forms.CharField(max_length=50)
+    user_email = forms.EmailField()
+    content = forms.CharField(widget=forms.TextArea)
     captcha = recaptcha.RecaptchaField()
     class Meta:
         model = models.Comment

File gnocchi_blog/views.py

 class PostMixin(object):
     date_field = 'post_date'
     slug_field = 'slug'
+    model = models.Post
     username = None
 
     def get_queryset(self):
             qset = qset.filter(tags__in=tags)
         return qset
 
-class PostList(ArchiveIndexView, PostMixin):
+class PostList(PostMixin, ArchiveIndexView):
     template_name = 'blog/post_list.html'
-    model = models.Post
 
-class PostDetail(DateDetailView, PostMixin):
+class PostDetail(PostMixin, DateDetailView):
     template_name = 'blog/post_detail.html'
-    model = models.Post
 
     def post(self, request, *args, **kwargs):
         self.object = self.get_object()
-        form = forms.CommentForm(request.META['REQUEST_ADDR'], request.POST)
+        form = forms.CommentForm(request.META['REMOTE_ADDR'], request.POST)
         if form.is_valid():
             comment = form.save(commit=False)
             comment.post = self.object
+            comment.ip_address = reqpoest.META['REMOTE_ADDR']
             if request.user.is_authenticated():
                 comment.user = request.user
             comment.save()
     def get_context_data(self, **kwargs):
         context = super(PostDetail, self).get_context_data(**kwargs)
         if not self.request.method == 'POST':
-            context['comment_form'] = forms.CommentForm()
+            context['comment_form'] = forms.CommentForm(self.request.META['REMOTE_ADDR'])
         return context