-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Simple domain creation. syncdb (though not post-syncdb handlers) now …
…works.
- Loading branch information
Dan Fairs
committed
May 1, 2011
1 parent
0854fe6
commit 36a49e5
Showing
3 changed files
with
140 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
from boto.sdb.db.query import Query as BotoQuery | ||
from boto.sdb.db.property import Property | ||
|
||
def model_adapter(django_model): | ||
properties = {} | ||
for field in django_model._meta.fields: | ||
default = field.default | ||
if callable(default): | ||
default = default() | ||
choices = [c[0] for c in getattr(field, 'choices', ())] | ||
properties[field.name] = Property( | ||
verbose_name=field.verbose_name, | ||
name=field.name, | ||
default=default, | ||
required=not field.null, | ||
choices=choices, | ||
unique=field.unique | ||
) | ||
|
||
class ModelAdapter(django_model): | ||
""" Adapter to provide the API that boto expects its models to have for | ||
normal Django models | ||
""" | ||
|
||
# Used by SDBManager._get_all_descendents. Might need to implement | ||
# this for model inheritance... | ||
__sub_classes__ = () | ||
|
||
# Override __name__ as boto uses this to figure out the | ||
# __type__ attributes. | ||
__name__ = '%s.%s' % (django_model._meta.app_label, django_model.__name__) | ||
|
||
@classmethod | ||
def find_property(cls, prop_name): | ||
""" Find the named property. Returns None if the property can't | ||
be found | ||
""" | ||
return properties.get(prop_name) | ||
|
||
return ModelAdapter | ||
|
||
class SimpleDBQuery(BotoQuery): | ||
|
||
def __init__(self, manager, model, limit=None, next_token=None): | ||
self.manager = manager | ||
self.model_class = model_adapter(model) | ||
self.limit = limit | ||
self.offset = 0 | ||
self.filters = [] | ||
self.select = None | ||
self.sort_by = None | ||
self.rs = None | ||
self.next_token = next_token | ||
|
||
def fetch_infinite(self, offset): | ||
return self.manager.query(self) | ||
|
||
def fetch_range(self, count, low_mark): | ||
raise NotImplementedError |