コード例 #1
0
  def post(self):
    user = users.GetCurrentUser()

    jsonObj = json.loads(self.request.body)
    names = jsonObj["names"]
    events = jsonObj["events"]
    cycle_id = jsonObj["cycleId"]
    cycle_title = jsonObj["title"]

    cycle = None
    user_event_map = {}
    # Get the cycle and any existing users in the cycle.
    if (cycle_id):
      logging.info("getting cycle with id: " + cycle_id)
      cycle = db.get(db.Key.from_path(Cycle.kind(), cycle_id))
      if (cycle):
        logging.info("got cycle: " + str(cycle))
        user_event_map = util.getEmailToEventId(cycle)
    if (not cycle):
      # Create the cycle db entry
      if (not cycle_id):
        os_rand = os.urandom(30)
        cycle_id = id = hashlib.sha1(user.nickname() + '-' +
                   os_rand).hexdigest()

      cycle = Cycle(key_name = cycle_id, initiator = user, title = cycle_title)
      cycle.put()
      logging.info("Cycle with id \"" + cycle_id + "\" created by " +
          user.nickname())

    # Create the user db entries
    for event in events:
      logging.info("event: " + str(event))
      creator = event["owner"]
      if (not creator in names):
        logging.info("skipped due to creator being unselected: " + creator)
        continue
      if (not creator in user_event_map):
        user_event_map[creator] = []
      # Check to make sure we haven't already processed the event.
      if (not event["eventId"] in user_event_map[creator]):
        # Create a new event and put it in the map.
        user_event_map[creator].append(event)
        # Save the event for later.
        db_event = CalendarEvent(
            parent = cycle,
            owner = creator,
            calendar_id = event["calendarId"],
            event_id = event["eventId"],
            summary = event["summary"],
            event_location = event["location"],
            recurrence = event["recurrence"],
            start_time = event["startTime"],
            link = event["link"],
            state = "Pending")
        db_event.put()
        logging.info("created event: " + event["eventId"])
コード例 #2
0
  def post(self):
    user = users.GetCurrentUser()
    # TODO: Validate user is owner of current cycle.

    cycle_id = self.request.get('id')
    cycle = db.get(db.Key.from_path(Cycle.kind(), cycle_id))
    if not cycle:
      self.response.set_status(404, 'Cycle with id ' + cycle_id + ' not found.')
      return

    events_query = CalendarEvent.all(keys_only=True)
    events_query.ancestor(cycle)
    db.delete(events_query.run())
    db.delete(cycle)
    logging.info('Deleted cycle with id ' + cycle_id)
コード例 #3
0
    def post(self):
        user = users.GetCurrentUser()
        # TODO: Validate user is owner of the cycle containing the event.

        event_id = self.request.get("event_id")
        cycle_id = self.request.get("cycle_id")
        event = None

        if event_id and cycle_id:
            cycle_key = db.Key.from_path(Cycle.kind(), cycle_id)
            event = CalendarEvent.gql("WHERE event_id = :1 AND ANCESTOR IS :2", event_id, cycle_key).get()

        if event is not None:
            event.delete()
            logging.info("Deleted event with id " + event_id)
        else:
            self.response.set_status(404, "Event with id %s not found in " "cycle with id %s" % (event_id, cycle_id))