Exemple #1
0
    def delete(self, idArg):
        User = users.get_current_user()
        if User:
            student = db.GqlQuery("SELECT * FROM Student WHERE user = :1",
                                  User).get()
            reminder = db.GqlQuery(
                "SELECT * FROM Reminder WHERE ANCESTOR IS :1 AND id = :2",
                models.student_key(User), int(idArg)).get()

            if reminder == None:
                self.response.out.write(
                    "failed to find single reminder to delete")
                return

            eventid = reminder.eventid

            reminder.delete()

            if eventid == "":
                self.response.out.write("deleted reminder only from db")
            else:
                # delete reminder from google calendar
                logging.warning("about to delete reminder from gcal")
                request = service.events().delete(calendarId=student.calID,
                                                  eventId=eventid)
                response = request.execute(http=decorator.http())
                if response is not None and response != "":
                    logging.warning(response)
                self.response.out.write("deleted reminder from db AND gcal")
        else:
            self.response.out.write("['auth':'fail']")
Exemple #2
0
  def delete(self, idArg):
    User = users.get_current_user()
    if User:
      student = db.GqlQuery("SELECT * FROM Student WHERE user = :1", User).get()
      reminder = db.GqlQuery("SELECT * FROM Reminder WHERE ANCESTOR IS :1 AND id = :2",
        models.student_key(User), int(idArg)).get()

      if reminder == None :
        self.response.out.write("failed to find single reminder to delete")
        return

      eventid = reminder.eventid

      reminder.delete()

      if eventid == "" :
        self.response.out.write("deleted reminder only from db")
      else :
        # delete reminder from google calendar
        logging.warning("about to delete reminder from gcal")
        request = service.events().delete(calendarId=student.calID, eventId=eventid)
        response = request.execute(http=decorator.http())
        if response is not None and response != "":
          logging.warning(response)
        self.response.out.write("deleted reminder from db AND gcal")
    else: 
      self.response.out.write("['auth':'fail']");
Exemple #3
0
    def delete(self, idArg):
        User = users.get_current_user()  # dont do this so often ***
        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("couldn't find class to delete")
                return

            eventid = course.eventid
            course.delete()

            # delete class from google calendar
            logging.warning("deleting class")
            request = service.events().delete(calendarId=student.calID,
                                              eventId=eventid)
            response = request.execute(http=decorator.http())

            if response is not None and response != "":
                logging.warning(json.dumps(response))

            self.response.out.write("deleted class")
        else:
            self.response.out.write("['auth':'fail']")
Exemple #4
0
  def delete(self, idArg):
    User = users.get_current_user() # dont do this so often ***
    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("couldn't find class to delete")
        return

      eventid = course.eventid
      course.delete()

      # delete class from google calendar
      logging.warning("deleting class")
      request = service.events().delete(calendarId=student.calID, eventId=eventid)
      response = request.execute(http=decorator.http())

      if response is not None and response != "":
        logging.warning(json.dumps(response))

      self.response.out.write("deleted class")
    else: 
      self.response.out.write("['auth':'fail']");
Exemple #5
0
    def post(self):

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

            #logging.warning("going to get credentials")
            #credentials = decorator.credentials
            #logging.warning("going to refresh credentials")
            #credentials.refresh(http=decorator.http())
            #logging.warning("refreshed credentials")

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

            newReminder = models.Reminder(parent=models.student_key(User))

            newReminder.type = postData['type']
            newReminder.title = postData['title']
            newReminder.course_str = postData['course_str']
            newReminder.completed = False
            newReminder.date = postData['date']
            newReminder.start_time = postData['start_time']
            newReminder.end_time = postData['end_time']
            newReminder.course = postData['course']
            newReminder.note = postData['note']
            newReminder.id = int(time.time())  # do we need to rand here too?
            newReminder.eventid = ""
            newReminder.eventseq = -1
            newReminder.alert_min = int(postData['alert_min'])
            newReminder.deleted = False
            newReminder.semester_id = "SP13"  # eventually not hardcoded

            if postData['add_to_cal'] == True:
                newReminder.add_to_cal = True
                event = utils.createReminderEvent(postData)
                logging.warning(event)
                request = service.events().insert(calendarId=student.calID,
                                                  body=event)
                response = request.execute(http=decorator.http())

                if response is not None and response != "":
                    logging.warning(json.dumps(response))
                    newReminder.eventid = response["id"]
                    newReminder.eventseq = response["sequence"]
            else:
                newReminder.add_to_cal = False

            newReminder.put()
            logging.warning("added reminder to db")

            self.response.out.write(json.dumps(models.serialize(newReminder)))
        else:
            self.response.out.write("['auth':'fail']")
Exemple #6
0
  def get(self):
    User = users.get_current_user()
    if User:
      courses = db.GqlQuery("SELECT * FROM Course WHERE ANCESTOR IS :1", models.student_key(User))

      output = []
      for x in courses :
        output.append(models.serialize(x))

      self.response.out.write(json.dumps(output))
    else: 
      self.response.out.write("['auth':'fail']")
Exemple #7
0
  def post(self):
    
    User = users.get_current_user()
    if User:
      student = db.GqlQuery("SELECT * FROM Student WHERE user = :1", User).get()

      #logging.warning("going to get credentials")
      #credentials = decorator.credentials
      #logging.warning("going to refresh credentials")
      #credentials.refresh(http=decorator.http())
      #logging.warning("refreshed credentials")

      postData = json.loads(self.request.body)
      logging.warning(postData)
     
      newReminder = models.Reminder(parent=models.student_key(User))

      newReminder.type = postData['type']
      newReminder.title = postData['title']
      newReminder.course_str = postData['course_str']
      newReminder.completed = False
      newReminder.date =  postData['date']
      newReminder.start_time = postData['start_time']
      newReminder.end_time = postData['end_time']
      newReminder.course = postData['course']
      newReminder.note = postData['note']
      newReminder.id = int(time.time()) # do we need to rand here too?
      newReminder.eventid = ""
      newReminder.eventseq = -1
      newReminder.alert_min = int(postData['alert_min'])
      newReminder.deleted = False
      newReminder.semester_id = "SP13" # eventually not hardcoded

      if postData['add_to_cal'] == True :
        newReminder.add_to_cal = True
        event = utils.createReminderEvent(postData)
        logging.warning(event)
        request = service.events().insert(calendarId=student.calID, body=event)
        response = request.execute(http=decorator.http())

        if response is not None and response != "" :
          logging.warning(json.dumps(response))
          newReminder.eventid = response["id"]
          newReminder.eventseq = response["sequence"]
      else :
        newReminder.add_to_cal = False

      newReminder.put()
      logging.warning("added reminder to db")

      self.response.out.write(json.dumps(models.serialize(newReminder)))
    else :
      self.response.out.write("['auth':'fail']")
Exemple #8
0
    def get(self):
        User = users.get_current_user()
        if User:
            courses = db.GqlQuery("SELECT * FROM Course WHERE ANCESTOR IS :1",
                                  models.student_key(User))

            output = []
            for x in courses:
                output.append(models.serialize(x))

            self.response.out.write(json.dumps(output))
        else:
            self.response.out.write("['auth':'fail']")
Exemple #9
0
  def get(self):
    User = users.get_current_user()
    if User:
      reminders = db.GqlQuery("SELECT * FROM Reminder WHERE ANCESTOR IS :1", models.student_key(User))

      output = []
      for x in reminders :
        #if(self.request.get('showAll') == "true" or x.completed == False):
          output.append(models.serialize(x))

      self.response.out.write(json.dumps(output))
    else: 
      self.response.out.write("['auth':'fail']")
Exemple #10
0
    def get(self):
        User = users.get_current_user()
        if User:
            reminders = db.GqlQuery(
                "SELECT * FROM Reminder WHERE ANCESTOR IS :1",
                models.student_key(User))

            output = []
            for x in reminders:
                #if(self.request.get('showAll') == "true" or x.completed == False):
                output.append(models.serialize(x))

            self.response.out.write(json.dumps(output))
        else:
            self.response.out.write("['auth':'fail']")
Exemple #11
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']")
Exemple #12
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']")
Exemple #13
0
    def put(self, idArg):
        User = users.get_current_user()
        if User:
            student = db.GqlQuery("SELECT * FROM Student WHERE user = :1",
                                  User).get()
            reminder = db.GqlQuery(
                "SELECT * FROM Reminder WHERE ANCESTOR IS :1 AND id = :2",
                models.student_key(User), int(idArg)).get()

            if reminder == None:
                self.response.out.write(
                    "couldn't find a single reminder to edit")
                return

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

            reminder.course = 0
            if (info['course']):
                reminder.course = int(info['course'])
            reminder.course_str = info['course_str']
            reminder.type = info['type']
            reminder.title = info['title']
            reminder.completed = info['completed']
            reminder.date = info['date']
            reminder.note = info['note']
            reminder.start_time = info['start_time']
            reminder.end_time = info['end_time']
            if (info['alert_min']):
                reminder.alert_min = int(info['alert_min'])

            if info['add_to_cal'] == True:
                event = utils.createReminderEvent(info)
                logging.warning(event)

                if reminder.add_to_cal == False:
                    # reminder was NOT on calendar before, add it
                    request = service.events().insert(calendarId=student.calID,
                                                      body=event)
                    response = request.execute(http=decorator.http())
                    logging.warning(json.dumps(response))
                    reminder.eventid = response["id"]
                    reminder.eventseq = response["sequence"]
                else:
                    # reminder was on calendar before, edit it
                    event["sequence"] = int(reminder.eventseq)
                    request = service.events().update(calendarId=student.calID,
                                                      eventId=reminder.eventid,
                                                      body=event)
                    response = request.execute(http=decorator.http())
                    logging.warning(json.dumps(response))
                    reminder.eventseq = response["sequence"]

                reminder.add_to_cal = True

            else:
                if reminder.add_to_cal == True:
                    # reminder was on calendar before, delete it from calendar
                    request = service.events().delete(calendarId=student.calID,
                                                      eventId=reminder.eventid)
                    response = request.execute(http=decorator.http())
                    logging.warning(response)
                    reminder.eventid = ""
                    reminder.eventseq = -1

                reminder.add_to_cal = False

            reminder.put()

            self.response.out.write("completed reminders")
        else:
            self.response.out.write("['auth':'fail']")
Exemple #14
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']")
Exemple #15
0
  def put(self, idArg):
    User = users.get_current_user()
    if User:
      student = db.GqlQuery("SELECT * FROM Student WHERE user = :1", User).get()
      reminder = db.GqlQuery("SELECT * FROM Reminder WHERE ANCESTOR IS :1 AND id = :2",
        models.student_key(User), int(idArg)).get()

      if reminder == None :
        self.response.out.write("couldn't find a single reminder to edit")
        return

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

      reminder.course = 0
      if (info['course']):
        reminder.course = int(info['course'])
      reminder.course_str = info['course_str']
      reminder.type = info['type']
      reminder.title = info['title']
      reminder.completed = info['completed']
      reminder.date =  info['date']
      reminder.note = info['note']
      reminder.start_time = info['start_time']
      reminder.end_time = info['end_time']
      if (info['alert_min']):
        reminder.alert_min = int(info['alert_min'])

      if info['add_to_cal'] == True :
        event = utils.createReminderEvent(info)
        logging.warning(event)

        if reminder.add_to_cal == False :
          # reminder was NOT on calendar before, add it
          request = service.events().insert(calendarId=student.calID, body=event)
          response = request.execute(http=decorator.http())
          logging.warning(json.dumps(response))
          reminder.eventid = response["id"]
          reminder.eventseq = response["sequence"]
        else :
          # reminder was on calendar before, edit it
          event["sequence"] = int(reminder.eventseq)
          request = service.events().update(calendarId=student.calID,
              eventId=reminder.eventid, body=event)
          response = request.execute(http=decorator.http())
          logging.warning(json.dumps(response))
          reminder.eventseq = response["sequence"]

        reminder.add_to_cal = True;

      else :
        if reminder.add_to_cal == True :
          # reminder was on calendar before, delete it from calendar
          request = service.events().delete(calendarId=student.calID, eventId=reminder.eventid)
          response = request.execute(http=decorator.http())
          logging.warning(response)
          reminder.eventid = ""
          reminder.eventseq = -1

        reminder.add_to_cal = False;

      reminder.put()

      self.response.out.write("completed reminders")
    else: 
      self.response.out.write("['auth':'fail']");
Exemple #16
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']")