Exemple #1
0
def logout_and_cleanup(uid=None, next_url=None, logout=False):
   online_students = StudentRecord.online_students()

   if uid is None:
      user = auth.get_logged_in_user()
      auth.logout_user(user)
   else:
      user = auth.User.get(auth.User.id == uid)
      auth.logout_user(user, self_logout=False)

   user_record = StudentRecord(user.id)
   user_record.open_board = False
   user_record.online = False
   user_record.save()

   listening_clients = sse.listening_clients(user.id)

   # Turn off menu/tabs of all listeners and tell them to go home
   mesg = {}
   for cid in online_students:
      mesg[cid] = dict(cid=user.id)
      if cid in listening_clients or cid==user.id:
         mesg[cid].update(home_cid = cid)
         sse.listen_to(cid, cid)
   sse.notify(mesg, event="log-out")

   sse.close(user_record.id, logout)

   return redirect( next_url or url_for('index') )
Exemple #2
0
def index():
   logged_in_user = auth.get_logged_in_user()

   user_record = StudentRecord(logged_in_user.id)
   user_record.online = True
   user_record.save()

   # if user is running on another client, close the other.
   sse.close(user_record.id)

   current_channel = sse.current_channel(user_record.id) or user_record.id

   all_users = auth.User.select()
   online_students = StudentRecord.online_students()
   listeners=[ online_students[int(i)].username \
      for i in sse.listening_clients(current_channel) if int(i) in online_students ]

   # notify those who can view boards that the client is online
   messages = {}
   for c, r in online_students.items():
      if user_record.id != c and (r.is_teacher or user_record.open_board):
         messages[c] = dict(cid=user_record.id, board_status=user_record.open_board)
   sse.notify(messages, event='online')

   problem_ids = sorted(int(i) for i in red.smembers('published-problems'))

   return render_template('sandbox.html',
      sum=sum, enumerate=enumerate,
      current_channel = current_channel,
      problem_ids=problem_ids,
      user_record = user_record,
      online_students = online_students,
      all_users = all_users,
      listeners = listeners)
Exemple #3
0
def logout_and_cleanup(uid=None, next_url=None, logout=False):
    online_students = StudentRecord.online_students()

    if uid is None:
        user = auth.get_logged_in_user()
        auth.logout_user(user)
    else:
        user = auth.User.get(auth.User.id == uid)
        auth.logout_user(user, self_logout=False)

    user_record = StudentRecord(user.id)
    user_record.open_board = False
    user_record.online = False
    user_record.save()

    listening_clients = sse.listening_clients(user.id)

    # Turn off menu/tabs of all listeners and tell them to go home
    mesg = {}
    for cid in online_students:
        mesg[cid] = dict(cid=user.id)
        if cid in listening_clients or cid == user.id:
            mesg[cid].update(home_cid=cid)
            sse.listen_to(cid, cid)
    sse.notify(mesg, event="log-out")

    sse.close(user_record.id, logout)

    return redirect(next_url or url_for('index'))
Exemple #4
0
def index():
    logged_in_user = auth.get_logged_in_user()

    user_record = StudentRecord(logged_in_user.id)
    user_record.online = True
    user_record.save()

    # if user is running on another client, close the other.
    sse.close(user_record.id)

    current_channel = sse.current_channel(user_record.id) or user_record.id

    all_users = auth.User.select()
    online_students = StudentRecord.online_students()
    listeners=[ online_students[int(i)].username \
       for i in sse.listening_clients(current_channel) if int(i) in online_students ]

    # notify those who can view boards that the client is online
    messages = {}
    for c, r in online_students.items():
        if user_record.id != c and (r.is_teacher or user_record.open_board):
            messages[c] = dict(cid=user_record.id,
                               board_status=user_record.open_board)
    sse.notify(messages, event='online')

    problem_ids = sorted(int(i) for i in red.smembers('published-problems'))

    return render_template('sandbox.html',
                           sum=sum,
                           enumerate=enumerate,
                           current_channel=current_channel,
                           problem_ids=problem_ids,
                           user_record=user_record,
                           online_students=online_students,
                           all_users=all_users,
                           listeners=listeners)