Mercurial > agora
changeset 194:50ba20441122
Added comment template files and customized comments app files
author | ahsanalishahid <ahsan.ali.shahid@gmail.com> |
---|---|
date | Tue, 02 Jul 2013 02:04:09 +0500 |
parents | fe51ec4eccc1 |
children | baf8776dc44d |
files | apps/treecomments/__init__.py apps/treecomments/forms.py apps/treecomments/models.py apps/treecomments/tests.py apps/treecomments/views.py comments/form.html comments/list.html comments/rawcomment.html |
diffstat | 8 files changed, 148 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /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
--- /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
--- /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'] + +
--- /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)
--- /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.
--- /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 %} + + +<form action="{% comment_form_target %}" method="post"> + {% csrf_token %} + {{ form.object_pk }} + {{ form.content_type }} + {{ form.timestamp }} + {{ form.security_hash }} + {# if it is has a parent #} + + {% if node.id %} + <input type="hidden" name="parent" id="parent_id" value="{{ node.id }}" /> + <input type = 'button' value = "Reply" onClick= "$(this).ShowCommentForm({{ node.id }})" id = "{{ node.id }}-button" + class = "reply-button"/> + + {% endif %} + <!-- I have used node id over here so that I can show/hide comment field --> + <div class = "comment-box" style="{% if node.id %}display:none {% else %} display:block {%endif%}" id = "{{ node.id }}" > + <h4> + {%if node.id%} + Reply: + {%else%} Comment: + {%endif%} + </h4> + {{form.comment}} + + <br/> + <input type="submit" value = "Submit" class = 'reply-button' > + </div> + + + +</form>
--- /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 +<dl id="comments"> + {% for comment in comment_list %} + <dt id="c{{ comment.id }}"> + {{ comment.submit_date }} - {{ comment.name }} + </dt> + <dt> {{ comment.user_name }} </dt> + <dt> {{ comment.ip_address }} </dt> + <dt> {{ comment.user_email }} </dt> + <dd> + <p>{{ comment.user_url }}</p> + </dd> + {% endfor %} +</dl>
--- /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 %} +<div id = "comment"> + + + +{% if user.is_authenticated %} + + +{% render_comment_form for object %} + +{% get_comment_list for object as comments %} + +{% if comments %} +{% recursetree comments %} + <a name = "c{{ node.id }}"> </a> + <!-- {{ node.id }} --> + <div class = "comment-node"> + + <p class = "comment-bar"><a href = "{{ object.get_absolute_url }}#c{{ node.id }}"><strong>{{ node.user }} </strong> ยท {{ node.submit_date|timesince }} ago </a> </p> + <p class = "comment"><p class = "comment-body"> {{ node.comment }} </p> + + + + + + {% render_comment_form for object %} +</div> + {# recursion tree logic #} + {% if not node.is_leaf_node %} + <div class = "comment-node-child"> + {{ children }} +</div> + {% endif %} + +{% endrecursetree %} +{% endif%} + +{% else %} + <h4>You need to be logged in to see comments</h4> + +{% endif%} + +</div> \ No newline at end of file