Add package_count to Category objects
Partially implements blueprint enable-category-management Change-Id: I8639586d6dad1b398d54ee6f4ac5755cb38ed8b0
This commit is contained in:
parent
7a08d3b81f
commit
5542f47b61
doc/source/specification
murano
@ -441,13 +441,15 @@ List categories
|
|||||||
"id": "0420045dce7445fabae7e5e61fff9e2f",
|
"id": "0420045dce7445fabae7e5e61fff9e2f",
|
||||||
"updated": "2014-12-26T13:57:04",
|
"updated": "2014-12-26T13:57:04",
|
||||||
"name": "Web",
|
"name": "Web",
|
||||||
"created": "2014-12-26T13:57:04"
|
"created": "2014-12-26T13:57:04",
|
||||||
|
"package_count": 1
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"id": "3dd486b1e26f40ac8f35416b63f52042",
|
"id": "3dd486b1e26f40ac8f35416b63f52042",
|
||||||
"updated": "2014-12-26T13:57:04",
|
"updated": "2014-12-26T13:57:04",
|
||||||
"name": "Databases",
|
"name": "Databases",
|
||||||
"created": "2014-12-26T13:57:04"
|
"created": "2014-12-26T13:57:04",
|
||||||
|
"package_count": 0
|
||||||
}]
|
}]
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -490,7 +492,8 @@ Get category details
|
|||||||
}
|
}
|
||||||
],
|
],
|
||||||
"name": "Web",
|
"name": "Web",
|
||||||
"created": "2015-01-28T17:00:19"
|
"created": "2015-01-28T17:00:19",
|
||||||
|
"package_count": 1
|
||||||
}
|
}
|
||||||
|
|
||||||
+----------------+-----------------------------------------------------------+
|
+----------------+-----------------------------------------------------------+
|
||||||
@ -541,6 +544,7 @@ Add new category
|
|||||||
"name": "category_name",
|
"name": "category_name",
|
||||||
"created": "2013-11-30T03:23:42Z",
|
"created": "2013-11-30T03:23:42Z",
|
||||||
"updated": "2013-11-30T03:23:44Z",
|
"updated": "2013-11-30T03:23:44Z",
|
||||||
|
"package_count": 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -265,7 +265,6 @@ class Controller(object):
|
|||||||
def delete(self, req, package_id):
|
def delete(self, req, package_id):
|
||||||
target = {'package_id': package_id}
|
target = {'package_id': package_id}
|
||||||
policy.check("delete_package", req.context, target)
|
policy.check("delete_package", req.context, target)
|
||||||
|
|
||||||
db_api.package_delete(package_id, req.context)
|
db_api.package_delete(package_id, req.context)
|
||||||
|
|
||||||
def get_category(self, req, category_id):
|
def get_category(self, req, category_id):
|
||||||
|
@ -416,6 +416,9 @@ def category_add(category_name):
|
|||||||
|
|
||||||
with session.begin():
|
with session.begin():
|
||||||
category.update({'name': category_name})
|
category.update({'name': category_name})
|
||||||
|
# NOTE(kzaitsev) update package_count, so we can safely access from
|
||||||
|
# outside the session
|
||||||
|
category.package_count = 0
|
||||||
category.save(session)
|
category.save(session)
|
||||||
|
|
||||||
return category
|
return category
|
||||||
|
@ -278,6 +278,17 @@ class Category(Base, TimestampMixin):
|
|||||||
default=uuidutils.generate_uuid)
|
default=uuidutils.generate_uuid)
|
||||||
name = sa.Column(sa.String(80), nullable=False, index=True, unique=True)
|
name = sa.Column(sa.String(80), nullable=False, index=True, unique=True)
|
||||||
|
|
||||||
|
package_count = sa_orm.column_property(
|
||||||
|
sa.select([sa.func.count(package_to_category.c.package_id)]).
|
||||||
|
where(package_to_category.c.category_id == id).
|
||||||
|
correlate_except(package_to_category)
|
||||||
|
)
|
||||||
|
|
||||||
|
def to_dict(self):
|
||||||
|
d = super(Category, self).to_dict()
|
||||||
|
d['package_count'] = self.package_count
|
||||||
|
return d
|
||||||
|
|
||||||
|
|
||||||
class Tag(Base, TimestampMixin):
|
class Tag(Base, TimestampMixin):
|
||||||
"""Represents tags in the datastore."""
|
"""Represents tags in the datastore."""
|
||||||
|
@ -148,9 +148,12 @@ Content-Type: application/json
|
|||||||
fake_now = timeutils.utcnow()
|
fake_now = timeutils.utcnow()
|
||||||
timeutils.utcnow.override_time = fake_now
|
timeutils.utcnow.override_time = fake_now
|
||||||
|
|
||||||
expected = {'name': 'new_category',
|
expected = {
|
||||||
'created': timeutils.isotime(fake_now)[:-1],
|
'name': 'new_category',
|
||||||
'updated': timeutils.isotime(fake_now)[:-1]}
|
'created': timeutils.isotime(fake_now)[:-1],
|
||||||
|
'updated': timeutils.isotime(fake_now)[:-1],
|
||||||
|
'package_count': 0,
|
||||||
|
}
|
||||||
|
|
||||||
body = {'name': 'new_category'}
|
body = {'name': 'new_category'}
|
||||||
req = self._post('/catalog/categories', json.dumps(body))
|
req = self._post('/catalog/categories', json.dumps(body))
|
||||||
|
Loading…
Reference in New Issue
Block a user