Re: Chrome Desktop Notification for Django

2014-11-17 Thread Collin Anderson
Hello,

The frontend part is simple:

var myEventSource = new EventSource('/path/to/eventsource/');
myEventSource.onmessage = function(e) {
  console.log(e.data)
}

The backend part is where things get complicated (untested code, as always 
:)
def eventsource(request):
last_id = request.META.get('HTTP_LAST_EVENT_ID')
id, data = get_new_data()  # somehow wait for some new data, and 
timeout after 10-50 seconds.
if not data:
  return HttpResponse('', content_type='text/event-stream')
assert '\n\n' not in data, 'two line breaks in a row signifies an end 
of message'
return HttpResponse('id: %s\ndata: %s' % (id, data), content_type=
'text/event-stream')

Collin

On Thursday, November 13, 2014 8:25:07 PM UTC-5, Max Nathaniel Ho wrote:
>
> HI Collin,
>
> Thanks for pointing that out. Apart from the documentation, do you have 
> any examples of how to implement it?
>
> Thank you.
>
> On Thu, Nov 13, 2014 at 5:55 AM, Collin Anderson  > wrote:
>
>> Hello,
>>
>> From a front-end standpoint, I personally like EventSource for this, 
>> though you could also use websockets or polling (checking every few 
>> minutes/seconds).
>>
>> https://developer.mozilla.org/en-US/docs/Web/API/EventSource
>> http://en.wikipedia.org/wiki/Server-sent_events
>>
>> Collin
>>
>> On Tuesday, November 11, 2014 8:12:43 PM UTC-5, Max Nathaniel Ho wrote:
>>>
>>> I found this excellent example on Chrome Desktop Notification - Chrome 
>>> desktop notification example? 
>>> 
>>>
>>> I am able to create the Desktop Notification by clicking a button. 
>>>
>>> However, that is pretty front-end. 
>>>
>>> I would like to find out how to link an event in the web app. For 
>>> example,  the event could be someone posting a job for a freelance work. 
>>> And user who is logged into the web app but not actively browsing on the 
>>> web page will be notified via the Chrome Desktop Notification. 
>>>
>>> Are there any examples of how I can create a Event Handler to listen to 
>>> data in the backend, and prompt the user via the Desktop Notification?
>>>
>>> Many thanks!
>>>
>>  

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/6b4132fb-0169-4a35-bec9-09b7ac987ba8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Chrome Desktop Notification for Django

2014-11-13 Thread Max Nathaniel Ho
HI Collin,

Thanks for pointing that out. Apart from the documentation, do you have any
examples of how to implement it?

Thank you.

On Thu, Nov 13, 2014 at 5:55 AM, Collin Anderson 
wrote:

> Hello,
>
> From a front-end standpoint, I personally like EventSource for this,
> though you could also use websockets or polling (checking every few
> minutes/seconds).
>
> https://developer.mozilla.org/en-US/docs/Web/API/EventSource
> http://en.wikipedia.org/wiki/Server-sent_events
>
> Collin
>
> On Tuesday, November 11, 2014 8:12:43 PM UTC-5, Max Nathaniel Ho wrote:
>>
>> I found this excellent example on Chrome Desktop Notification - Chrome
>> desktop notification example?
>> 
>>
>> I am able to create the Desktop Notification by clicking a button.
>>
>> However, that is pretty front-end.
>>
>> I would like to find out how to link an event in the web app. For
>> example,  the event could be someone posting a job for a freelance work.
>> And user who is logged into the web app but not actively browsing on the
>> web page will be notified via the Chrome Desktop Notification.
>>
>> Are there any examples of how I can create a Event Handler to listen to
>> data in the backend, and prompt the user via the Desktop Notification?
>>
>> Many thanks!
>>
>  --
> You received this message because you are subscribed to a topic in the
> Google Groups "Django users" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/django-users/64rg0i9ChyY/unsubscribe.
> To unsubscribe from this group and all its topics, 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.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/c162fe08-81fa-4a25-aa55-30bd2821ce2b%40googlegroups.com
> 
> .
>
> For more options, visit https://groups.google.com/d/optout.
>



-- 
Regards,
Max Nathaniel Ho.

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAMognGFTsKL5dHEUxAdx3VkbjDHe-nXkEi8uq_riPmnwuLWf4w%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Chrome Desktop Notification for Django

2014-11-12 Thread Collin Anderson
Hello,

>From a front-end standpoint, I personally like EventSource for this, though 
you could also use websockets or polling (checking every few 
minutes/seconds).

https://developer.mozilla.org/en-US/docs/Web/API/EventSource
http://en.wikipedia.org/wiki/Server-sent_events

Collin

On Tuesday, November 11, 2014 8:12:43 PM UTC-5, Max Nathaniel Ho wrote:
>
> I found this excellent example on Chrome Desktop Notification - Chrome 
> desktop notification example? 
> 
>
> I am able to create the Desktop Notification by clicking a button. 
>
> However, that is pretty front-end. 
>
> I would like to find out how to link an event in the web app. For example, 
>  the event could be someone posting a job for a freelance work. And user 
> who is logged into the web app but not actively browsing on the web page 
> will be notified via the Chrome Desktop Notification. 
>
> Are there any examples of how I can create a Event Handler to listen to 
> data in the backend, and prompt the user via the Desktop Notification?
>
> Many thanks!
>

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/c162fe08-81fa-4a25-aa55-30bd2821ce2b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Chrome Desktop Notification for Django

2014-11-11 Thread Max Nathaniel Ho


I found this excellent example on Chrome Desktop Notification - Chrome 
desktop notification example? 


I am able to create the Desktop Notification by clicking a button. 

However, that is pretty front-end. 

I would like to find out how to link an event in the web app. For example, 
 the event could be someone posting a job for a freelance work. And user 
who is logged into the web app but not actively browsing on the web page 
will be notified via the Chrome Desktop Notification. 

Are there any examples of how I can create a Event Handler to listen to 
data in the backend, and prompt the user via the Desktop Notification?

Many thanks!

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/7e07f9eb-1009-4bc2-b254-7f2637231284%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.