Exemplo n.º 1
0
 def CreateEntity(self, values):
     #logging.info('Creating entity: %s'  % (self.__kind))
     
     props = []
     for ep in self.__profile_obj._fields:
         if not ep:
             logging.error("Error: bad property mapping in import profile")
         import_statement = self.GetImportStatementForType(ep.type_info)
         #logging.info(import_statement)
         converter = utils.loadImportConverter(import_statement)            
         props.append( (ep.name, converter) )   
     
     key_name = utils.new_key()
     if props[0][0] == 'name':
         key_name = utils.format_key(values[0])
     
     entity = datastore.Entity(self.__kind, name=key_name)
     for (name, converter), val in zip(props, values):
       #logging.info('%s = %s' % (name, val))
       if converter is bool and val.lower() in ('0', 'false', 'no'):
           val = False
       if name != 'name':
           entity[name] = converter(val)
       
     entity['org']           = self.__req.org.name
     entity['owner']         = self.__req.user.name
     entity['is_deleted']    = False
     entity['created']       = datetime.datetime.now()
     entity['updated']       = datetime.datetime.now()
     entity['bookmark']      = utils.bookmark_for_kind(self.__kind, self.__req.user.name, entity['updated'])
     #logging.info('Data bookmark=' + entity['bookmark'])
     return [entity]
Exemplo n.º 2
0
def reverse_transform(req, data, datatype):
    '''
  Transform the PyAmf data to GAE data
  '''
    gae_obj = None

    gae_klazz = utils.loadModuleType(req.metadata.name, datatype)

    if ('id' in data):
        key = data['id']
        key_obj = db.Key.from_path(datatype, key)
        gae_obj = db.Model.get(key_obj)
    else:
        key = utils.new_key()

    if not gae_obj:
        gae_obj = gae_klazz(key_name=key)
    '''
  em = metadataservice.find_entity_metadata(req, datatype)  
  for k in em.entity_property_metadatas(req):
      if data.has_key(k.name) and data[k.name]:
  '''
    for k in data.keys():
        val = data[k]
        setattr(gae_obj, k, val)

    return gae_obj
Exemplo n.º 3
0
    def CreateEntity(self, values):
        #logging.info('Creating entity: %s'  % (self.__kind))

        props = []
        for ep in self.__profile_obj._fields:
            if not ep:
                logging.error("Error: bad property mapping in import profile")
            import_statement = self.GetImportStatementForType(ep.type_info)
            #logging.info(import_statement)
            converter = utils.loadImportConverter(import_statement)
            props.append((ep.name, converter))

        key_name = utils.new_key()
        if props[0][0] == 'name':
            key_name = utils.format_key(values[0])

        entity = datastore.Entity(self.__kind, name=key_name)
        for (name, converter), val in zip(props, values):
            #logging.info('%s = %s' % (name, val))
            if converter is bool and val.lower() in ('0', 'false', 'no'):
                val = False
            if name != 'name':
                entity[name] = converter(val)

        entity['org'] = self.__req.org.name
        entity['owner'] = self.__req.user.name
        entity['is_deleted'] = False
        entity['created'] = datetime.datetime.now()
        entity['updated'] = datetime.datetime.now()
        entity['bookmark'] = utils.bookmark_for_kind(self.__kind,
                                                     self.__req.user.name,
                                                     entity['updated'])
        #logging.info('Data bookmark=' + entity['bookmark'])
        return [entity]
def reverse_transform(req, data, datatype):
  '''
  Transform the PyAmf data to GAE data
  '''  
  gae_obj       = None    

  gae_klazz     = utils.loadModuleType(req.metadata.name, datatype)
  
  if ('id' in data):
      key       = data['id']
      key_obj   = db.Key.from_path(datatype, key)
      gae_obj   = db.Model.get(key_obj)
  else:
      key       = utils.new_key()
  
  if not gae_obj:
      gae_obj   = gae_klazz(key_name = key)

  '''
  em = metadataservice.find_entity_metadata(req, datatype)  
  for k in em.entity_property_metadatas(req):
      if data.has_key(k.name) and data[k.name]:
  ''' 
  for k in data.keys():
      val = data[k]
      setattr(gae_obj, k, val)
          
  return gae_obj 
    def post(self):
        token = None
        ret = {}
        ret['status'] = constants.STATUS_INVALID_PARAM

        try:

            app = get_request_value(self.request, 'app')
            org = get_request_value(self.request, 'org')
            friend = get_request_value(self.request, 'friend')

            u = users.get_current_user()
            if u:
                user = securityservice.SecurityService.userid_to_user(
                    u.email())
                if user:
                    token = securityservice.SecurityService.generate_user_token(
                        user)
                else:
                    new_user = {}
                    new_user['name'] = u.email()
                    new_user['email'] = u.email()
                    new_user['password'] = utils.new_key()

                    user = securityservice.SecurityService.register_user(
                        new_user, app, org)
                    if user:
                        token = securityservice.SecurityService.generate_user_token(
                            user)

                fd = {}
                if friend and friend == '1':
                    gae_klazz = utils.loadModuleType('Friends', 'Friends_User')
                    query = gae_klazz.all()
                    query.filter('owner =', user.name)
                    query.filter('nick =', user.name)
                    friendUser = query.get()
                    if friendUser:
                        fd["nick"] = friendUser.nick
                        fd["age"] = friendUser.age
                        fd["gender"] = friendUser.gender
                        fd["description"] = friendUser.description
                        fd["photo"] = friendUser.photo
                        fd["location"] = friendUser.location
                        fd["approved"] = 1 if friendUser.approved == '1' else 0

                ret['name'] = user.name
                ret['email'] = user.email
                ret['token'] = token
                ret['friend'] = fd
                ret['status'] = constants.STATUS_OK
            #if u
        except Exception, e:
            ret['status'] = constants.STATUS_FATAL_ERROR
            ret['error_message'] = str(e)
            logging.error(traceback.format_exc())
 def get(self):
     token = get_request_value(self.request, 'token')
     key = utils.new_key()
     upload_url = '/assets/upload/%s/%s' % (key, token)
     #upload_url = '/assets/upload'
     self.response.out.write('<html><body>')
     self.response.out.write('<form action="%s" method="POST" enctype="multipart/form-data">' % upload_url)
     #self.response.out.write('<input type="hidden" name="id" value="%s"> <input type="hidden" name="token" value="%s">' % (utils.new_key() , token))
     self.response.out.write("""Upload File: <input type="file" name="file"><br><input type="submit" 
         name="submit" value="Submit"> </form></body></html>""")
    def post(self):
        token = get_request_value(self.request, 'token')
        data = get_request_value(self.request, 'upload')
        key = get_request_value(self.request, 'id')
        user = securityservice.SecurityService.authenticate_user_token(token)

        if key is None:
            key = utils.new_key()
            logging.info('No id in request: %s', key)

        #logging.info(self.request)
        if user and data:  # and len(data)<=2097152:
            file = datamodel.UploadedFile(key_name=key)
            file.ip = self.request.remote_addr

            file.fileName = self.request.POST.get('upload').filename
            if not file.fileName:
                file.fileName = str(uuid.uuid1())
            logging.info(file.fileName)

            file.fileType = None  #self.request.headers.get('Content-Type')
            if not file.fileType:
                file.fileType = 'image/png'
            logging.info(file.fileType)

            if 'image' in file.fileType:
                img = images.Image(data)
                file.width = img.width
                file.height = img.height

            if len(data) <= 524288 and 'image' in file.fileType:
                file.thumbnailBlob = db.Blob(images.resize(data, 96, 96))

            file.fileBlob = db.Blob(data)
            file.fileSize = len(data)
            file.owner = user.name
            file.is_deleted = False
            file.updated = datetime.datetime.now()
            file.bookmark = utils.bookmark_for_kind(datatype, user.name,
                                                    file.updated)
            file.put()

            file.url = '/assets?id=%s' % (file.key())
            if file.thumbnailBlob:
                file.thumbnail = '/assets?id=%s&size=thumbnail' % (file.key())
            file.put()

            json_ret = '{"status": "0", "id": "%s", "url": "%s"}' % (key,
                                                                     file.url)
            self.response.out.write(json_ret)

        else:
            logging.error(
                'File upload failed, upload key is missing or file size > 2MB')
            self.error(401)
    def post(self):     
        token = get_request_value(self.request, 'token')
        data = get_request_value(self.request, 'upload')
        key = get_request_value(self.request, 'id')
        user   = securityservice.SecurityService.authenticate_user_token(token)
        
        if key is None:
            key = utils.new_key()
            logging.info('No id in request: %s', key)
                   
        #logging.info(self.request)
        if user and data: # and len(data)<=2097152:
            file = datamodel.UploadedFile(key_name = key)
            file.ip = self.request.remote_addr
                        
            file.fileName = self.request.POST.get('upload').filename;
            if not file.fileName:
                file.fileName = str(uuid.uuid1())     
            logging.info(file.fileName)
            
            file.fileType = None #self.request.headers.get('Content-Type')
            if not file.fileType:
                file.fileType = 'image/png'
            logging.info(file.fileType)
            
            if 'image' in file.fileType:
                img = images.Image(data)
                file.width = img.width
                file.height = img.height
                
            if len(data)<=524288 and 'image' in file.fileType:
              file.thumbnailBlob = db.Blob(images.resize(data, 96, 96))

            file.fileBlob = db.Blob(data)  
            file.fileSize = len(data)
            file.owner = user.name
            file.is_deleted = False
            file.updated = datetime.datetime.now()
            file.bookmark = utils.bookmark_for_kind(datatype, user.name, file.updated)
            file.put()
            
            file.url = '/assets?id=%s' % (file.key()) 
            if file.thumbnailBlob:
                file.thumbnail = '/assets?id=%s&size=thumbnail' % (file.key()) 
            file.put()
            
            json_ret = '{"status": "0", "id": "%s", "url": "%s"}' % (key, file.url)
            self.response.out.write(json_ret)
            
        else:
            logging.error('File upload failed, upload key is missing or file size > 2MB')
            self.error(401)
    def post(self):
        token=None       
        ret                 = {}
        ret['status']       = constants.STATUS_INVALID_PARAM
        
        try:
            
            app = get_request_value(self.request, 'app')
            org = get_request_value(self.request, 'org')
            friend = get_request_value(self.request, 'friend')
        
            u = users.get_current_user()
            if u:
                user = securityservice.SecurityService.userid_to_user(u.email())
                if user:
                    token = securityservice.SecurityService.generate_user_token(user)
                else:
                    new_user                 = {}
                    new_user['name']         = u.email()
                    new_user['email']        = u.email()
                    new_user['password']     = utils.new_key()
                
                    user = securityservice.SecurityService.register_user(new_user, app, org)
                    if user:
                        token = securityservice.SecurityService.generate_user_token(user)
                    
                fd = {}
                if friend and friend == '1':
                    gae_klazz = utils.loadModuleType('Friends', 'Friends_User')
                    query = gae_klazz.all()
                    query.filter('owner =', user.name)
                    query.filter('nick =', user.name)
                    friendUser = query.get()   
                    if friendUser:
                        fd["nick"] = friendUser.nick
                        fd["age"] = friendUser.age
                        fd["gender"] = friendUser.gender
                        fd["description"] = friendUser.description
                        fd["photo"] = friendUser.photo
                        fd["location"] = friendUser.location
                        fd["approved"] =  1 if friendUser.approved == '1' else 0  

                ret['name']         = user.name
                ret['email']        = user.email
                ret['token']        = token
                ret['friend']       = fd
                ret['status']       = constants.STATUS_OK
            #if u
        except Exception, e:
            ret['status'] = constants.STATUS_FATAL_ERROR
            ret['error_message'] = str(e)
            logging.error(traceback.format_exc())
Exemplo n.º 10
0
 def get(self):
     token = get_request_value(self.request, 'token')
     key = utils.new_key()
     upload_url = '/assets/upload/%s/%s' % (key, token)
     #upload_url = '/assets/upload'
     self.response.out.write('<html><body>')
     self.response.out.write(
         '<form action="%s" method="POST" enctype="multipart/form-data">' %
         upload_url)
     #self.response.out.write('<input type="hidden" name="id" value="%s"> <input type="hidden" name="token" value="%s">' % (utils.new_key() , token))
     self.response.out.write(
         """Upload File: <input type="file" name="file"><br><input type="submit" 
         name="submit" value="Submit"> </form></body></html>""")
 def get(self, app):
     token = get_request_value(self.request, 'token')
     
     if token: 
         key = utils.new_key()
         upload_url = '/assets/upload/%s/%s' % (key, token)
         file_url = '/assets/upload?id=%s' % (key) 
         thumbnail_url = '/assets/upload?id=%s&size=thumbnail' % (key) 
         json_ret = '{"status": "0", "id": "%s", "uploadUrl": "%s", "fileUrl": "%s", "thumbnailUrl" : "%s"}' % (key, upload_url, file_url, thumbnail_url)
         self.response.out.write(json_ret)
         
     else:
         logging.error('File upload failed, invalid token')
         self.error(401)
Exemplo n.º 12
0
    def get(self, app):
        token = get_request_value(self.request, 'token')

        if token:
            key = utils.new_key()
            upload_url = '/assets/upload/%s/%s' % (key, token)
            file_url = '/assets/upload?id=%s' % (key)
            thumbnail_url = '/assets/upload?id=%s&size=thumbnail' % (key)
            json_ret = '{"status": "0", "id": "%s", "uploadUrl": "%s", "fileUrl": "%s", "thumbnailUrl" : "%s"}' % (
                key, upload_url, file_url, thumbnail_url)
            self.response.out.write(json_ret)

        else:
            logging.error('File upload failed, invalid token')
            self.error(401)
Exemplo n.º 13
0
    def post(self):
        message = xmpp.Message(self.request.POST)

        to_address = message.to.split('@')[0]
        from_email_address = message.sender.split('/')[0]
        logging.info('xmpp searching for: ' + to_address + ' from ' +
                     from_email_address)

        chat_message_sent = False
        gae_klazz_user = utils.loadModuleType("Friends", "Friends_User")
        uq = gae_klazz_user.all()
        uq.filter('nick =', to_address)
        friend = uq.get()

        uq = gae_klazz_user.all()
        uq.filter('emailAddress =', from_email_address)
        sender = uq.get()

        if friend and sender:
            status_code = xmpp.send_message(friend.emailAddress, message.body)
            chat_message_sent = (status_code != xmpp.NO_ERROR)
            logging.info('XMPP send to:' + friend.emailAddress + ' = ' +
                         str(status_code))

            if not chat_message_sent:
                logging.info('Failed to send message')
                gae_klazz_queue = utils.loadModuleType("Friends",
                                                       "Friends_Queue")
                q = gae_klazz_queue(key_name=utils.new_key())
                q.owner = sender.name
                q.targetUser = to_address
                q.comments = message.body
                q.org = 'ParabayOrg'
                q.isPrivate = False
                q.itemType = 1
                q.updated = datetime.datetime.now()
                q.bookmark = utils.bookmark_for_kind('Friends_Queue',
                                                     sender.name, q.updated)
                q.put()
                message.reply(
                    "The user is currently offline. Your message will be delivered when the user is online."
                )
            else:
                logging.info('Sent message')
        else:
            logging.info('invalid friend:' + to_address + ', ' +
                         from_email_address)
Exemplo n.º 14
0
def reverse_transform_location(req, data):
    '''
  Transform the PyAmf data to GAE data
  '''
    gae_obj = None

    if ('id' in data):
        key = data['id']
        key_obj = db.Key.from_path('datamodel.UserLocation', key)
        gae_obj = db.Model.get(key_obj)
    else:
        key = utils.new_key()

    if not gae_obj:
        gae_obj = datamodel.UserLocation(key_name=key)

    for k in data.keys():
        val = data[k]
        setattr(gae_obj, k, val)

    return gae_obj
def reverse_transform_location(req, data):
  '''
  Transform the PyAmf data to GAE data
  '''  
  gae_obj       = None    

  if ('id' in data):
      key       = data['id']
      key_obj   = db.Key.from_path(datatype, key)
      gae_obj   = db.Model.get(key_obj)
  else:
      key       = utils.new_key()
  
  if not gae_obj:
      gae_obj   = datamodel.UserLocation(key_name = key)

  for k in data.keys():
      val = data[k]
      setattr(gae_obj, k, val)
          
  return gae_obj 
 def post(self):
   message = xmpp.Message(self.request.POST)
   
   to_address = message.to.split('@')[0] 
   from_email_address = message.sender.split('/')[0] 
   logging.info('xmpp searching for: ' + to_address + ' from ' + from_email_address )
   
   chat_message_sent = False    
   gae_klazz_user = utils.loadModuleType("Friends", "Friends_User")
   uq = gae_klazz_user.all()
   uq.filter('nick =', to_address)
   friend = uq.get()
   
   uq = gae_klazz_user.all()
   uq.filter('emailAddress =', from_email_address)
   sender = uq.get()
   
   if friend and sender:
       status_code = xmpp.send_message(friend.emailAddress, message.body)
       chat_message_sent = (status_code != xmpp.NO_ERROR)
       logging.info('XMPP send to:' + friend.emailAddress + ' = ' + str(status_code))
   
       if not chat_message_sent:    
           logging.info('Failed to send message')
           gae_klazz_queue = utils.loadModuleType("Friends", "Friends_Queue")
           q = gae_klazz_queue(key_name=utils.new_key())
           q.owner = sender.name
           q.targetUser = to_address
           q.comments = message.body
           q.org = 'ParabayOrg'
           q.isPrivate = False 
           q.itemType = 1
           q.updated  = datetime.datetime.now()
           q.bookmark = utils.bookmark_for_kind('Friends_Queue', sender.name, q.updated)
           q.put()
           message.reply("The user is currently offline. Your message will be delivered when the user is online.")
       else:
           logging.info('Sent message')
   else:
       logging.info('invalid friend:' + to_address + ', ' + from_email_address)
def reverse_transform_metadata(req, data, datatype):
  '''
  Transform the PyAmf data to GAE data
  '''  
  gae_obj       = None    

  if ('name' in data):
      key       = data['name']
      key_obj   = db.Key.from_path(datatype.__name__, key)
      gae_obj   = db.Model.get(key_obj)
  else:
      key       = utils.new_key()
  
  if not gae_obj:
      gae_obj   = datatype(key_name = key)

  for k in data.keys():
      val = data[k]
      #check value type if the next line fails
      #logging.info(k)
      #logging.info(val)
      setattr(gae_obj, k, val)
          
  return gae_obj 
Exemplo n.º 18
0
def reverse_transform_metadata(req, data, datatype):
    '''
  Transform the PyAmf data to GAE data
  '''
    gae_obj = None

    if ('name' in data):
        key = data['name']
        key_obj = db.Key.from_path(datatype.__name__, key)
        gae_obj = db.Model.get(key_obj)
    else:
        key = utils.new_key()

    if not gae_obj:
        gae_obj = datatype(key_name=key)

    for k in data.keys():
        val = data[k]
        #check value type if the next line fails
        #logging.info(k)
        #logging.info(val)
        setattr(gae_obj, k, val)

    return gae_obj