Ejemplo n.º 1
0
def event_join(host, guest):
   online_students = StudentRecord.online_students()
   ## Key error is possible
   guest_record = online_students[int(guest)]
   host_record = online_students[int(host)]
   host_channel = sse.current_channel(host)
   guest_channel = sse.current_channel(guest)
   sse.listen_to(host, guest)

   m = dict(cid=guest, host_cid=host, board_status=host_record.open_board)

   if host!=guest and int(host)!=int(host_channel):
      # host is elsewhere
      host_of_host = online_students[int(host_channel)]
      m.update(notice = "%s is visiting %s's sandbox" % (host_record.username, host_of_host.username))

   if guest_record.is_teacher:
      pids = sorted(int(i) for i in red.smembers('published-problems'))
      scores = [ [p, host_record.scores.get(p,0)] for p in pids ]
      m.update(scores=scores, brownies=host_record.brownies)

   sse.notify( { guest : m } , event='join')

   ## Inform old channel and new channel of updated listeners list
   guest_listeners = [ online_students[int(i)].username for i in sse.listening_clients(guest_channel) ]
   m = dict(host_cid=guest_channel, listeners=guest_listeners)
   sse.broadcast(guest_channel, m, m, event='listeners-update')

   host_listeners = [ online_students[int(i)].username for i in sse.listening_clients(host) ]
   m = dict(host_cid=host, listeners=host_listeners)
   sse.broadcast(host, m, m, event='listeners-update')
Ejemplo n.º 2
0
def event_chat(message, cid):
    chatter = StudentRecord(cid)
    channel = sse.current_channel(cid)
    teachers = StudentRecord.all_students(lambda v: v.is_teacher == True)
    m = dict(cid=channel,
             chat=message,
             chat_id=chat_id(),
             uid=chatter.id,
             username=chatter.username)
    sse.broadcast(channel,
                  m,
                  m,
                  additional_channels=teachers.keys(),
                  event='chat')
Ejemplo n.º 3
0
def event_join(host, guest):
    online_students = StudentRecord.online_students()
    ## Key error is possible
    guest_record = online_students[int(guest)]
    host_record = online_students[int(host)]
    host_channel = sse.current_channel(host)
    guest_channel = sse.current_channel(guest)
    sse.listen_to(host, guest)

    m = dict(cid=guest, host_cid=host, board_status=host_record.open_board)

    if host != guest and int(host) != int(host_channel):
        # host is elsewhere
        host_of_host = online_students[int(host_channel)]
        m.update(notice="%s is visiting %s's sandbox" %
                 (host_record.username, host_of_host.username))

    if guest_record.is_teacher:
        pids = sorted(int(i) for i in red.smembers('published-problems'))
        scores = [[p, host_record.scores.get(p, 0)] for p in pids]
        m.update(scores=scores, brownies=host_record.brownies)

    sse.notify({guest: m}, event='join')

    ## Inform old channel and new channel of updated listeners list
    guest_listeners = [
        online_students[int(i)].username
        for i in sse.listening_clients(guest_channel)
    ]
    m = dict(host_cid=guest_channel, listeners=guest_listeners)
    sse.broadcast(guest_channel, m, m, event='listeners-update')

    host_listeners = [
        online_students[int(i)].username for i in sse.listening_clients(host)
    ]
    m = dict(host_cid=host, listeners=host_listeners)
    sse.broadcast(host, m, m, event='listeners-update')
Ejemplo n.º 4
0
def event_chat(message, cid):
   chatter = StudentRecord(cid)
   channel = sse.current_channel(cid)
   teachers = StudentRecord.all_students( lambda v: v.is_teacher == True)
   m = dict(cid=channel, chat=message, chat_id=chat_id(), uid=chatter.id, username=chatter.username)
   sse.broadcast(channel, m, m, additional_channels=teachers.keys(), event='chat')
Ejemplo n.º 5
0
def event_send_code(message, cid):
   to_others = dict(cid=cid, code=message)
   sse.broadcast(cid, to_others, None, event='send-code')
Ejemplo n.º 6
0
def event_run_code(message, cid):
   output = execute_python_code(message)
   to_others = dict(cid=cid, output=output, code=message)
   to_self = dict(cid=cid, output=output)
   sse.broadcast(cid, to_others, to_self, event='run-code')
Ejemplo n.º 7
0
def event_send_code(message, cid):
    to_others = dict(cid=cid, code=message)
    sse.broadcast(cid, to_others, None, event='send-code')
Ejemplo n.º 8
0
def event_run_code(message, cid):
    output = execute_python_code(message)
    to_others = dict(cid=cid, output=output, code=message)
    to_self = dict(cid=cid, output=output)
    sse.broadcast(cid, to_others, to_self, event='run-code')