Esempio n. 1
0
 def student_question(self, request):
     if g.lti.is_instructor():
         rv = []
         user_questions = UserQuestion.get_list(5)
         for q in user_questions:
             user = UserModel.by_user_id(q.user_id)
             if user is not None:
                 rv.append({'user':user.username, 'text':q.text, 'id':q.id})
     else:
         rv = dict({'error': True, 'type': ''})
         try:
             text = request.form['text']
         except KeyError:
             rv['type'] = 'key'
             return json.dumps(rv)
         
         min_delay = 10
         dt = UserQuestion.time_since_last(g.lti.get_user_id())
         if dt is not None and dt < min_delay:
             rv['type'] = 'time'
         else:
             rv['error'] = False
             UserQuestion.add(g.lti.get_user_id(), text)
     
     return json.dumps(rv)
Esempio n. 2
0
    def delete_userquestion(qid):
        '''removes the question with the provided id from the database'''
        question = UserQuestion.by_id(int(qid))
        if g.lti.is_instructor():
            session.delete(question)
            session.commit()

        return json.dumps({'deleted': g.lti.is_instructor()})