def post(self):
     user = users.get_current_user()
     q = HelpRequest.query(HelpRequest.in_queue == True,
                           HelpRequest.netid == user.email(),
                           ancestor=help_queue_key())
     if q.count() != 0:
         self.response.write('Unable to add to queue')
         return
     hr = HelpRequest(parent=help_queue_key())
     hr.netid = user.email()
     hr.name = self.request.get('name')
     hr.help_msg = self.request.get('help_msg')
     hr.course = self.request.get('course')
     hr.put()
     ChannelManager.queue_update()
Beispiel #2
0
 def post(self):
     user = users.get_current_user()
     q = HelpRequest.query(HelpRequest.in_queue == True,
                           HelpRequest.netid == user.email(),
                           ancestor=help_queue_key())
     if q.count() != 0:
         self.response.write('Unable to add to queue')
         return
     hr = HelpRequest(parent=help_queue_key())
     hr.netid = user.email()
     hr.name = self.request.get('name')
     hr.help_msg = self.request.get('help_msg')
     hr.course = self.request.get('course')
     hr.put()
     ChannelManager.queue_update()
Beispiel #3
0
 def post(self):
     q = HelpRequest.query(HelpRequest.in_queue == True,
                           ancestor=help_queue_key()).fetch()
     for hr in q:
         hr.canceled = True
         hr.put()
     ChannelManager.queue_update()
Beispiel #4
0
 def post(self):
     user = users.get_current_user()
     q = HelpRequest.query(HelpRequest.in_queue == True,
                           HelpRequest.netid == self.request.get('email'),
                           ancestor=help_queue_key())
     if q.count() != 1:
         logging.error("Database corrupted for user {}".format(
             user.email()))
         return
     if is_ta(user.email()):
         update_active_tas(user.email())
     hr = q.get()
     hr.canceled = True
     hr.put()
     ChannelManager.queue_update()
Beispiel #5
0
def get_json_queue():
    q = HelpRequest.query(ancestor=help_queue_key())
    q = q.filter(HelpRequest.been_helped == False)
    q = q.filter(HelpRequest.canceled == False)
    q = q.order(HelpRequest.request_datetime)
    q.fetch()
    queue = []
    for e in q:
        tmp = {}
        tmp['name'] = e.name
        tmp['email'] = e.netid
        tmp['help_msg'] = e.help_msg
        tmp['course'] = e.course
        queue.append(tmp)
    return json.dumps(queue)
Beispiel #6
0
def get_json_queue():
    q = HelpRequest.query(ancestor=help_queue_key())
    q = q.filter(HelpRequest.been_helped == False)
    q = q.filter(HelpRequest.canceled == False)
    q = q.order(HelpRequest.request_datetime)
    q.fetch()
    queue = []
    for e in q:
        current = {}
        # escape all strings before they are sent to JSON
        # to prevent XSS
        current['name'] = cgi.escape(e.name, True)
        current['email'] = cgi.escape(e.netid, True)
        current['help_msg'] = cgi.escape(e.help_msg, True)
        current['course'] = cgi.escape(e.course, True)
        current['id'] = e.key.id()
        current['full_id'] = e.key.urlsafe()
        queue.append(current)
    return json.dumps(queue)
Beispiel #7
0
    def post(self):
        user = users.get_current_user()

        # NOTE: previously this command could be run by anybody; now it
        # is restricted to TAs; consider restricting this further.
        
        if is_ta(user.email()):
          logging.info("User {} cleared the queue".format(user.email()))
          q = HelpRequest.query(HelpRequest.in_queue == True,
                                ancestor=help_queue_key()).fetch()
          for hr in q:
              hr.canceled = True

              # NOTE: same as above, if cancelled by TA, mark it.
              if hr.netid != user.email():
                   hr.attending_ta = user.email()
              
              hr.put()
          ChannelManager.queue_update()
Beispiel #8
0
def fetch_help_request(requester = None, full_id = None):
    """This method fetches the HelpRequest object from database that
    corresponds to the one that is to be processed by a call (currently
    'cancel' or 'mark_help'). Two ways of obtaining such an object is
    either by giving the requester's netid - in theory a given requester
    can only have one live query at a time - or by given the pickled
    primary key of the row in question."""
    
    hr = None
    
    # Best solution: get HelpRequest from pickled database key
    if full_id:
        try:
            key = ndb.Key(urlsafe = full_id)
            hr = key.get()
        except ProtocolBufferDecodeError:
            # This happens if the full_id is garbage (as even if the
            # full_id corresponds to a key that no longer exists it should
            # be unpickled correctly - in this case the key.get() will
            # simply return None).
            
            logging.error(
              "Could not recover HelpRequest from bad id {}".format(full_id))
        
        if hr:
            return hr
          
        logging.error("Failed HelpRequest access from id {}".format(full_id))

    # Fallback: get HelpRequest by querying for open requests by a user
    if requester:
        q = HelpRequest.query(HelpRequest.in_queue == True,
                              HelpRequest.netid == requester,
                              ancestor=help_queue_key())

        # NOTE: Not sure this is very helpful...
        if q.count() != 1:
            logging.error("Database corrupt for requester {}".format(requester))
            return
        
        hr = q.get()
        return hr
Beispiel #9
0
 def post(self):
     user = users.get_current_user()
     q = HelpRequest.query(HelpRequest.in_queue == True,
                           HelpRequest.netid == self.request.get('email'),
                           ancestor=help_queue_key())
     if q.count() != 1:
         logging.error("Database corrupted for user {}".format(
             user.email()))
         return
     update_active_tas(user.email())
     hr = q.get()
     hr.been_helped = True
     hr.helped_datetime = datetime.utcnow()
     hr.attending_ta = user.email()
     hr.put()
     ChannelManager.queue_update()
     ta = LabTA.query(LabTA.email == hr.attending_ta,
                      ancestor=labta_key()).fetch()[0]
     ChannelManager.notify_request_accepted(hr.netid, ta.first_name,
                                            ta.img_path)