Esempio n. 1
0
    def put(self, idArg):
        User = users.get_current_user()
        if User:
            student = db.GqlQuery("SELECT * FROM Student WHERE user = :1",
                                  User).get()
            course = db.GqlQuery(
                "SELECT * FROM Course WHERE ANCESTOR IS :1 AND id = :2",
                models.student_key(User), int(idArg)).get()

            if course == None:
                self.response.out.write("couldnt find class to edit")
                return

            info = json.loads(self.request.body)

            # update class in google calendar
            eventInfo = utils.createClassEvent(info)
            event = eventInfo["event"]
            event["sequence"] = int(course.eventseq)
            logging.warning(event)
            request = service.events().update(calendarId=student.calID,
                                              eventId=course.eventid,
                                              body=event)
            logging.warning(course.eventid + " " + student.calID)
            response = request.execute(http=decorator.http())
            logging.warning(json.dumps(response))

            # edit the course
            course.type = info["type"]
            course.title = info["title"]
            course.days = eventInfo["days"]
            course.start = info["start"]
            course.end = info["end"]
            course.start_time = info["start_time"]
            course.end_time = info["end_time"]
            course.location = info["location"]
            course.instructor = info["instructor"]
            course.site_link = info["site_link"]
            course.prof_email = info["prof_email"]
            course.eventid = course.eventid
            course.eventseq = response["sequence"]

            course.put()
        else:
            self.response.out.write("['auth':'fail']")
Esempio n. 2
0
  def put(self, idArg):
    User = users.get_current_user()
    if User:
      student = db.GqlQuery("SELECT * FROM Student WHERE user = :1", User).get()
      course = db.GqlQuery("SELECT * FROM Course WHERE ANCESTOR IS :1 AND id = :2",
        models.student_key(User), int(idArg)).get()

      if course == None :
        self.response.out.write("couldnt find class to edit")
        return

      info = json.loads(self.request.body)

      # update class in google calendar
      eventInfo = utils.createClassEvent(info)
      event = eventInfo["event"]
      event["sequence"] = int(course.eventseq)
      logging.warning(event)
      request = service.events().update(calendarId=student.calID,
          eventId=course.eventid, body=event)
      logging.warning(course.eventid + " " + student.calID)
      response = request.execute(http=decorator.http())
      logging.warning(json.dumps(response))

      # edit the course
      course.type = info["type"]
      course.title = info["title"]
      course.days = eventInfo["days"]
      course.start = info["start"]
      course.end = info["end"]
      course.start_time = info["start_time"]
      course.end_time = info["end_time"]
      course.location = info["location"]
      course.instructor = info["instructor"]
      course.site_link = info["site_link"]
      course.prof_email = info["prof_email"]
      course.eventid = course.eventid
      course.eventseq = response["sequence"]

      course.put()
    else:
      self.response.out.write("['auth':'fail']")
Esempio n. 3
0
    def post(self):

        User = users.get_current_user()
        if User:
            student = db.GqlQuery("SELECT * FROM Student WHERE user = :1",
                                  User).get()

            info = json.loads(self.request.body)
            logging.warning(info)

            if student == None:
                self.response.out.write("student is null")
                return

            dup_course = db.GqlQuery(
                "SELECT * FROM Course WHERE ANCESTOR IS :1 AND id = :2",
                models.student_key(User), int(info["courseId"])).get()

            if dup_course != None:
                logging.warning("duplicate course")
                self.response.out.write("already in this course")
                return

            # create the courses calendar if it doesn't already exist
            if student.calID is None or student.calID == "":
                logging.warning('student calID is in fact empty')
                self.response.out.write(
                    "student calendar is empty in api, not adding course")
                return
            else:
                logging.warning('student id is something else, it is %s' %
                                student.calID)

            courseInfo = utils.createClassEvent(info)
            logging.warning(courseInfo)
            event = courseInfo["event"]
            request = service.events().insert(calendarId=student.calID,
                                              body=event)
            response = request.execute(http=decorator.http())

            logging.warning(json.dumps(response))

            newCourse = models.Course(parent=models.student_key(User))
            newCourse.id = info["courseId"]
            newCourse.code = info["code"]
            newCourse.number = info["number"]
            newCourse.section = info["section"]
            newCourse.type = info["type"]
            newCourse.title = info["title"]
            newCourse.days = courseInfo["days"]
            newCourse.start_time = info["start_time"]
            newCourse.end_time = info["end_time"]
            newCourse.start = info["start"]
            newCourse.end = info["end"]
            newCourse.location = info["location"]
            newCourse.instructor = info["instructor"]
            newCourse.prof_email = info["prof_email"]
            newCourse.site_link = info["site_link"]
            newCourse.eventid = response["id"]
            newCourse.eventseq = response["sequence"]
            newCourse.semester_id = "SP13"  # should not be hardcoded in the future

            newCourse.put()
            # respond with changes so backbone knows the id
            self.response.out.write(json.dumps(models.serialize(newCourse)))
        else:
            self.response.out.write("['auth':'fail']")
Esempio n. 4
0
  def post(self):
 
    User = users.get_current_user()
    if User:
      student = db.GqlQuery("SELECT * FROM Student WHERE user = :1", User).get()

      info = json.loads(self.request.body)   
      logging.warning(info)

      if student == None :
        self.response.out.write("student is null")
        return

      dup_course = db.GqlQuery("SELECT * FROM Course WHERE ANCESTOR IS :1 AND id = :2",
        models.student_key(User), int(info["courseId"])).get()

      if dup_course != None :
        logging.warning("duplicate course")
        self.response.out.write("already in this course")
        return

      # create the courses calendar if it doesn't already exist
      if student.calID is None or student.calID == "":
        logging.warning('student calID is in fact empty')
        self.response.out.write("student calendar is empty in api, not adding course")
        return
      else:
        logging.warning('student id is something else, it is %s' % student.calID)

      courseInfo = utils.createClassEvent(info)
      logging.warning(courseInfo)
      event = courseInfo["event"]
      request = service.events().insert(calendarId=student.calID, body=event)
      response = request.execute(http=decorator.http())

      logging.warning(json.dumps(response))

      newCourse = models.Course(parent=models.student_key(User))
      newCourse.id = info["courseId"]
      newCourse.code = info["code"]
      newCourse.number = info["number"]
      newCourse.section = info["section"]
      newCourse.type = info["type"]
      newCourse.title = info["title"]
      newCourse.days = courseInfo["days"]
      newCourse.start_time = info["start_time"]
      newCourse.end_time = info["end_time"]
      newCourse.start = info["start"]
      newCourse.end = info["end"]
      newCourse.location = info["location"]
      newCourse.instructor = info["instructor"]
      newCourse.prof_email = info["prof_email"]
      newCourse.site_link = info["site_link"]
      newCourse.eventid = response["id"]
      newCourse.eventseq = response["sequence"]
      newCourse.semester_id = "SP13" # should not be hardcoded in the future
      
      newCourse.put()
      # respond with changes so backbone knows the id
      self.response.out.write(json.dumps(models.serialize(newCourse)))
    else:
      self.response.out.write("['auth':'fail']")