Re: html templates and dynamic loading

2013-08-26 Thread Bastien Amiel

Le 24/08/2013 04:44, Mantas Zilinskis a écrit :

this might help you

http://stackoverflow.com/questions/1879872/django-update-div-with-ajax

let me know if you need more help


Thank you for this good pointer.




On Fri, Aug 23, 2013 at 10:51 AM, Bastien Amiel > wrote:


Le 23/08/2013 17:01, Mantas Zilinskis a écrit :

can you post all of chat.html



On Fri, Aug 23, 2013 at 7:04 AM, Bastien Amiel > wrote:

Le 23/08/2013 11:26, Huu Da Tran a écrit :

On Thursday, August 22, 2013 8:42:04 AM UTC-4, Bastien Amiel
wrote:

I need to update the chat when an event come but :

1.
If I update my chat sub page, inputs are reset (seems
logic since html
is recreated).


You can always have some field that keep when the chat was
started (in the session), and redisplay everything since
that time.

Then what would be the good / best method to update only
the chat content ?
(I have 2 ideas but they don't seems very Django'ic)

2.
For now, I update the content every XX ms with a
periodic request client
side.
Would it be possible / preferable to have a push from
server when new
data comes or is there a better way to update this kind
of content ?


Trying to hack django to get server push would be hell (look
into tornado). If you really need server push, you may need
to look into other technologies, like nodejs.

Using the periodic request client-side is what is mostly done.


Hope this helps.

HD.


1.
My question was not clear enough,
Let's admit i have this template page :

/{% for elem in data %}//
////
//{{ elem.datetime }}//
//{{ elem.name 
}} ://
//{{ elem.text }}//
////
//{% endfor %}//
//Text : /

and this view.py :

/def getchat(request)://
//template = loader.get_template('chat.html')//
//context  = RequestContext(request, { 'data': lines
})//# lines is an array with lines
//response = {'html' : template.render(context)}//
//return HttpResponse(json.dumps(response),
mimetype='application/json')/

and this javascript :

/function getchat()//
//{ //
//$.post('/getchat')//.done(function(data, textStatus,
jqXHR) //
//{//
//$("#chat").html(data["html"])//
//})//
//}

/Then whenever I call getchat() in javascript, the chat is
reloaded with all the old lines, this point is ok, but
 field is reseted too, which mean that if user was
typing, the content is erased.
I would say the solution is to create a second function in
view /getchatcontent/ that will send only the content so I do
not
update the whole thing. Do you think it is the right way ?


2.
lets use periodic request client-side.



Thank you for your answer



There is nothing more in chat.html
there is a base.html template that contains

///
//{% load staticfiles %}//






//post//
///


appchat.js


/$(document).ready(function()//
//{//
//$("#addline").click(function()//
//{//
//addline($("#chatname")[0].value,
$("#chatinput")[0].value);//
//$("#chatinput")[0].value = "" //
//})//
//setInterval(function() { getchat() }, 1000);//
//})//
//
//function addline(name, text)//
//{//
//$.post('/addline', {"name":name, "text":text})//
//.done(function() //{//})//
//}//
//
//function getchat()//
//{ //
//   $.post('/getchat')/
/
//.done(function(data, textStatus, jqXHR) //
//{//
   $("#chat").html(data["html"])//
//})//
//}/


Now you have everything, does this seems the right way to do what
I want to achieve with django or is there a better way ?



--
You received this message because you are subscribed to the Google Groups "Django 
users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.


Re: html templates and dynamic loading

2013-08-23 Thread Mantas Zilinskis
this might help you

http://stackoverflow.com/questions/1879872/django-update-div-with-ajax

let me know if you need more help


On Fri, Aug 23, 2013 at 10:51 AM, Bastien Amiel  wrote:

>  Le 23/08/2013 17:01, Mantas Zilinskis a écrit :
>
>  can you post all of chat.html
>
>
>
> On Fri, Aug 23, 2013 at 7:04 AM, Bastien Amiel  wrote:
>
>>  Le 23/08/2013 11:26, Huu Da Tran a écrit :
>>
>> On Thursday, August 22, 2013 8:42:04 AM UTC-4, Bastien Amiel wrote:
>>
>>
>>> I need to update the chat when an event come but :
>>>
>>> 1.
>>> If I update my chat sub page, inputs are reset (seems logic since html
>>> is recreated).
>>>
>>
>>  You can always have some field that keep when the chat was started (in
>> the session), and redisplay everything since that time.
>>
>>
>>> Then what would be the good / best method to update only the chat
>>> content ?
>>> (I have 2 ideas but they don't seems very Django'ic)
>>>
>>> 2.
>>> For now, I update the content every XX ms with a periodic request client
>>> side.
>>> Would it be possible / preferable to have a push from server when new
>>> data comes or is there a better way to update this kind of content ?
>>
>>
>>  Trying to hack django to get server push would be hell (look into
>> tornado). If you really need server push, you may need to look into other
>> technologies, like nodejs.
>>
>>  Using the periodic request client-side is what is mostly done.
>>
>>
>>  Hope this helps.
>>
>>  HD.
>>
>>
>> 1.
>> My question was not clear enough,
>> Let's admit i have this template page :
>>
>> *{% for elem in data %}**
>> ****
>> **{{ elem.datetime }}**
>> **{{ elem.name }} :**
>> **{{ elem.text }}**
>> ****
>> **{% endfor %}**
>> **Text : *
>>
>> and this view.py :
>>
>> *def getchat(request):**
>> **template = loader.get_template('chat.html')**
>> **context  = RequestContext(request, { 'data': lines })** # lines is
>> an array with lines
>> **response = {'html' : template.render(context)}**
>> **return HttpResponse(json.dumps(response),
>> mimetype='application/json')*
>>
>> and this javascript :
>>
>> *function getchat()**
>> **{**
>> **$.post('/getchat')**.done(function(data, textStatus, jqXHR) **
>> **{**
>> **$("#chat").html(data["html"])**
>> **})**
>> **}
>>
>> *Then whenever I call getchat() in javascript, the chat is reloaded with
>> all the old lines, this point is ok, but
>>  field is reseted too, which mean that if user was typing, the
>> content is erased.
>> I would say the solution is to create a second function in view *
>> getchatcontent* that will send only the content so I do not
>> update the whole thing. Do you think it is the right way ?
>>
>>
>> 2.
>> lets use periodic request client-side.
>>
>>
>>
>> Thank you for your answer
>>
>>
> There is nothing more in chat.html
> there is a base.html template that contains
>
> ***
> **{% load staticfiles %}**
> 
> **
> **
> 
> 
> 
> 
> **post**
> ***
>
>
> appchat.js
>
>
> *$(document).ready(function()**
> **{**
> **$("#addline").click(function()**
> **{**
> **addline($("#chatname")[0].value, $("#chatinput")[0].value);*
> *
> **$("#chatinput")[0].value = "" **
> **})**
> **setInterval(function() { getchat() }, 1000);**
> **})**
> **
> **function addline(name, text)**
> **{**
> **$.post('/addline', {"name":name, "text":text})**
> **.done(function() ** {** })**
> **}**
> **
> **function getchat()**
> **{**
> **   $.post('/getchat')*
> *
> **.done(function(data, textStatus, jqXHR) **
> **{**
> **   **$("#chat").html(data["html"])**
> **})**
> **}*
>
>
> Now you have everything, does this seems the right way to do what I want
> to achieve with django or is there a better way ?
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> For more options, visit https://groups.google.com/groups/opt_out.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.


Re: html templates and dynamic loading

2013-08-23 Thread Bastien Amiel

Le 23/08/2013 17:01, Mantas Zilinskis a écrit :

can you post all of chat.html



On Fri, Aug 23, 2013 at 7:04 AM, Bastien Amiel > wrote:


Le 23/08/2013 11:26, Huu Da Tran a écrit :

On Thursday, August 22, 2013 8:42:04 AM UTC-4, Bastien Amiel wrote:

I need to update the chat when an event come but :

1.
If I update my chat sub page, inputs are reset (seems logic
since html
is recreated).


You can always have some field that keep when the chat was
started (in the session), and redisplay everything since that time.

Then what would be the good / best method to update only the
chat content ?
(I have 2 ideas but they don't seems very Django'ic)

2.
For now, I update the content every XX ms with a periodic
request client
side.
Would it be possible / preferable to have a push from server
when new
data comes or is there a better way to update this kind of
content ?


Trying to hack django to get server push would be hell (look into
tornado). If you really need server push, you may need to look
into other technologies, like nodejs.

Using the periodic request client-side is what is mostly done.


Hope this helps.

HD.


1.
My question was not clear enough,
Let's admit i have this template page :

/{% for elem in data %}//
////
//{{ elem.datetime }}//
//{{ elem.name  }}
://
//{{ elem.text }}//
////
//{% endfor %}//
//Text : /

and this view.py :

/def getchat(request)://
//template = loader.get_template('chat.html')//
//context  = RequestContext(request, { 'data': lines })//#
lines is an array with lines
//response = {'html' : template.render(context)}//
//return HttpResponse(json.dumps(response),
mimetype='application/json')/

and this javascript :

/function getchat()//
//{ //
//$.post('/getchat')//.done(function(data, textStatus, jqXHR) //
//{//
//$("#chat").html(data["html"])//
//})//
//}

/Then whenever I call getchat() in javascript, the chat is
reloaded with all the old lines, this point is ok, but
 field is reseted too, which mean that if user was typing,
the content is erased.
I would say the solution is to create a second function in view
/getchatcontent/ that will send only the content so I do not
update the whole thing. Do you think it is the right way ?


2.
lets use periodic request client-side.



Thank you for your answer



There is nothing more in chat.html
there is a base.html template that contains

///
//{% load staticfiles %}//







//post//
///


appchat.js


/$(document).ready(function()//
//{//
//$("#addline").click(function()//
//{//
//addline($("#chatname")[0].value, $("#chatinput")[0].value);//
//$("#chatinput")[0].value = "" //
//})//
//setInterval(function() { getchat() }, 1000);//
//})//
//
//function addline(name, text)//
//{//
//$.post('/addline', {"name":name, "text":text})//
//.done(function() //{//})//
//}//
//
//function getchat()//
//{ //
//   $.post('/getchat')//
//.done(function(data, textStatus, jqXHR) //
//{//
   $("#chat").html(data["html"])//
//})//
//}/


Now you have everything, does this seems the right way to do what I want 
to achieve with django or is there a better way ?


--
You received this message because you are subscribed to the Google Groups "Django 
users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.


Re: html templates and dynamic loading

2013-08-23 Thread Mantas Zilinskis
can you post all of chat.html






On Fri, Aug 23, 2013 at 7:04 AM, Bastien Amiel  wrote:

>  Le 23/08/2013 11:26, Huu Da Tran a écrit :
>
> On Thursday, August 22, 2013 8:42:04 AM UTC-4, Bastien Amiel wrote:
>
>
>> I need to update the chat when an event come but :
>>
>> 1.
>> If I update my chat sub page, inputs are reset (seems logic since html
>> is recreated).
>>
>
>  You can always have some field that keep when the chat was started (in
> the session), and redisplay everything since that time.
>
>
>> Then what would be the good / best method to update only the chat content
>> ?
>> (I have 2 ideas but they don't seems very Django'ic)
>>
>> 2.
>> For now, I update the content every XX ms with a periodic request client
>> side.
>> Would it be possible / preferable to have a push from server when new
>> data comes or is there a better way to update this kind of content ?
>
>
>  Trying to hack django to get server push would be hell (look into
> tornado). If you really need server push, you may need to look into other
> technologies, like nodejs.
>
>  Using the periodic request client-side is what is mostly done.
>
>
>  Hope this helps.
>
>  HD.
>
>
> 1.
> My question was not clear enough,
> Let's admit i have this template page :
>
> *{% for elem in data %}**
> ****
> **{{ elem.datetime }}**
> **{{ elem.name }} :**
> **{{ elem.text }}**
> ****
> **{% endfor %}**
> **Text : *
>
> and this view.py :
>
> *def getchat(request):**
> **template = loader.get_template('chat.html')**
> **context  = RequestContext(request, { 'data': lines })** # lines is
> an array with lines
> **response = {'html' : template.render(context)}**
> **return HttpResponse(json.dumps(response),
> mimetype='application/json')*
>
> and this javascript :
>
> *function getchat()**
> **{**
> **$.post('/getchat')**.done(function(data, textStatus, jqXHR) **
> **{**
> **$("#chat").html(data["html"])**
> **})**
> **}
>
> *Then whenever I call getchat() in javascript, the chat is reloaded with
> all the old lines, this point is ok, but
>  field is reseted too, which mean that if user was typing, the
> content is erased.
> I would say the solution is to create a second function in view *
> getchatcontent* that will send only the content so I do not
> update the whole thing. Do you think it is the right way ?
>
>
> 2.
> lets use periodic request client-side.
>
>
>
> Thank you for your answer
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> For more options, visit https://groups.google.com/groups/opt_out.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.


Re: html templates and dynamic loading

2013-08-23 Thread Bastien Amiel

Le 23/08/2013 11:26, Huu Da Tran a écrit :

On Thursday, August 22, 2013 8:42:04 AM UTC-4, Bastien Amiel wrote:

I need to update the chat when an event come but :

1.
If I update my chat sub page, inputs are reset (seems logic since
html
is recreated).


You can always have some field that keep when the chat was started (in 
the session), and redisplay everything since that time.


Then what would be the good / best method to update only the chat
content ?
(I have 2 ideas but they don't seems very Django'ic)

2.
For now, I update the content every XX ms with a periodic request
client
side.
Would it be possible / preferable to have a push from server when new
data comes or is there a better way to update this kind of content ?


Trying to hack django to get server push would be hell (look into 
tornado). If you really need server push, you may need to look into 
other technologies, like nodejs.


Using the periodic request client-side is what is mostly done.


Hope this helps.

HD.


1.
My question was not clear enough,
Let's admit i have this template page :

/{% for elem in data %}//
////
//{{ elem.datetime }}//
//{{ elem.name }} ://
//{{ elem.text }}//
////
//{% endfor %}//
//Text : /

and this view.py :

/def getchat(request)://
//template = loader.get_template('chat.html')//
//context  = RequestContext(request, { 'data': lines })//# lines is 
an array with lines

//response = {'html' : template.render(context)}//
//return HttpResponse(json.dumps(response), 
mimetype='application/json')/


and this javascript :

/function getchat()//
//{ //
//$.post('/getchat')//.done(function(data, textStatus, jqXHR) //
//{//
//$("#chat").html(data["html"])//
//})//
//}

/Then whenever I call getchat() in javascript, the chat is reloaded with 
all the old lines, this point is ok, but
 field is reseted too, which mean that if user was typing, the 
content is erased.
I would say the solution is to create a second function in view 
/getchatcontent/ that will send only the content so I do not

update the whole thing. Do you think it is the right way ?


2.
lets use periodic request client-side.



Thank you for your answer

--
You received this message because you are subscribed to the Google Groups "Django 
users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.


Re: html templates and dynamic loading

2013-08-23 Thread Huu Da Tran
On Thursday, August 22, 2013 8:42:04 AM UTC-4, Bastien Amiel wrote:
 

> I need to update the chat when an event come but : 
>
> 1. 
> If I update my chat sub page, inputs are reset (seems logic since html 
> is recreated). 
>

You can always have some field that keep when the chat was started (in the 
session), and redisplay everything since that time.
 

> Then what would be the good / best method to update only the chat content 
> ? 
> (I have 2 ideas but they don't seems very Django'ic) 
>
> 2. 
> For now, I update the content every XX ms with a periodic request client 
> side. 
> Would it be possible / preferable to have a push from server when new 
> data comes or is there a better way to update this kind of content ?


Trying to hack django to get server push would be hell (look into tornado). 
If you really need server push, you may need to look into other 
technologies, like nodejs.

Using the periodic request client-side is what is mostly done.

 
Hope this helps.

HD.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.


html templates and dynamic loading

2013-08-22 Thread Bastien Amiel

Hi list,

I'm testing Django for a few days now and I have 2 questions.

I created for my tests a simple chat integrated in a base page (one 
template for the main page, and one for the chat).


I need to update the chat when an event come but :

1.
If I update my chat sub page, inputs are reset (seems logic since html 
is recreated).

Then what would be the good / best method to update only the chat content ?
(I have 2 ideas but they don't seems very Django'ic)

2.
For now, I update the content every XX ms with a periodic request client 
side.
Would it be possible / preferable to have a push from server when new 
data comes or is there a better way to update this kind of content ?



Thanks for reading

--
You received this message because you are subscribed to the Google Groups "Django 
users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.