def show(self,student_id):
     student = Student.get_by_id(int(student_id))
     if student:
         self.response.write(json.dumps(student.dict()))
     else:
         """ Interesting thing here is validator doesn't really need to be called... """
         validator = Validator(student_id,"show",StudentHandler.valid_model)
         self.response.write(json.dumps(validator.error_message()))
 def delete(self,course_id):
     validator = Validator(course_id,'delete',CourseHandler.valid_model)
     course = Course.get_by_id(int(course_id))
     if course:
         course.key.delete()
         self.response.write(json.dumps(validator.success_message()))
     else:
         self.response.write(json.dumps(validator.error_message()))
 def show(self,course_id):
     course = Course.get_by_id(int(course_id))
     if course:
         self.response.write(json.dumps(course.dict()))
     else:
         """ Interesting thing here is validator doesn't really need to be called... """
         validator = Validator(course_id,"show",CourseHandler.valid_model)
         self.response.write(json.dumps(validator.error_message()))
 def delete(self,student_id):
     validator = Validator(student_id,'delete',StudentHandler.valid_model)
     student = Student.get_by_id(int(student_id))
     if student:
         student.key.delete()
         self.response.write(json.dumps(validator.success_message()))
     else:
         self.response.write(json.dumps(validator.error_message()))
 def delete(self, grade_id):
     validator = Validator(grade_id, "delete", GradeHandler.valid_model)
     grade = Grade.get_by_id(int(grade_id))
     if grade:
         grade.key.delete()
         self.response.write(json.dumps(validator.success_message()))
     else:
         self.response.write(json.dumps(validator.error_message()))
 def create(self):
     params = self.request.body
     validator=Validator(params,'create',StudentHandler.valid_model)
     if new_student_data:
         new_student=Student(
             name = new_student_data['name'],
             email = new_student_data['email']
              )
         new_student.put()
         self.response.write(json.dumps(new_student.dict()))
     else:
         self.response.write(json.dumps(validator.error_message()))
 def update(self, grade_id):
     grade = Grade.get_by_id(int(grade_id))
     params = self.request.body
     validator = Validator(params, "update", GradeHandler.valid_model)
     grade_update_data = validator.good_update_request()
     if grade and grade_update_data:
         if "score" in grade_update_data.keys():
             grade.score = grade_update_data["score"]
         grade.put()
         self.response.write(json.dumps(grade.dict()))
     else:
         self.response.write(json.dumps(validator.error_message()))
 def create(self):
     params = self.request.body
     validator=Validator(params,'create',CourseHandler.valid_model)
     new_course_data = validator.good_create_request()
     if new_course_data:
         new_course=Course(
             name = new_course_data['name'],
             description = new_course_data['description'],
             department_name = new_course_data['department_name'],
              )
         new_course.put()
         self.response.write(json.dumps(new_course.dict()))
     else:
         self.response.write(json.dumps(validator.error_message()))
 def update(self,student_id):
     student = Student.get_by_id(int(student_id))
     params = self.request.body
     validator=Validator(params,'update',StudentHandler.valid_model)
     student_update_data = validator.good_update_request()
     if student and student_update_data:
         if 'name' in student_update_data.keys():
             student.name = student_update_data['name']
         if 'email' in student_update_data.keys():
             student.email = student_update_data['email']
         student.put()
         self.response.write(json.dumps(student.dict()))
     else:
         self.response.write(json.dumps(validator.error_message()))
 def update(self,course_id):
     course = Course.get_by_id(int(course_id))
     params = self.request.body
     validator=Validator(params,'update',CourseHandler.valid_model)
     course_update_data = validator.good_update_request()
     if course and course_update_data:
         if 'name' in course_update_data.keys():
             course.name = course_update_data['name']
         if 'description' in course_update_data.keys():
             course.description = course_update_data['description']
         if 'department_name' in course_update_data.keys():
             course.department_name = course_update_data['department_name']
         course.put()
         self.response.write(json.dumps(course.dict()))
     else:
         self.response.write(json.dumps(validator.error_message()))
 def create(self):
     params = self.request.body
     validator = Validator(params, "create", GradeHandler.valid_model)
     new_grade_data = validator.good_create_request()
     if new_grade_data:
         #     grade = Grade.create(new_grade_data)
         #     if grade:
         #         return ...
         new_grade = Grade(score=new_grade_data["score"])
         s_key = new_grade_data.get("student_key")
         if s_key:
             student = Student.get_by_id(s_key)
             if student:
                 new_grade.student = student.key
         new_grade.put()
         self.response.write(json.dumps(new_grade.dict()))
     else:
         self.response.write(json.dumps(validator.error_message()))