Exemplo n.º 1
0
  def post(self):
    try:
      json_item = json.loads(self.request.body)
      converted = ndb_json.ConvertToNdb(model.Event, json_item)
      activity = converted['activity'].get()
      start_time = converted['start_time']
      user_key = activity.submitted_by_user

      if not activity:
        self.abort(httplib.BAD_REQUEST, u'הפעילות לא קיימת')
        return

      collides_with = Event.CollidesWith(
          start_time, activity.duration_minutes, user_key)
      if collides_with:
        self.abort(httplib.BAD_REQUEST, collides_with)
        return

      converted['crew'].append(activity.submitted_by_user)
      item = model.Event(**converted)
      item.put()
      self.SendJson(ndb_json.AsDict(item))
    except Exception as e:
      raise
      self.abort(httplib.BAD_REQUEST, u'Invalid request')
Exemplo n.º 2
0
 def post(self):
     args = json.loads(self.request.body)
     if 'key' not in args:
         self.abort(httplib.BAD_REQUEST)
     key = args['key']
     del args['key']
     item = Cls.Update(key, **args)
     self.SendJson(ndb_json.AsDict(item, False))
Exemplo n.º 3
0
 def get(self):
     key = self.request.get('key')
     recursive = self.request.get('r', False)
     if not key:
         self.abort(httplib.BAD_REQUEST)
     item = Cls.Fetch(key)
     if item is None:
         self.abort(httplib.NOT_FOUND)
     self.SendJson(ndb_json.AsDict(item, recursive))
Exemplo n.º 4
0
def MakeProgramEvent(event):
    """Changes the given event so that it will have all program details.

  Args:
    event: A flat event.

  Returns:
    The event, modified to have all details needed for the program.
  """
    event_dict = ndb_json.AsDict(event, False)
    event_dict['activity'] = ndb_json.AsDict(event.activity.get(), False)
    event_dict['crew'] = []
    for user in event.crew:
        user_record = ndb_json.AsDict(user.get(), False)
        event_dict['crew'].append({
            'key': user_record['key'],
            'name': user_record['name']
        })
    return event_dict
Exemplo n.º 5
0
 def post(self):
     args = json.loads(self.request.body)
     if 'key' not in args:
         logging.info('No key: %s', self.request.body)
         self.abort(httplib.BAD_REQUEST)
     key = args['key']
     del args['key']
     if 'credentials_level' in args:
         current_user = CurrentUser()
         if not current_user:
             args['credentials_level'] = Credentials.USER
         elif current_user.credentials_level < args['credentials_level']:
             self.abort(httplib.UNAUTHORIZED)
             return
     item = User.Update(key, **args)
     self.SendJson(ndb_json.AsDict(item, False))
Exemplo n.º 6
0
    def get(self):
        return_url = self.request.get('source', self.request.uri)

        # Creating the response assuming the user is not logged in.
        response = {}
        response['url'] = users.create_login_url(
            User.Url('record_login', redirect=return_url))
        response['email'] = None
        response['user'] = None

        user = users.get_current_user()
        if user:
            # Updating with user data.
            response['url'] = users.create_logout_url(return_url)
            response['email'] = user.email()
            user_record = LookupUserByEmail(user.email())
            if not user_record:
                user_record = model.User(id=MakeUserId(user.email()),
                                         email=user.email(),
                                         created=datetime.now())
                user_record.put()
            response['user'] = ndb_json.AsDict(user_record)

        self.SendJson(response)
Exemplo n.º 7
0
 def post(self):
     json_item = json.loads(self.request.body)
     item = Cls.Insert(**json_item)
     self.SendJson(ndb_json.AsDict(item, False))
Exemplo n.º 8
0
 def get(self):
     recursive = self.request.get('r', False)
     self.SendJson([
         ndb_json.AsDict(item, recursive) for item in Cls.All()
     ])