Example #1
0
 def __new__(self, id, **params):
     domain_name = domain_for_model(self.model_class)
     domain = Domain(name=domain_name, connection=manager.sdb)
     item = Item(domain, id)
     params['_id'] = id
     item.update(params)
     return item
Example #2
0
 def sql_create_model(self, model, style, known_models=set()):
     """ We don't actually return any SQL here, but we do go right ahead
     and create a domain for the model.
     """
     domain_name = domain_for_model(model)
     self.sdb.create_domain(domain_name)
     return [], {}
Example #3
0
def save_entity(connection, model, data):
    domain_name = domain_for_model(model)
    manager = connection.create_manager(domain_name)
    attrs = {
        '__type__': domain_name,
    }
    attrs.update(data)
    if not attrs.has_key('_id'):
        # New item. Generate an ID.
        attrs['_id'] = uuid.uuid4().int
    domain = Domain(name=domain_name, connection=manager.sdb)
    domain.put_attributes(attrs['_id'], attrs, replace=True)
    return attrs['_id']
Example #4
0
def save_entity(connection, model, data):
    domain_name = domain_for_model(model)
    manager = connection.create_manager(domain_name)
    attrs = {
        '__type__': domain_name,
    }
    attrs.update(data)
    if not attrs.has_key('_id'):
        # New item. Generate an ID.
        attrs['_id'] = uuid.uuid4().int
    domain = Domain(name=domain_name, connection=manager.sdb)
    domain.put_attributes(attrs['_id'], attrs, replace=True)
    return attrs['_id']
Example #5
0
def model_adapter(django_model, manager):
    """ Return a generated subclass of django_model that conforms to the
    API that boto expects of its own models.
    """
    class ModelAdapter(object):
        """ Adapter to provide the API that boto expects its models to have for
        normal Django models
        """
        def __new__(self, id, **params):
            domain_name = domain_for_model(self.model_class)
            domain = Domain(name=domain_name, connection=manager.sdb)
            item = Item(domain, id)
            params['_id'] = id
            item.update(params)
            return item
            #return self.model_class(**attrs)

        # Used by SDBManager._get_all_descendents. Might need to implement
        # this for model inheritance...
        __sub_classes__ = ()

        # Used by simpledb.base.SDBManager to track the real Django model
        # class this represents, and for us to know what kind of model to
        # actually instantiate.
        model_class = None

        @classmethod
        def find_property(cls, prop_name):
            """ Find the named property. Returns None if the property can't
            be found
            """
            # Special-case - _id always maps to the primary key
            if prop_name == '_id':
                return property_from_field(django_model._meta.pk)

            # Otherwise, look through the Django model fields for a field
            # of the correct name. XXX should this be name or column?
            result = None
            for field in django_model._meta.fields:
                if field.name == prop_name:
                    result = property_from_field(field)
                    break
            return result

        @classmethod
        def properties(cls, hidden=True):
            return [property_from_field(f) for f in django_model._meta.fields]

    ModelAdapter.model_class = django_model
    ModelAdapter.__name__ = domain_for_model(django_model)
    return ModelAdapter
Example #6
0
 def delete(self):
     items = dict([(e['_id'], None) for e in self.fetch_infinite(0)])
     domain = Domain(name=domain_for_model(self.model),
                     connection=self.manager.sdb)
     return domain.batch_delete_attributes(items)
Example #7
0
 def __init__(self, compiler, fields):
     super(BackendQuery, self).__init__(compiler, fields)
     # TODO: add your initialization code here
     domain = domain_for_model(self.query.model)
     self.db_query = SimpleDBQuery(
         self.connection.create_manager(domain), self.query.model)
Example #8
0
 def __init__(self, compiler, fields):
     super(BackendQuery, self).__init__(compiler, fields)
     # TODO: add your initialization code here
     domain = domain_for_model(self.query.model)
     self.db_query = SimpleDBQuery(self.connection.create_manager(domain),
                                   self.query.model)