Custom Search

Tuesday, March 2, 2010

Django Customizing the comments framework

Django Customizing the comments framework

****************************************

{% render_comment_form for message %}

****************************************

{% get_comment_form for message as form %}

<form action="{% comment_form_target %}" method="POST">
{{ form }}
<tr>
<td></td>
<td><input type="submit" name="preview" class="submit-post" value="Preview"></td>
</tr>
</form>


****************************************

<form action=" {% comment_form_target %} " method="POST">

{% for field in form %}

{% if field.is_hidden %}

{{ field }}

{% else %}

<p

{% if field.errors %} class="error"{% endif %}

{% ifequal field.name "honeypot" %}
style="display:none;"{% endifequal %}>

{% if field.errors %}{{ field.errors }}{% endif %}

{{ field.label_tag }} {{ field }}

</p>

****************************************

{% get_comment_form for message as form %}

<form action=" {% comment_form_target %} " method="POST">

{% for field in form %}

{% if field.is_hidden %}
{{ field }}
{% endif %}

{% ifequal field.name "comment" %} {{ field }}{% endifequal %}

{% endfor %}
<p class="submit">
<input type="submit" value="Post" class="submit-post" name="post">
<input type="submit" value="Preview" class="submit-preview" name="preview">
</p>
</form>

****************************************

You can remove fields from templates (from html). They indeed should
be removed if you don't want them :)
Then we face a problem: some of CommentForm fields are marked as
required. The solution is to subclass CommentForm and set this flag to
False:

class NoEmailForm(CommentForm):
def __init__(self, target_object, data=None, initial=None):
super(NoEmailForm, self).__init__(target_object, data,
initial)
self.fields['email'].required = False

****************************************

BaseCommentAbstractModel

****************************************working

{% get_comment_form for message as form %}

<form action=" {% comment_form_target %} " method="POST">

{% for field in form %}

{% if field.is_hidden %}
{{ field }}
{% endif %}

{% ifequal field.name "comment" %} {{ field }}{% endifequal %}

{% endfor %}
<p class="submit">
<input type="submit" value="Post" class="submit-post" name="post">
<!-- <input type="submit" value="Preview" class="submit-preview" name="preview"> -->
</p>
</form>


**************************************** works
<h4>Comments </h4>

{% get_comment_list for message as comment_list %}
{% for comment in comment_list %}
{{ comment.comment }} <br>
{% endfor %}


{% get_comment_form for message as form %}

<form action=" {% comment_form_target %} " method="POST">
<input type="hidden" name="next" value="{% url message_detail project.id message.id %}" />
{% for field in form %}
{% if field.is_hidden %}
{{ field }}
{% endif %}
{% ifequal field.name "comment" %} {{ field }}{% endifequal %}
{% endfor %}
<p class="submit">
<input type="submit" value="Post" class="submit-post" name="post">
<!-- <input type="submit" value="Preview" class="submit-preview" name="preview"> -->
</p>
</form>


****************************************


****************************************

No comments:

Post a Comment