# HG changeset patch # User ahsanalishahid # Date 1372712649 -18000 # Node ID 50ba204411225357018dbede5fb2d311972cbfff # Parent fe51ec4eccc1146ef36c4db14d4887844a2c7cb7 Added comment template files and customized comments app files diff -r fe51ec4eccc1 -r 50ba20441122 apps/treecomments/__init__.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/apps/treecomments/__init__.py Tue Jul 02 02:04:09 2013 +0500 @@ -0,0 +1,9 @@ +from apps.treecomments.models import TreeComments +from apps.treecomments.forms import TreeCommentsForm + +def get_model(): + return TreeComments + +def get_form(): + return TreeCommentsForm + \ No newline at end of file diff -r fe51ec4eccc1 -r 50ba20441122 apps/treecomments/forms.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/apps/treecomments/forms.py Tue Jul 02 02:04:09 2013 +0500 @@ -0,0 +1,15 @@ +from django import forms +from django.contrib.admin import widgets +from django.contrib.comments.forms import CommentForm +from apps.treecomments.models import TreeComments + +class TreeCommentsForm(CommentForm): + parent = forms.ModelChoiceField(queryset=TreeComments.objects.all(), required=False, widget=forms.HiddenInput) + + def get_comment_model(self): + return TreeComments + + def get_comment_create_data(self): + data = super(TreeCommentsForm,self).get_comment_create_data() + data['parent'] = self.cleaned_data['parent'] + return data \ No newline at end of file diff -r fe51ec4eccc1 -r 50ba20441122 apps/treecomments/models.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/apps/treecomments/models.py Tue Jul 02 02:04:09 2013 +0500 @@ -0,0 +1,15 @@ +from django.contrib.comments.models import Comment +from mptt.models import MPTTModel, TreeForeignKey +# Create your models here. + + +class TreeComments(MPTTModel,Comment): + parent = TreeForeignKey('self', null =True, blank=True,related_name='children') + + class MPTTMeta: + order_insertion_by = ['submit_date'] + + class Meta: + ordering = ['tree_id','lft'] + + diff -r fe51ec4eccc1 -r 50ba20441122 apps/treecomments/tests.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/apps/treecomments/tests.py Tue Jul 02 02:04:09 2013 +0500 @@ -0,0 +1,16 @@ +""" +This file demonstrates writing tests using the unittest module. These will pass +when you run "manage.py test". + +Replace this with more appropriate tests for your application. +""" + +from django.test import TestCase + + +class SimpleTest(TestCase): + def test_basic_addition(self): + """ + Tests that 1 + 1 always equals 2. + """ + self.assertEqual(1 + 1, 2) diff -r fe51ec4eccc1 -r 50ba20441122 apps/treecomments/views.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/apps/treecomments/views.py Tue Jul 02 02:04:09 2013 +0500 @@ -0,0 +1,1 @@ +# Create your views here. diff -r fe51ec4eccc1 -r 50ba20441122 comments/form.html --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/comments/form.html Tue Jul 02 02:04:09 2013 +0500 @@ -0,0 +1,34 @@ +{% load comments i18n %} + + +
+ {% csrf_token %} + {{ form.object_pk }} + {{ form.content_type }} + {{ form.timestamp }} + {{ form.security_hash }} + {# if it is has a parent #} + + {% if node.id %} + + + + {% endif %} + +
+

+ {%if node.id%} + Reply: + {%else%} Comment: + {%endif%} +

+ {{form.comment}} + +
+ +
+ + + +
diff -r fe51ec4eccc1 -r 50ba20441122 comments/list.html --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/comments/list.html Tue Jul 02 02:04:09 2013 +0500 @@ -0,0 +1,14 @@ +Override +
+ {% for comment in comment_list %} +
+ {{ comment.submit_date }} - {{ comment.name }} +
+
{{ comment.user_name }}
+
{{ comment.ip_address }}
+
{{ comment.user_email }}
+
+

{{ comment.user_url }}

+
+ {% endfor %} +
diff -r fe51ec4eccc1 -r 50ba20441122 comments/rawcomment.html --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/comments/rawcomment.html Tue Jul 02 02:04:09 2013 +0500 @@ -0,0 +1,44 @@ +{% load comments %} +{% load mptt_tags %} +
+ + + +{% if user.is_authenticated %} + + +{% render_comment_form for object %} + +{% get_comment_list for object as comments %} + +{% if comments %} +{% recursetree comments %} + + +
+ +

{{ node.user }} ยท {{ node.submit_date|timesince }} ago

+

{{ node.comment }}

+ + + + + + {% render_comment_form for object %} +
+ {# recursion tree logic #} + {% if not node.is_leaf_node %} +
+ {{ children }} +
+ {% endif %} + +{% endrecursetree %} +{% endif%} + +{% else %} +

You need to be logged in to see comments

+ +{% endif%} + +
\ No newline at end of file