Electronics & Programming

develissimo

Open Source electronics development and programming

  • You are not logged in.
  • Root
  • » Django
  • » Where's the form value set for comments framework/app [RSS Feed]

#1 Nov. 30, 2010 13:17:03

p.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

Where's the form value set for comments framework/app


Mostly I followed the instruction ofhttp://docs.djangoproject.com/en/dev/ref/contrib/comments/While my code could run as expected, I cannot find when and where the
field values in "form" are set before it's called in line 4~6 of the
form.html as below. What I'm particularly interested in was the
content_type field.

Part of my code looks like this:

detail.html:
21 {% load comments %}
22 {% get_comment_count for topic as comment_count %}
23 <p>{{ comment_count }} comments have been posted. </p>
24
25 {% render_comment_list for topic %}
26
27 {% render_comment_form for topic %}

form.html under templates/comments/
1 {% load comments i18n %}
2 <form action="{% comment_form_target %}" method="post">{%
csrf_token %}
3 {% if next %}<input type="hidden" name="next"
value="{{ next }}" />{% endi f %}
4 {% for field in form %}
5 {% if field.is_hidden %}
6 {{ field }}
...


The source code of form.html when opened in a browser:
...
<form action="/comments/post/" method="post"><div
style='display:none'><input type='hidden' name='csrfmiddlewaretoken'
value='7bc056d8f14034c257c49aa0b38763ce' /></div>

<input type="hidden" name="content_type" value="topics.topic"
id="id_content_type" />
<input type="hidden" name="object_pk" value="1"
id="id_object_pk" />
<input type="hidden" name="timestamp" value="1291103625"
id="id_timestamp" />
<input type="hidden" name="security_hash"
value="a4080f739cd016f4eaa2ed2bfb4b9f5e6c0ed313"
id="id_security_hash" />
...

--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

Offline

#2 Nov. 30, 2010 13:55:03

Daniel R.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

Where's the form value set for comments framework/app


On Nov 30, 8:31 am, photon <photo...@gmail.com> wrote:
> Mostly I followed the instruction
> ofhttp://docs.djangoproject.com/en/dev/ref/contrib/comments/>
> While my code could run as expected, I cannot find when and where the
> field values in "form" are set before it's called in line 4~6 of the
> form.html as below. What I'm particularly interested in was the
> content_type field.
>
> Part of my code looks like this:
>
> detail.html:
>  21 {% load comments %}
>  22 {% get_comment_count for topic as comment_count %}
>  23 <p>{{ comment_count }} comments have been posted. </p>
>  24
>  25 {% render_comment_list for topic %}
>  26
>  27 {% render_comment_form for topic %}
>
> form.html under templates/comments/
>   1 {% load comments i18n %}
>   2 <form action="{% comment_form_target %}" method="post">{%
> csrf_token %}
>   3   {% if next %}<input type="hidden" name="next"
> value="{{ next }}" />{% endi    f %}
>   4   {% for field in form %}
>   5     {% if field.is_hidden %}
>   6       {{ field }}
> ...
>
> The source code of form.html when opened in a browser:
> ...
> <form action="/comments/post/" method="post"><div
> style='display:none'><input type='hidden' name='csrfmiddlewaretoken'
> value='7bc056d8f14034c257c49aa0b38763ce' /></div>
>
>       <input type="hidden" name="content_type" value="topics.topic"
> id="id_content_type" />
>       <input type="hidden" name="object_pk" value="1"
> id="id_object_pk" />
>       <input type="hidden" name="timestamp" value="1291103625"
> id="id_timestamp" />
>       <input type="hidden" name="security_hash"
> value="a4080f739cd016f4eaa2ed2bfb4b9f5e6c0ed313"
> id="id_security_hash" />
> ...

It's done by the render_comment_form tag itself, which is in
django.contrib.comments.templatetags.comments.
--
DR.

--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

Offline

#3 Dec. 1, 2010 07:26:15

p.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

Where's the form value set for comments framework/app


I looked into the code again and think I've found where the values
come from.

class CommentFormNode(BaseCommentNode):
"""Insert a form for the comment model into the context."""
...
return comments.get_form()
(ctype.get_object_for_this_type(pk=object_pk))

The comments.get_form() will return a CommentForm, which is a child
class of CommentSecurityForm from django.contrib.comments.form

class CommentSecurityForm(forms.Form):
...
def generate_security_data(self):
...
security_dict = {
'content_type' : str(self.target_object._meta),
'object_pk' : str(self.target_object._get_pk_val()),
'timestamp' : str(timestamp),
'security_hash' : self.initial_security_hash(timestamp),
}

So the content_type value is from target_object._meta

On Nov 30, 4:31 pm, photon <photo...@gmail.com> wrote:
> Mostly I followed the instruction
> ofhttp://docs.djangoproject.com/en/dev/ref/contrib/comments/--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

Offline

  • Root
  • » Django
  • » Where's the form value set for comments framework/app [RSS Feed]

Board footer

Moderator control

Enjoy the 11th of December
PoweredBy

The Forums are managed by develissimo stuff members, if you find any issues or misplaced content please help us to fix it. Thank you! Tell us via Contact Options
Leave a Message
Welcome to Develissimo Live Support