Skip to content

Commit

Permalink
Moving ATTR helpers into db module
Browse files Browse the repository at this point in the history
  • Loading branch information
rconradharris committed Oct 17, 2010
1 parent 9382efb commit 98dc44c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
6 changes: 2 additions & 4 deletions glance/parallax/controllers.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,17 +132,15 @@ def _make_image_dict(image):
def _fetch_attrs(d, attrs):
return dict([(a, d[a]) for a in attrs])

file_attrs = db.BASE_MODEL_ATTRS | set(['location', 'size'])
files = [_fetch_attrs(f, file_attrs) for f in image['files']]
files = [_fetch_attrs(f, db.IMAGE_FILE_ATTRS) for f in image['files']]

# TODO(sirp): should this be a dict, or a list of dicts?
# A plain dict is more convenient, but list of dicts would provide
# access to created_at, etc
metadata = dict((m['key'], m['value']) for m in image['metadata']
if not m['deleted'])

image_attrs = db.BASE_MODEL_ATTRS | set(['name', 'image_type', 'status', 'is_public'])
image_dict = _fetch_attrs(image, image_attrs)
image_dict = _fetch_attrs(image, db.IMAGE_ATTRS)

image_dict['files'] = files
image_dict['metadata'] = metadata
Expand Down
5 changes: 5 additions & 0 deletions glance/parallax/db/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,8 @@
# attributes common to all models
BASE_MODEL_ATTRS = set(['id', 'created_at', 'updated_at', 'deleted_at',
'deleted'])

IMAGE_FILE_ATTRS = BASE_MODEL_ATTRS | set(['location', 'size'])

IMAGE_ATTRS = BASE_MODEL_ATTRS | set(['name', 'image_type', 'status',
'is_public'])

0 comments on commit 98dc44c

Please sign in to comment.