# HG changeset patch # User ahsanalishahid # Date 1372712649 -18000 # Node ID 50ba204411225357018dbede5fb2d311972cbfff # Parent fe51ec4eccc1146ef36c4db14d4887844a2c7cb7 Added comment template files and customized comments app files diff --git a/apps/treecomments/__init__.py b/apps/treecomments/__init__.py new file mode 100644 --- /dev/null +++ b/apps/treecomments/__init__.py @@ -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 --git a/apps/treecomments/forms.py b/apps/treecomments/forms.py new file mode 100644 --- /dev/null +++ b/apps/treecomments/forms.py @@ -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 --git a/apps/treecomments/models.py b/apps/treecomments/models.py new file mode 100644 --- /dev/null +++ b/apps/treecomments/models.py @@ -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 --git a/apps/treecomments/tests.py b/apps/treecomments/tests.py new file mode 100644 --- /dev/null +++ b/apps/treecomments/tests.py @@ -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 --git a/apps/treecomments/views.py b/apps/treecomments/views.py new file mode 100644 --- /dev/null +++ b/apps/treecomments/views.py @@ -0,0 +1,1 @@ +# Create your views here. diff --git a/comments/form.html b/comments/form.html new file mode 100644 --- /dev/null +++ b/comments/form.html @@ -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 --git a/comments/list.html b/comments/list.html new file mode 100644 --- /dev/null +++ b/comments/list.html @@ -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 --git a/comments/rawcomment.html b/comments/rawcomment.html new file mode 100644 --- /dev/null +++ b/comments/rawcomment.html @@ -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