Ejemplo n.º 1
0
    def get(self):
        user = self.get_current_user()
        if not user:
            self.redirect("/")
            return

        key = db.Key(encoded=self.request.get("key"))
        course = Course.get(key)
        class_key = db.Key(encoded=self.request.get("class"))

        goto = self.request.get("goto")
        if goto == None or goto == "":
            goto = "/"

        # if class is different copy list to the new class
        if class_key != course.parent_key():
            aclass = Class.get(class_key)
            newCourse = Course(parent=aclass)
            newCourse.name = course.name
            newCourse.chapters = course.chapters
            newCourse.count_questions()
            newCourse.put()

        self.stop_edit_course()

        self.redirect(goto)
Ejemplo n.º 2
0
 def put(self,Id):
     """Save a class with key == Id"""
     clss = Class.get( db.Key(encoded=Id) )
     if clss:
         jsn = json.decoder.JSONDecoder()
         model = jsn.decode( self.request.get('model'))
         clss.name = model['name']
         clss.put()
     else:
         raise Exception('Saving of class failed')
Ejemplo n.º 3
0
    def post(self,Id=None):
        """Create new class instance and retirn its id which is its key"""
        teacher = self.get_current_teacher()
        if not teacher:
            self.redirect('/')
            return
        
        #raise Exception('uri='+self.request.uri)
            
        httpMethod = self.request.get('_method')
        if httpMethod == 'PUT':
            self.put(Id)
            return
        if httpMethod == 'DELETE':
            #raise Exception("deleting...")
            self.delete(Id)
            return
        if httpMethod == 'GET':
            raise Exception('GET not implemented')
            return
            
        jsn = json.decoder.JSONDecoder()
        #raise Exception('model '+self.request.get('model'))
        model = jsn.decode( self.request.get('model'))
        
        if not 'clss' in model:
            raise Exception('Class is missing from model.')
            
        logger.info('Create student '+str(model))
        try:
            student = create_user(model)
        except:
            self.response.out.write('error')
            return
        
        clss_encoded_key = model['clss']
        clss = Class.get( db.Key(encoded=clss_encoded_key) )
        if clss != None:
            #try:
            clss.add_student(student)
            #except:
            #    raise Exception('failed to add student')
        else:
            raise Exception('Class not found.')

        #raise Exception('stu key: '+str(self.request.uri) + ' ' + str(model))
        self.response.out.write('{"id":"'+str(student.key())+'"}')
Ejemplo n.º 4
0
 def delete(self, Id):
     """Delete a user with key == Id"""
     user = Class.get( db.Key(encoded=Id) )
     if user:
         user.delete()