Re: how to save response 's render file to server or email using httpresponse

2012-07-03 Thread Min Hong Tan
\(^o^)/

On Tue, Jul 3, 2012 at 4:53 PM, Nikolas Stevenson-Molnar <
nik.mol...@consbio.org> wrote:

>  You are welcome. Glad you got it working :)
>
> _Nik
>
>
> On 7/3/2012 3:33 PM, Min Hong Tan wrote:
>
> Thx nik,
>
>  I'm confused , your words has aroused me  from the word.
> "You won't use HttpResponse at all, just EmailMessage (using
> message.attach). "
>
>  problem solved by using below:
>
>
>
>  from io import BytesIO
>
>
>
>  buffer = BytesIO()
> book.save(buffer)
> excel = buffer.getvalue()
> buffer.close()
>
>  and just
>
>
> mail.attach(filename="testing.xls",content=excel,mimetype="application/ms-excel")
>
>  mail.send()
>
>  and mission accomplished!!
>
>
>
>
> On Tue, Jul 3, 2012 at 2:59 PM, Nikolas Stevenson-Molnar <
> nik.mol...@consbio.org> wrote:
>
>>  You'll need to use EmailMessage:
>> https://docs.djangoproject.com/en/dev/topics/email/?from=olddocs/#django.core.mail.EmailMessage
>>
>> You won't use HttpResponse at all, just EmailMessage (using
>> message.attach).
>>
>> _Nik
>>
>>
>> On 7/3/2012 1:34 PM, Min Hong Tan wrote:
>>
>> sorry all, maybe i'm not type why i need the httpresponse to be attach.
>>
>>  response = HttpResponse(mimetype='application/pdf')
>> response['Content-Disposition'] = 'attaachment; filename=report.pdf'
>>
>>  i'm generating the pdf file in response. and normally i will return
>> response and it should be perfect with the pdf file download.
>>
>>  but, how if i want to attach it and send out the mail?
>>
>> On Tue, Jul 3, 2012 at 12:32 PM, Nikolas Stevenson-Molnar <
>> nik.mol...@consbio.org> wrote:
>>
>>> Oh, and HttpResponse is intended to send data back to a web browser. I
>>> can't think of any reason you would use an HttpResponse when sending an
>>> email.
>>>
>>> _Nik
>>>
>>> On 7/3/2012 11:20 AM, Min Hong Tan wrote:
>>>  > hi,
>>> >
>>> > I have a problem to send mail using Emailmessage,
>>> > i wan to attach the file that render using httpresponse and send, but
>>> > always show me "int" does not have method "lower".
>>> > therefore, I think to save the file in the server and then attach
>>> > using emailmessage.  but how do i get the httpresonse to save
>>> > in server /tmp/file  ?
>>> >
>>> > Regards,
>>> > MH
>>>   > --
>>> > You received this message because you are subscribed to the Google
>>> > Groups "Django users" group.
>>> > To post to this group, send email to django-users@googlegroups.com.
>>> > To unsubscribe from this group, send email to
>>> > django-users+unsubscr...@googlegroups.com.
>>> > For more options, visit this group at
>>> > http://groups.google.com/group/django-users?hl=en.
>>>
>>>
>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "Django users" group.
>>> To post to this group, send email to django-users@googlegroups.com.
>>> To unsubscribe from this group, send email to
>>> django-users+unsubscr...@googlegroups.com.
>>> For more options, visit this group at
>>> http://groups.google.com/group/django-users?hl=en.
>>>
>>>
>>  --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To post to this group, send email to django-users@googlegroups.com.
>> To unsubscribe from this group, send email to
>> django-users+unsubscr...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/django-users?hl=en.
>>
>>
>>
>>--
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To post to this group, send email to django-users@googlegroups.com.
>> To unsubscribe from this group, send email to
>> django-users+unsubscr...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/django-users?hl=en.
>>
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>

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



Re: how to save response 's render file to server or email using httpresponse

2012-07-03 Thread Min Hong Tan
Thx nik,

I'm confused , your words has aroused me  from the word.
"You won't use HttpResponse at all, just EmailMessage (using
message.attach). "

problem solved by using below:



from io import BytesIO



buffer = BytesIO()
book.save(buffer)
excel = buffer.getvalue()
buffer.close()

and just

mail.attach(filename="testing.xls",content=excel,mimetype="application/ms-excel")

mail.send()

and mission accomplished!!




On Tue, Jul 3, 2012 at 2:59 PM, Nikolas Stevenson-Molnar <
nik.mol...@consbio.org> wrote:

>  You'll need to use EmailMessage:
> https://docs.djangoproject.com/en/dev/topics/email/?from=olddocs/#django.core.mail.EmailMessage
>
> You won't use HttpResponse at all, just EmailMessage (using
> message.attach).
>
> _Nik
>
>
> On 7/3/2012 1:34 PM, Min Hong Tan wrote:
>
> sorry all, maybe i'm not type why i need the httpresponse to be attach.
>
>  response = HttpResponse(mimetype='application/pdf')
> response['Content-Disposition'] = 'attaachment; filename=report.pdf'
>
>  i'm generating the pdf file in response. and normally i will return
> response and it should be perfect with the pdf file download.
>
>  but, how if i want to attach it and send out the mail?
>
> On Tue, Jul 3, 2012 at 12:32 PM, Nikolas Stevenson-Molnar <
> nik.mol...@consbio.org> wrote:
>
>> Oh, and HttpResponse is intended to send data back to a web browser. I
>> can't think of any reason you would use an HttpResponse when sending an
>> email.
>>
>> _Nik
>>
>> On 7/3/2012 11:20 AM, Min Hong Tan wrote:
>>  > hi,
>> >
>> > I have a problem to send mail using Emailmessage,
>> > i wan to attach the file that render using httpresponse and send, but
>> > always show me "int" does not have method "lower".
>> > therefore, I think to save the file in the server and then attach
>> > using emailmessage.  but how do i get the httpresonse to save
>> > in server /tmp/file  ?
>> >
>> > Regards,
>> > MH
>>   > --
>> > You received this message because you are subscribed to the Google
>> > Groups "Django users" group.
>> > To post to this group, send email to django-users@googlegroups.com.
>> > To unsubscribe from this group, send email to
>> > django-users+unsubscr...@googlegroups.com.
>> > For more options, visit this group at
>> > http://groups.google.com/group/django-users?hl=en.
>>
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To post to this group, send email to django-users@googlegroups.com.
>> To unsubscribe from this group, send email to
>> django-users+unsubscr...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/django-users?hl=en.
>>
>>
>  --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>

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



Re: how to save response 's render file to server or email using httpresponse

2012-07-03 Thread Min Hong Tan
sorry all, maybe i'm not type why i need the httpresponse to be attach.

response = HttpResponse(mimetype='application/pdf')
response['Content-Disposition'] = 'attaachment; filename=report.pdf'

i'm generating the pdf file in response. and normally i will return
response and it should be perfect with the pdf file download.

but, how if i want to attach it and send out the mail?

On Tue, Jul 3, 2012 at 12:32 PM, Nikolas Stevenson-Molnar <
nik.mol...@consbio.org> wrote:

> Oh, and HttpResponse is intended to send data back to a web browser. I
> can't think of any reason you would use an HttpResponse when sending an
> email.
>
> _Nik
>
> On 7/3/2012 11:20 AM, Min Hong Tan wrote:
> > hi,
> >
> > I have a problem to send mail using Emailmessage,
> > i wan to attach the file that render using httpresponse and send, but
> > always show me "int" does not have method "lower".
> > therefore, I think to save the file in the server and then attach
> > using emailmessage.  but how do i get the httpresonse to save
> > in server /tmp/file  ?
> >
> > Regards,
> > MH
> > --
> > You received this message because you are subscribed to the Google
> > Groups "Django users" group.
> > To post to this group, send email to django-users@googlegroups.com.
> > To unsubscribe from this group, send email to
> > django-users+unsubscr...@googlegroups.com.
> > For more options, visit this group at
> > http://groups.google.com/group/django-users?hl=en.
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>

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



how to save response 's render file to server or email using httpresponse

2012-07-03 Thread Min Hong Tan
hi,

I have a problem to send mail using Emailmessage,
i wan to attach the file that render using httpresponse and send, but
always show me "int" does not have method "lower".
therefore, I think to save the file in the server and then attach using
emailmessage.  but how do i get the httpresonse to save
in server /tmp/file  ?

Regards,
MH

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



mssql

2012-06-07 Thread Min Hong Tan
hi all,

i'm going to use django-mssql.  is there any one has use this b4? and any
working example?
am i need to define a model in models.py?? how if i run syndb. will it sync
to my default. mysql
database?

Regards,
MH

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



list indices must be integers, not str

2012-06-01 Thread Min Hong Tan
Hi all,

My error msg when i trying to pass character instead of decimal value
through the
URL pattern

URL Link:
/project1/program1_add/DUM014749/


URLS.py

url(r'^program1_add/(?P\w{1,13})/$',
'view.program_common_add''),

Is there any way to pass character instead of value?

Regards,
MH

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



Re: output string for template render object

2012-05-27 Thread Min Hong Tan
hi Chew,

Thanks.  I have found out the html code that i render is invalid. :P  too
tire for late night programming

Regards,
MH

On Sun, May 27, 2012 at 11:17 AM, Chew Kok Hoor <kokh...@gmail.com> wrote:

> Hi Min Hong,
>
> I think you need to provide a simple example, of values in the context
> (programs, generate_html,generate_script), your template and the result as
> well as the expected result so that it is easier for forum members to help
> you.
>
> Thanks.
>
> Regards,
> Kok Hoor
>
> On Sun, May 27, 2012 at 4:28 PM, Min Hong Tan <tan.dja...@gmail.com>wrote:
>
>> hi all,
>>
>> i have one question
>> return render_to_response(mainPageTemplate,
>>   {'programs':find_program ,
>>'generate_html':generate_html,
>>'generate_script':generate_script
>>},
>>   context_instance=RequestContext(request))
>>
>> on the above return value.  i have two parameter one is return string
>> value with javascript and html components.
>> i have put the {% autoescape off %} as well to avoid conversation.  but,
>> i noticed it seems like can not capture the
>> html 's component that i specified in  the generate_html.  even
>> javascript put at $(document).ready(function(){ }
>> is it i left out anything? thanks
>>
>>
>> Regards,
>> MH
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To post to this group, send email to django-users@googlegroups.com.
>> To unsubscribe from this group, send email to
>> django-users+unsubscr...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/django-users?hl=en.
>>
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>

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



output string for template render object

2012-05-27 Thread Min Hong Tan
hi all,

i have one question
return render_to_response(mainPageTemplate,
  {'programs':find_program ,
   'generate_html':generate_html,
   'generate_script':generate_script
   },
  context_instance=RequestContext(request))

on the above return value.  i have two parameter one is return string value
with javascript and html components.
i have put the {% autoescape off %} as well to avoid conversation.  but, i
noticed it seems like can not capture the
html 's component that i specified in  the generate_html.  even javascript
put at $(document).ready(function(){ }
is it i left out anything? thanks


Regards,
MH

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



django connect alternate database.

2012-05-25 Thread Min Hong Tan
hi,

I have a situation.  currently i have one default django 's database.
but, i wound like to connect to mssql/other database.
- how can i get connected to ms-sql/other database?
- is it we have to create class in models? the database is for read only.
Hope able to get the information.

Regards,
MH

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



model form_set can not delete

2012-05-23 Thread Min Hong Tan
Hi there,

i have a problem whereby, if i for form in formset line by line and run
form.save().  my delete (ticked) item will not be deleted.
and if i 'm direct using formset.save(). it did deleted. where am i code
wrong already?


q1 = modelformset_factory(CustomerDetail,
   form=
CustomerDetail lForm,
   can_delete=True)
# bla bla bla

if request.method == 'POST':

find_formsetcustomerdetail =
CustomerDetail .objects.filter(customerheader__id=id_unquekey)
formset =
q1(request.POST,request.FILES,queryset=find_formsetcustomerdetail)
if formset.is_valid():
for formline in formset:
 # do checking..bla bla bla
   formline.save()

Regards,
MH

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



Re: user.set_password('new password')

2012-05-19 Thread Min Hong Tan
thanks all :)

On Sat, May 19, 2012 at 9:49 AM, Timothy Makobu <makobu.mwambir...@gmail.com
> wrote:

> user.save returns the function object, which is a valid statement, so
> Python wont raise an Exception.
>
>
> On Sat, May 19, 2012 at 9:23 AM, Min Hong Tan <tan.dja...@gmail.com>wrote:
>
>> hi..
>>
>> thanks!! haha... didn't notice  that. how can no error...prompt out
>> one
>>
>>
>> On Fri, May 18, 2012 at 11:48 PM, Jonathan D. Baker <
>> jonathandavidba...@gmail.com> wrote:
>>
>>> Save is a method, so it needs parentheses: user.save()
>>>
>>> Sent from my iPhone
>>>
>>> On May 18, 2012, at 10:53 PM, Min Hong Tan <tan.dja...@gmail.com> wrote:
>>>
>>> Hi,
>>>
>>> I 'm trying to change password in views.py in one of my  def.
>>> having the below code.
>>> newpassword ="testing123"
>>> user = User.objects.get(username__exact = request.user)
>>> user.set_password(newpassword)
>>> user.save
>>>
>>> it didn't prompt me any error.  but, why my password still remained
>>> unchanged?
>>>
>>> Regards,
>>> MH
>>>
>>>
>>>  --
>>> You received this message because you are subscribed to the Google
>>> Groups "Django users" group.
>>> To post to this group, send email to django-users@googlegroups.com.
>>> To unsubscribe from this group, send email to
>>> django-users+unsubscr...@googlegroups.com.
>>> For more options, visit this group at
>>> http://groups.google.com/group/django-users?hl=en.
>>>
>>>  --
>>> You received this message because you are subscribed to the Google
>>> Groups "Django users" group.
>>> To post to this group, send email to django-users@googlegroups.com.
>>> To unsubscribe from this group, send email to
>>> django-users+unsubscr...@googlegroups.com.
>>> For more options, visit this group at
>>> http://groups.google.com/group/django-users?hl=en.
>>>
>>
>>  --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To post to this group, send email to django-users@googlegroups.com.
>> To unsubscribe from this group, send email to
>> django-users+unsubscr...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/django-users?hl=en.
>>
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>

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



Re: user.set_password('new password')

2012-05-19 Thread Min Hong Tan
hi..

thanks!! haha... didn't notice  that. how can no error...prompt out one

On Fri, May 18, 2012 at 11:48 PM, Jonathan D. Baker <
jonathandavidba...@gmail.com> wrote:

> Save is a method, so it needs parentheses: user.save()
>
> Sent from my iPhone
>
> On May 18, 2012, at 10:53 PM, Min Hong Tan <tan.dja...@gmail.com> wrote:
>
> Hi,
>
> I 'm trying to change password in views.py in one of my  def.
> having the below code.
> newpassword ="testing123"
> user = User.objects.get(username__exact = request.user)
> user.set_password(newpassword)
> user.save
>
> it didn't prompt me any error.  but, why my password still remained
> unchanged?
>
> Regards,
> MH
>
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>

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



user.set_password('new password')

2012-05-18 Thread Min Hong Tan
Hi,

I 'm trying to change password in views.py in one of my  def.
having the below code.
newpassword ="testing123"
user = User.objects.get(username__exact = request.user)
user.set_password(newpassword)
user.save

it didn't prompt me any error.  but, why my password still remained
unchanged?

Regards,
MH

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



Re: Can't locate 'media' directory

2012-05-17 Thread Min Hong Tan
hi,

you may try this way.
in your settings.py

import os
ROOT_PATH  =  'c:/project/ajax_tut'   # take note. need to use black slash.


On Thu, May 17, 2012 at 12:31 AM, Venkat Rangan <venkat.ran...@gmail.com>wrote:

> No, this did not work. Is there a way to print what the ROOT_PATH is, on
> an HTML page?
>
>
> On Wed, May 16, 2012 at 3:55 PM, Min Hong Tan <tan.dja...@gmail.com>wrote:
>
>> hi,
>>
>> your media folder location should be
>>
>> /media
>>
>> example: your  ROOT_PATH  is c:\project\ajax_tut
>> then your media file should be
>>
>> c:\project\ajax_tut\media
>>
>> MEDIA_ROOT = os.path.join(ROOT_PATH, 'media')
>> MEDIA_URL = '/media/ <http://127.0.0.1:8000/media/>' < like this
>> should be ok.
>>
>> you may try. hope it helps.
>>
>> Regards,
>> MH
>>
>>
>> On Tue, May 15, 2012 at 8:41 PM, django-user59 
>> <venkat.ran...@gmail.com>wrote:
>>
>>> Hi,
>>>
>>> I attempted to add 'media' directory to the root of my project and
>>> placed a css file and some ajax javascript. The server runtime is unable to
>>> locate it. Can someone help?
>>>
>>> I have the following in settings.py
>>>
>>> MEDIA_ROOT = os.path.join(ROOT_PATH, 'media')
>>> MEDIA_URL = 'http://127.0.0.1:8000/media/'
>>>
>>> The console error I get is:
>>>
>>> C:\dev\Projects\ajax_tut\ajax_tut>python ../manage.py runserver
>>> Validating models...
>>> 0 errors found
>>> Django version 1.4, using settings 'ajax_tut.settings'
>>> Development server is running at http://127.0.0.1:8000/
>>> Quit the server with CTRL-BREAK.
>>> [15/May/2012 19:11:12] "GET / HTTP/1.1" 200 613
>>> [15/May/2012 19:11:12] "GET /media/style.css HTTP/1.1" 404 2312
>>> [15/May/2012 19:11:12] "GET /media/jquery-1.2.6.min.js HTTP/1.1" 404 2342
>>> [15/May/2012 19:11:28] "GET / HTTP/1.1" 200 613
>>> [15/May/2012 19:11:28] "GET /media/style.css HTTP/1.1" 404 2312
>>> [15/May/2012 19:11:28] "GET /media/jquery-1.2.6.min.js HTTP/1.1" 404 2342
>>>
>>> Where do I place this directory and what do I set in settings.py and
>>> which directory do I launch the server? Once again, any help would be much
>>> appreciated.
>>>
>>> Thanks,
>>>
>>>
>>>  --
>>> You received this message because you are subscribed to the Google
>>> Groups "Django users" group.
>>> To view this discussion on the web visit
>>> https://groups.google.com/d/msg/django-users/-/XyZWqGOd6KoJ.
>>> To post to this group, send email to django-users@googlegroups.com.
>>> To unsubscribe from this group, send email to
>>> django-users+unsubscr...@googlegroups.com.
>>> For more options, visit this group at
>>> http://groups.google.com/group/django-users?hl=en.
>>>
>>
>>  --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To post to this group, send email to django-users@googlegroups.com.
>> To unsubscribe from this group, send email to
>> django-users+unsubscr...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/django-users?hl=en.
>>
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>

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



Re: Can't locate 'media' directory

2012-05-16 Thread Min Hong Tan
hi,

your media folder location should be

/media

example: your  ROOT_PATH  is c:\project\ajax_tut
then your media file should be

c:\project\ajax_tut\media

MEDIA_ROOT = os.path.join(ROOT_PATH, 'media')
MEDIA_URL = '/media/ ' < like this
should be ok.

you may try. hope it helps.

Regards,
MH

On Tue, May 15, 2012 at 8:41 PM, django-user59 wrote:

> Hi,
>
> I attempted to add 'media' directory to the root of my project and placed
> a css file and some ajax javascript. The server runtime is unable to locate
> it. Can someone help?
>
> I have the following in settings.py
>
> MEDIA_ROOT = os.path.join(ROOT_PATH, 'media')
> MEDIA_URL = 'http://127.0.0.1:8000/media/'
>
> The console error I get is:
>
> C:\dev\Projects\ajax_tut\ajax_tut>python ../manage.py runserver
> Validating models...
> 0 errors found
> Django version 1.4, using settings 'ajax_tut.settings'
> Development server is running at http://127.0.0.1:8000/
> Quit the server with CTRL-BREAK.
> [15/May/2012 19:11:12] "GET / HTTP/1.1" 200 613
> [15/May/2012 19:11:12] "GET /media/style.css HTTP/1.1" 404 2312
> [15/May/2012 19:11:12] "GET /media/jquery-1.2.6.min.js HTTP/1.1" 404 2342
> [15/May/2012 19:11:28] "GET / HTTP/1.1" 200 613
> [15/May/2012 19:11:28] "GET /media/style.css HTTP/1.1" 404 2312
> [15/May/2012 19:11:28] "GET /media/jquery-1.2.6.min.js HTTP/1.1" 404 2342
>
> Where do I place this directory and what do I set in settings.py and which
> directory do I launch the server? Once again, any help would be much
> appreciated.
>
> Thanks,
>
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/django-users/-/XyZWqGOd6KoJ.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>

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



Re: Disable ModelChoiceField field in ModelForm

2012-05-12 Thread Min Hong Tan
problem solved.

from django.forms import ModelForm,Select
prg_type =
forms.ModelChoiceField(queryset=ProgramType.objects.all(),widget=Select(attrs={'disabled':'disabled'}))


in forms.py

On Sat, May 12, 2012 at 4:53 PM, Min Hong Tan <tan.dja...@gmail.com> wrote:

> hi,
>
> I have a foreign field show in the modelform, and i wish to disable it,
> may i know how to disable it in modelform?
> i tried attrs={'disabled':'disabled} but, it prompt doesn't have attrs
> attribute.
>
> Regards,
> MH
>

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



Disable ModelChoiceField field in ModelForm

2012-05-12 Thread Min Hong Tan
hi,

I have a foreign field show in the modelform, and i wish to disable it, may
i know how to disable it in modelform?
i tried attrs={'disabled':'disabled} but, it prompt doesn't have attrs
attribute.

Regards,
MH

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



Re: disabled or readonly field 's problem

2012-05-12 Thread Min Hong Tan
hi, thanks.

 def clean_pt_type(self):
data = self.initial['pt_type']

and solve the problem.

On Fri, May 11, 2012 at 10:56 PM, azizmb.in <m...@azizmb.in> wrote:

> Hey!
>
> You could clean the protected fields from the model data by overriding
> "clean" methods of the form. The documentation is 
> here<https://docs.djangoproject.com/en/dev/ref/forms/validation/#cleaning-a-specific-field-attribute>
> .
>
> On Sat, May 12, 2012 at 8:56 AM, Min Hong Tan <tan.dja...@gmail.com>wrote:
>
>> hi,
>>
>> i have a problem on the formmodel.  basically, to set the field read only
>> and disabled is easy.
>> but, the problem which I facing now, is a bit complicated.
>> - if set field "read-only" field. We can actually modify the record by
>> using web developer tools by press "F12"
>>   to modify the record and saved.  it did update the value for read-only
>> field.  this will be a security issue, if
>> some one know this.
>>
>> - if set field to "disabled" it will not post the key field.  but,
>> instead , it let it blank. and error shown, this field
>> is required. is ok, we can set required=false. but, it will be sending
>> key field value as blank to the database.
>>
>> How to I avoid this issue for record "Editing" without user  can modify
>> the value using F12 and show as read-only?
>>
>> Regards,
>> MH
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To post to this group, send email to django-users@googlegroups.com.
>> To unsubscribe from this group, send email to
>> django-users+unsubscr...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/django-users?hl=en.
>>
>
>
>
> --
> - Aziz M. Bookwala
>
> Website <http://azizmb.in/> | Twitter <https://twitter.com/azizbookwala>
>  | Github <http://github.com/azizmb>
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>

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



disabled or readonly field 's problem

2012-05-11 Thread Min Hong Tan
hi,

i have a problem on the formmodel.  basically, to set the field read only
and disabled is easy.
but, the problem which I facing now, is a bit complicated.
- if set field "read-only" field. We can actually modify the record by
using web developer tools by press "F12"
  to modify the record and saved.  it did update the value for read-only
field.  this will be a security issue, if
some one know this.

- if set field to "disabled" it will not post the key field.  but, instead
, it let it blank. and error shown, this field
is required. is ok, we can set required=false. but, it will be sending key
field value as blank to the database.

How to I avoid this issue for record "Editing" without user  can modify the
value using F12 and show as read-only?

Regards,
MH

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



unique key error doesn't show using copy record in modelform.

2012-05-10 Thread Min Hong Tan
hi,

my scenario as below:
- I want to copy existing record and show at the form. then clear the pk
and id then it will be able to "add" instead of "update".
- all working fine. but, if the record is exist (Unique error).  it should
prompt unique key 's error.  but, in the form.is_valid
   has no trigger the error. untill the cmodel.save() only it throw
exception.  but, the form doesn't render the error message.

if without using "form = ProgramTypeForm(request.POST or
None,instance=dataObject)"  and use "form = ProgramTypeForm(request.POST or
None)",
then, it will be false if we run form.is_valid() else, it will True if we
execute form.is_valid() , or maybe my method are incorrect?

below are the coding:

__
models.py
__

class ProgramType(Standard):
pt_type = models.CharField('Program Type',
max_length=20,blank=False,unique=True)
pt_desc = models.CharField('Program Description',max_length=100)

def __unicode__(self):
return self.pt_type

class Meta:
unique_together = (('pt_type'),)

__
views.py

def form_copy(request,id_key):
dataObject = get_object_or_404(ProgramType,pk=id_key)
dataObject.pk = None
dataObject.id = None
form = ProgramTypeForm(request.POST or None,instance=dataObject)
if form.is_valid():
try:
cmodel = form.save(commit=False)
cmodel.id = None
cmodel.pk = None
cmodel.save()# < *here is the error*
 except:
  # do exception
 finally:
  # do finally
 else:
 # return form invalid render.
__
forms.py

class ProgramTypeForm(ModelForm):
pt_desc = forms.CharField(widget=forms.Textarea(attrs = {'class':
"page-text", 'cols': 30, 'rows': 10}), label='Description')
class Meta(CommonForm.Meta):
model = ProgramType


Regards,
MH

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



Re: jquery form post without refresh the page

2012-05-05 Thread Min Hong Tan
i think i use .bind() instead of .live.  because .live will add the event
everytimes it .html again.
Thanks

On Sat, May 5, 2012 at 2:22 PM, Min Hong Tan <tan.dja...@gmail.com> wrote:

> seems like .html has another problem.  it will duplicate itself (even not
> seen in the screen).
> but it did post Number of times when i submit the form.  still need to
> struggling..bugs still
> exist..
>
>
> On Sat, May 5, 2012 at 2:17 PM, Min Hong Tan <tan.dja...@gmail.com> wrote:
>
>> hi Oscar,
>>
>> I think maybe it over some ajaxsetup({cache:false}) prevention when doing
>> replaceWith.
>> I have solve the problem by using ".html"  instead of ".replaceWith".
>>
>> Thank you for your help. very appreciate it .
>>
>> Regards,
>> MH
>>
>>
>> On Sat, May 5, 2012 at 2:01 PM, Oscar Mederos <omede...@gmail.com> wrote:
>>
>>> Hello Min,
>>>
>>> On Saturday, May 5, 2012, 1:36:24 PM, you wrote:
>>>
>>> > hi oscar,
>>>
>>> > it works, but the problem in jquery load didn't refresh the page after
>>> I have loaded.
>>> > it will always use the outdated html.  I have tried to use ajaxsetup
>>> cache:false etc.
>>> > but seems like once it loaded. if form return validation error, even
>>> we have close
>>> > and call jquery load again. it will still static and show the last
>>> validation error.
>>>
>>> > how you solve this issue?  seems like more to javascript itself .
>>>
>>> I'm not sure why it isn't modifying the page correctly, because the
>>> following line should do it:
>>>
>>> $("#my-form").replaceWith(data.message);
>>>
>>> - Are you sure the form isn't being validated in the server-side?
>>> - Are you sure the request is being made to the server? (maybe an error
>>> occurs on the client-side and the request is never made).
>>> - Could you show us the entire code you are using?
>>>
>>> I suggest you doing two things:
>>> 1) Load the page, and before submitting the form, store the source
>>> code of the page. Then store it again once you submit it, so that you
>>> can compare both source codes.
>>> 2) Debug that jQuery code either with Chrome's Developer Tools, or
>>> Firebug for Firefox.
>>>
>>> > Regards,
>>> > MH
>>>
>>>
>>> --
>>> Oscar Mederos
>>> omede...@gmail.com
>>>
>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "Django users" group.
>>> To post to this group, send email to django-users@googlegroups.com.
>>> To unsubscribe from this group, send email to
>>> django-users+unsubscr...@googlegroups.com.
>>> For more options, visit this group at
>>> http://groups.google.com/group/django-users?hl=en.
>>>
>>>
>>
>

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



Re: jquery form post without refresh the page

2012-05-05 Thread Min Hong Tan
seems like .html has another problem.  it will duplicate itself (even not
seen in the screen).
but it did post Number of times when i submit the form.  still need to
struggling..bugs still
exist..

On Sat, May 5, 2012 at 2:17 PM, Min Hong Tan <tan.dja...@gmail.com> wrote:

> hi Oscar,
>
> I think maybe it over some ajaxsetup({cache:false}) prevention when doing
> replaceWith.
> I have solve the problem by using ".html"  instead of ".replaceWith".
>
> Thank you for your help. very appreciate it .
>
> Regards,
> MH
>
>
> On Sat, May 5, 2012 at 2:01 PM, Oscar Mederos <omede...@gmail.com> wrote:
>
>> Hello Min,
>>
>> On Saturday, May 5, 2012, 1:36:24 PM, you wrote:
>>
>> > hi oscar,
>>
>> > it works, but the problem in jquery load didn't refresh the page after
>> I have loaded.
>> > it will always use the outdated html.  I have tried to use ajaxsetup
>> cache:false etc.
>> > but seems like once it loaded. if form return validation error, even we
>> have close
>> > and call jquery load again. it will still static and show the last
>> validation error.
>>
>> > how you solve this issue?  seems like more to javascript itself .
>>
>> I'm not sure why it isn't modifying the page correctly, because the
>> following line should do it:
>>
>> $("#my-form").replaceWith(data.message);
>>
>> - Are you sure the form isn't being validated in the server-side?
>> - Are you sure the request is being made to the server? (maybe an error
>> occurs on the client-side and the request is never made).
>> - Could you show us the entire code you are using?
>>
>> I suggest you doing two things:
>> 1) Load the page, and before submitting the form, store the source
>> code of the page. Then store it again once you submit it, so that you
>> can compare both source codes.
>> 2) Debug that jQuery code either with Chrome's Developer Tools, or
>> Firebug for Firefox.
>>
>> > Regards,
>> > MH
>>
>>
>> --
>> Oscar Mederos
>> omede...@gmail.com
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To post to this group, send email to django-users@googlegroups.com.
>> To unsubscribe from this group, send email to
>> django-users+unsubscr...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/django-users?hl=en.
>>
>>
>

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



Re: jquery form post without refresh the page

2012-05-05 Thread Min Hong Tan
hi Oscar,

I think maybe it over some ajaxsetup({cache:false}) prevention when doing
replaceWith.
I have solve the problem by using ".html"  instead of ".replaceWith".

Thank you for your help. very appreciate it .

Regards,
MH

On Sat, May 5, 2012 at 2:01 PM, Oscar Mederos  wrote:

> Hello Min,
>
> On Saturday, May 5, 2012, 1:36:24 PM, you wrote:
>
> > hi oscar,
>
> > it works, but the problem in jquery load didn't refresh the page after I
> have loaded.
> > it will always use the outdated html.  I have tried to use ajaxsetup
> cache:false etc.
> > but seems like once it loaded. if form return validation error, even we
> have close
> > and call jquery load again. it will still static and show the last
> validation error.
>
> > how you solve this issue?  seems like more to javascript itself .
>
> I'm not sure why it isn't modifying the page correctly, because the
> following line should do it:
>
> $("#my-form").replaceWith(data.message);
>
> - Are you sure the form isn't being validated in the server-side?
> - Are you sure the request is being made to the server? (maybe an error
> occurs on the client-side and the request is never made).
> - Could you show us the entire code you are using?
>
> I suggest you doing two things:
> 1) Load the page, and before submitting the form, store the source
> code of the page. Then store it again once you submit it, so that you
> can compare both source codes.
> 2) Debug that jQuery code either with Chrome's Developer Tools, or
> Firebug for Firefox.
>
> > Regards,
> > MH
>
>
> --
> Oscar Mederos
> omede...@gmail.com
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>

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



Re: jquery form post without refresh the page

2012-05-05 Thread Min Hong Tan
hi oscar,

it works, but the problem in jquery load didn't refresh the page after I
have loaded.
it will always use the outdated html.  I have tried to use ajaxsetup
cache:false etc.
but seems like once it loaded. if form return validation error, even we
have close
and call jquery load again. it will still static and show the last
validation error.

how you solve this issue?  seems like more to javascript itself .

Regards,
MH

On Fri, May 4, 2012 at 11:17 PM, Min Hong Tan <tan.dja...@gmail.com> wrote:

> hi oscar,
>
> Thank you!!! that is awesome! i not even need to manipulate the form using
> output data json!
> thanks! but ,  $("xxx").live  really is important...
>
>
> Regards,
> MH
>
>
> On Fri, May 4, 2012 at 4:56 PM, Oscar Mederos <omede...@gmail.com> wrote:
>
>> Hello Min,
>>
>> On Friday, May 4, 2012, 10:14:46 AM, you wrote:
>>
>> > hi oscar,
>>
>> > how do you make use of the particular method to be able to render
>> > the form only? as you said make use of the
>> > https://docs.djangoproject.com/en/1.4/ref/contrib/csrf/#ajax  and
>> > it able to render the form instead of page?
>> > because i'm using kurtis method, if any validation error, i
>> > retrieve the data from javascript and manipulate the
>> > output in html only.
>>
>> What I usually do is the following:
>> - Place  the  content  of  my  form  in a separate template file (eg.
>> password-form.html)
>> - Using jQuery, I do something like:
>>
>> //Override the behavior of the 'submit' event of the form.
>> //Very important to use 'live' instead of 'click'. Otherwise,
>> //if we change the HTML of the form, this function won't be triggered
>> //next time we submit the form.
>> $("#my-form").live('submit', function(e) {
>>e.preventDefault();
>>$.ajax({
>>type: "post",
>>//DRY. I suppose you already have the url where
>>//you want to make the POST request in the "action"
>>//tag of the 
>>url: $("#my-form").attr("action"),
>>//This automatically get all the values from the
>>//inputs in the form (eg. a=1=2)
>>data: $("#my-form").serialize(),
>>dataType: "json",
>>success: function(data) {
>>//If there was an error...
>>if (data.error == 1) {
>>//All we have to do is replace the body of
>>//the .. with the new HTML
>>//rendered value of the form returned from
>>//the server
>>$("#my-form").replaceWith(data.message);
>>}
>>else {
>>//Do whatever you want here
>>}
>>}
>>});
>>});
>>
>> 'data' is what the view should return. What I usually do is the
>> following:
>> * If there was an error validating the form, then:
>>  - "data.error" will be 1
>>  - "data.message" will have the form rendered
>> * If the form was validated without problems
>>  - "data.error" will be 0
>>  - "data.message" will have some success message (eg. "Your password
>>  was changed successfully).
>>
>> - Now, in the view... how do I return the rendered form as HTML?
>>
>> The "password-form.html" template should look like:
>>
>> 
>>  {% csrf_token %}
>>  ...
>> 
>>
>> And the code of the view could be something like the following (of
>> course, checking that the request method was POST, etc).
>>
>> def view(request):
>># Create the bounded form (as you usually do)
>>f = MyForm(request.POST)
>>if form.is_valid():
>>   form.save()
>>   d = {'error': 0, 'message': 'Some success message'}
>>else:
>>   d = {'error': 1}
>>   # Here we render the entire HTML text of the form. You can pass
>>   # anything you want in the context...
>>   form_html = render_to_string('password-form.html',...,
>> context_instance=RequestContext(request))
>>   d['message'] = form_html
>>response = simplejson.dumps(d)
>>return HttpResponse(

Re: jquery form post without refresh the page

2012-05-04 Thread Min Hong Tan
hi oscar,

Thank you!!! that is awesome! i not even need to manipulate the form using
output data json!
thanks! but ,  $("xxx").live  really is important...


Regards,
MH

On Fri, May 4, 2012 at 4:56 PM, Oscar Mederos  wrote:

> Hello Min,
>
> On Friday, May 4, 2012, 10:14:46 AM, you wrote:
>
> > hi oscar,
>
> > how do you make use of the particular method to be able to render
> > the form only? as you said make use of the
> > https://docs.djangoproject.com/en/1.4/ref/contrib/csrf/#ajax  and
> > it able to render the form instead of page?
> > because i'm using kurtis method, if any validation error, i
> > retrieve the data from javascript and manipulate the
> > output in html only.
>
> What I usually do is the following:
> - Place  the  content  of  my  form  in a separate template file (eg.
> password-form.html)
> - Using jQuery, I do something like:
>
> //Override the behavior of the 'submit' event of the form.
> //Very important to use 'live' instead of 'click'. Otherwise,
> //if we change the HTML of the form, this function won't be triggered
> //next time we submit the form.
> $("#my-form").live('submit', function(e) {
>e.preventDefault();
>$.ajax({
>type: "post",
>//DRY. I suppose you already have the url where
>//you want to make the POST request in the "action"
>//tag of the 
>url: $("#my-form").attr("action"),
>//This automatically get all the values from the
>//inputs in the form (eg. a=1=2)
>data: $("#my-form").serialize(),
>dataType: "json",
>success: function(data) {
>//If there was an error...
>if (data.error == 1) {
>//All we have to do is replace the body of
>//the .. with the new HTML
>//rendered value of the form returned from
>//the server
>$("#my-form").replaceWith(data.message);
>}
>else {
>//Do whatever you want here
>}
>}
>});
>});
>
> 'data' is what the view should return. What I usually do is the
> following:
> * If there was an error validating the form, then:
>  - "data.error" will be 1
>  - "data.message" will have the form rendered
> * If the form was validated without problems
>  - "data.error" will be 0
>  - "data.message" will have some success message (eg. "Your password
>  was changed successfully).
>
> - Now, in the view... how do I return the rendered form as HTML?
>
> The "password-form.html" template should look like:
>
> 
>  {% csrf_token %}
>  ...
> 
>
> And the code of the view could be something like the following (of
> course, checking that the request method was POST, etc).
>
> def view(request):
># Create the bounded form (as you usually do)
>f = MyForm(request.POST)
>if form.is_valid():
>   form.save()
>   d = {'error': 0, 'message': 'Some success message'}
>else:
>   d = {'error': 1}
>   # Here we render the entire HTML text of the form. You can pass
>   # anything you want in the context...
>   form_html = render_to_string('password-form.html',...,
> context_instance=RequestContext(request))
>   d['message'] = form_html
>response = simplejson.dumps(d)
>return HttpResponse(response, mimetype='application/json')
>
> I wrote all of it in the editor of my email client, so if something
> does not work, just let me know.
>
> Again, very important to use the snippet provided in
> https://docs.djangoproject.com/en/1.4/ref/contrib/csrf/#ajax
>
>
> > Regards,
> > MH
>
>
> --
> Oscar Mederos
> omede...@gmail.com
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>

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



Re: jquery form post without refresh the page

2012-05-04 Thread Min Hong Tan
hi oscar,

how do you make use of the particular method to be able to render the form
only? as you said make use of the
https://docs.djangoproject.com/en/1.4/ref/contrib/csrf/#ajax  and it able
to render the form instead of page?
because i'm using kurtis method, if any validation error, i retrieve the
data from javascript and manipulate the
output in html only.

Regards,
MH

On Fri, May 4, 2012 at 1:58 AM, Oscar Mederos  wrote:

> Hello Kurtis,
>
> On Thursday, May 3, 2012, 3:16:38 PM, you wrote:
>
> > Here's something I do.
>
> > I have a page where I include {% csrf_token %} and another field.
> > Then I do a simple JQuery .post() call.
>
> > Note, I've tried to pull out a bunch of stuff that isn't specific
> > to the call. It's untested in this form but should work. I tried to
> > include comments to help you understand what's going on.
>
> > 
> > $('div.theme_image, div.theme_name').on("click", function(event) {
> >
> > // Used later to access 'this' (the calling object)
> > var theme = this;
> >
> > // Prepare our AJAX Call.
> > url = '{% url fireflie.wizard.api.choose_theme %}'; // The URL to
> the View we're posting to.
>
> > // Building the POST data here.
> > data = {
> > theme_id: $(this).siblings('input').attr('value'),
> > csrfmiddlewaretoken:
> > $('input[name=csrfmiddlewaretoken]').attr('value')
> > };
> >
> > ...
> >
> > });
> > 
>
> Hello,
>
> Another good option for passing the csrf token is the following one:
> https://docs.djangoproject.com/en/1.4/ref/contrib/csrf/#ajax.
>
> That helped me a lot, because sometimes you need to render your form
> again if it contains errors, and in that case, if you submit it again,
> the csrf token won't get updated correctly.
>
> Just imagine the case where the user wants to change his password:
> - He clicks on "Change password"
> - A modal form (dialog) appears
> - The user clicks on "Submit" and he didn't enter the two passwords
> correctly.
> - The form is rendered again (what I usually do is replace the
> .. content with the some HTML returned by the server in
> the AJAX response). That HTML usually is the rendered form, so that I
> don't need to go for each field and set the errors manually using JS.
>
> > Good luck!
> > -Kurtis Mullins
>
>
> --
> Oscar Mederos
> omede...@gmail.com
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>

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



Re: jquery form post without refresh the page

2012-05-04 Thread Min Hong Tan
Thanks! kurtis, it did helps me. but, to render the form once it return
validation error. i need to use javascript returned value and
manipulate the form.
is there any refresh form content instead of i need to base on returned
value and manual add the error message?

On Thu, May 3, 2012 at 1:16 PM, Kurtis Mullins <kurtis.mull...@gmail.com>wrote:

> Here's something I do.
>
> I have a page where I include {% csrf_token %} and another field. Then I
> do a simple JQuery .post() call.
>
> Note, I've tried to pull out a bunch of stuff that isn't specific to the
> call. It's untested in this form but should work. I tried to include
> comments to help you understand what's going on.
>
> 
> $('div.theme_image, div.theme_name').on("click", function(event) {
>
> // Used later to access 'this' (the calling object)
> var theme = this;
>
> // Prepare our AJAX Call.
> url = '{% url fireflie.wizard.api.choose_theme %}'; // The URL to the
> View we're posting to.
>
> // Building the POST data here.
> data = {
> theme_id: $(this).siblings('input').attr('value'),
> csrfmiddlewaretoken:
> $('input[name=csrfmiddlewaretoken]').attr('value')
> };
>
> // Post Data to the Server
> var jqxhr = $.post(url, data, function(data) {
>
> // Do something in here on Success
> // In my example, I wanted to manipulate the calling object,
> // so it would be "theme" here. If you try to use "this", it won't
> work.
>
> });
>
> // On Error:
> jqxhr.error(function() {
>
>   // Do something in here in the case of errors.
>
> });
>
> });
> 
>
> Good luck!
> -Kurtis Mullins
>
> On Thu, May 3, 2012 at 1:46 PM, Bill Freeman <ke1g...@gmail.com> wrote:
>
>> AJAX
>>
>> You may require a separate view, but maybe not.
>>
>> If you search for jQuery and AJAX there should be samples.
>>
>> On 5/3/12, Min Hong Tan <tan.dja...@gmail.com> wrote:
>> > is there any sample that i can refer to do the ajax style form post
>> > without refresh the whole page?
>> > or backend form.save validation without refresh my form?
>> >
>> > --
>> > You received this message because you are subscribed to the Google
>> Groups
>> > "Django users" group.
>> > To post to this group, send email to django-users@googlegroups.com.
>> > To unsubscribe from this group, send email to
>> > django-users+unsubscr...@googlegroups.com.
>> > For more options, visit this group at
>> > http://groups.google.com/group/django-users?hl=en.
>> >
>> >
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To post to this group, send email to django-users@googlegroups.com.
>> To unsubscribe from this group, send email to
>> django-users+unsubscr...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/django-users?hl=en.
>>
>>
>  --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>

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



jquery form post without refresh the page

2012-05-03 Thread Min Hong Tan
is there any sample that i can refer to do the ajax style form post
without refresh the whole page?
or backend form.save validation without refresh my form?

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