コード例 #1
0
ファイル: views.py プロジェクト: xgds/xgds_notes2
def broadcastNote(note):
    """
    Send the json note information out on SSE
    return json note information regardless
    """
    json_data = json.dumps([note.toMapDict()], cls=DatetimeJsonEncoder)

    if settings.XGDS_SSE:
        channels = note.getChannels()
        for channel in channels:
            send_event('notes', json_data, channel)
    return json_data
コード例 #2
0
ファイル: views.py プロジェクト: geocam/geocamTrackWeb
 def testPositions(request, trackId=None):
     activePositions = getActivePositions(trackId)
     if activePositions:
         json_data = modelsToJson(activePositions, DatetimeJsonEncoder)
         channel = 'live/positions'
         if trackId:
             channel = channel + '/' + str(trackId)
         json_data = ['{"now":' + datetime.datetime.now(pytz.utc).isoformat() + '}'] + json_data
         send_event('positions', json_data, channel)
         return HttpResponse(content=json_data,
                             content_type="application/json")
     return HttpResponse('No data')
コード例 #3
0
ファイル: views.py プロジェクト: geocam/geocamTrackWeb
 def sendActivePositions(trackId=None):
     while True:
         activePositions = getActivePositions(trackId)
         if activePositions:
             json_data = modelsToJson(activePositions, DatetimeJsonEncoder)
             channel = 'live/positions'
             theNow = datetime.datetime.now(pytz.utc).isoformat()
             if trackId:
                 json_data = ['{"now":' + theNow + '}'] + json_data
                 send_event('positions', json_data, channel + '/' + str(trackId))
             else:
                 for position in activePositions:
                     json_data = '{"now":' + theNow + '}' + modelToJson(position, DatetimeJsonEncoder)
                     send_event('positions', json_data, channel + '/' + str(position.track.pk))
         time.sleep(1)
コード例 #4
0
ファイル: views.py プロジェクト: rmoorman/django-sse-wrapper
def start_course(request, course_id):
    send_event('state', 'started', 'course-state/%s' % course_id)
    return HttpResponse('Course started!')