Example #1
0
 def __init__(self):
     bulkloader.Loader.__init__(
         self, 'Iniciativa',
         [('uuid', lambda s: unicode(s, 'utf-8') or None),
          ('diputado', lambda s: unicode(s, 'utf-8') or None),
          ('fecha', parseFecha), ('fecha_aprobacion', parseFecha),
          ('fecha_aprobacion', parseFecha),
          ('link_gaceta', lambda s: unicode(s, 'utf-8') or None),
          ('rol_iniciativa', lambda s: unicode(s, 'utf-8') or None),
          ('sinopsis',
           lambda s: datastore_types.Text(s, encoding='UTF-8') or None),
          ('titulo',
           lambda s: datastore_types.Text(s, encoding='UTF-8') or None),
          ('tramite', lambda s: unicode(s, 'utf-8') or None)])
Example #2
0
 def __create_value_for_mongo_value(self, mongo_value):
     if isinstance(mongo_value, Binary):
         return datastore_types.Blob(str(mongo_value))
     if isinstance(mongo_value, types.DictType):
         if mongo_value['class'] == 'rating':
             return datastore_types.Rating(int(mongo_value["rating"]))
         if mongo_value['class'] == 'category':
             return datastore_types.Category(mongo_value["category"])
         if mongo_value['class'] == 'key':
             return self.__key_for_id(mongo_value['path'])
         if mongo_value['class'] == 'list':
             return [
                 self.__create_value_for_mongo_value(v)
                 for v in mongo_value['list']
             ]
         if mongo_value['class'] == 'user':
             return users.User(email=mongo_value["email"])
         if mongo_value['class'] == 'text':
             return datastore_types.Text(mongo_value['string'])
         if mongo_value['class'] == 'im':
             return datastore_types.IM(mongo_value['protocol'],
                                       mongo_value['address'])
         if mongo_value['class'] == 'geopt':
             return datastore_types.GeoPt(mongo_value['lat'],
                                          mongo_value['lon'])
         if mongo_value['class'] == 'email':
             return datastore_types.Email(mongo_value['value'])
         if mongo_value['class'] == 'bytes':
             return datastore_types.ByteString(mongo_value['value'])
         if mongo_value['class'] == 'blobkey':
             return datastore_types.BlobKey(mongo_value['value'])
     return mongo_value
    def testDatastoreTypes(self):
        """Puts and gets different basic datastore types."""

        entity = datastore.Entity('TestKind')

        entity.update({
            'rating':
            datastore_types.Rating(1),
            'category':
            datastore_types.Category('bugs'),
            'key':
            datastore_types.Key.from_path('foo', 'bar'),
            'user':
            users.User('*****@*****.**'),
            'text':
            datastore_types.Text('some text'),
            'blob':
            datastore_types.Blob('data'),
            'bytestring':
            datastore_types.ByteString('data'),
            'im':
            datastore_types.IM('http://example.com/', 'Larry97'),
            'geopt':
            datastore_types.GeoPt(1.1234, -1.1234),
            'email':
            datastore_types.Email('*****@*****.**'),
            'blobkey':
            datastore_types.BlobKey('27f5a7'),
        })

        datastore.Put(entity)
        e = datastore.Get(entity)
        datastore.Delete(entity)
Example #4
0
def rocket_to_ae(field_type, rocket_value):
    if not rocket_value:
        ae_value = None
    elif field_type == TYPE_DATETIME or field_type == TYPE_TIMESTAMP:
        ae_value = from_iso(rocket_value)
    elif field_type == TYPE_BOOL:
        ae_value = bool(int(rocket_value))
    elif field_type == TYPE_LONG:
        ae_value = long(rocket_value)
    elif field_type == TYPE_FLOAT:
        ae_value = float(rocket_value)
    elif field_type == TYPE_INT:
        ae_value = int(rocket_value)
    elif field_type == TYPE_TEXT:
        ae_value = datastore_types.Text(rocket_value.replace('|', '|'))
    elif field_type == TYPE_REFERENCE:
        slash = rocket_value.find("/")
        if slash > 0:
            kind = rocket_value[:slash]
            key_name_or_id = rocket_value[slash + 1:]
            if key_name_or_id[0] in "0123456789":
                key_name_or_id = int(key_name_or_id)
            ae_value = datastore.Key.from_path(kind, key_name_or_id)
        else:
            logging.error("invalid reference value: %s" % rocket_value)
            ae_value = None
    elif field_type == TYPE_BLOB:
        ae_value = datastore_types.Blob(base64.b64decode(rocket_value))
    else:  #str
        ae_value = (u"%s" % rocket_value).replace('|', '|')

    return ae_value
Example #5
0
  def get_value_for_datastore(self, model_instance):
    """Gets value for datastore.

    Args:
      model_instance: instance of the model class.

    Returns:
      datastore-compatible value.
    """
    value = super(JsonProperty, self).get_value_for_datastore(model_instance)
    if not value:
      return None
    return datastore_types.Text(simplejson.dumps(
        value.to_json(), sort_keys=True))
Example #6
0
    def save(self):
        """Creates or edits this page in the datastore."""
        now = datetime.datetime.now()
        if self.entity:
            entity = self.entity
        else:
            entity = datastore.Entity('Page')
            entity['name'] = self.name
            entity['created'] = now
        entity['content'] = datastore_types.Text(self.content)
        entity['modified'] = now

        if users.get_current_user():
            entity['user'] = users.get_current_user()
        elif entity.has_key('user'):
            del entity['user']

        datastore.Put(entity)
Example #7
0
  def get_value_for_datastore(self, model_instance):
    """Gets value for datastore.

    Args:
      model_instance: instance of the model class.

    Returns:
      datastore-compatible value.
    """
    value = super(JsonProperty, self).get_value_for_datastore(model_instance)
    if not value:
      return None
    json_value = value
    if not isinstance(value, dict):
      json_value = value.to_json()
    if not json_value:
      return None
    return datastore_types.Text(json.dumps(
        json_value, sort_keys=True, cls=JsonEncoder))
def js_to_appengine_value(value, attr_config):
    if not value:
        return None
    
    if not attr_config:
        return value
    
    type = attr_config['type']
    if type == DATETIME:
        return datetime_from_iso(value)
        
    elif type == INT:
        return int(value)
    
    elif type == LONG:
        return long(value)
    
    elif type == BOOL:
        return bool(value)
        
    elif type == TEXT:
        return datastore_types.Text(value)
        
    elif type == KEY:
        kind = attr_config['kind']
        if value[0] in "0123456789":
            return datastore.Key.from_path(kind, int(value))
        else:            
            return datastore.Key.from_path(kind, value)
          
    elif type == BLOB:
        return datastore_types.Blob(base64.b64decode(value))

    elif type == LIST:
        return map(lambda value: js_to_appengine_value(value, attr_config['items']), value.split("|"))
        
    else: #str
        return value
Example #9
0
def change_property_to_text(key, entity):
    print('.')
    entity[key] = datastore_types.Text(entity[key])
 def parse(self, value):
     return datastore_types.Text(value)