示例#1
0
 def update_tag(self, context, resource, resource_id, tag):
     res = self._get_resource(context, resource, resource_id)
     if any(tag == tag_db.tag for tag_db in res.standard_attr.tags):
         return
     try:
         with context.session.begin(subtransactions=True):
             tag_db = tag_model.Tag(standard_attr_id=res.standard_attr_id,
                                    tag=tag)
             context.session.add(tag_db)
     except db_exc.DBDuplicateEntry:
         pass
示例#2
0
 def update_tag(self, context, resource, resource_id, tag):
     res = self._get_resource(context, resource, resource_id)
     if any(tag == tag_db.tag for tag_db in res.standard_attr.tags):
         return
     try:
         with db_api.context_manager.writer.using(context):
             tag_db = tag_model.Tag(standard_attr_id=res.standard_attr_id,
                                    tag=tag)
             context.session.add(tag_db)
     except db_exc.DBDuplicateEntry:
         pass
示例#3
0
 def update_tags(self, context, resource, resource_id, body):
     res = self._get_resource(context, resource, resource_id)
     new_tags = set(body['tags'])
     old_tags = {tag_db.tag for tag_db in res.standard_attr.tags}
     tags_added = new_tags - old_tags
     tags_removed = old_tags - new_tags
     with context.session.begin(subtransactions=True):
         for tag_db in res.standard_attr.tags:
             if tag_db.tag in tags_removed:
                 context.session.delete(tag_db)
         for tag in tags_added:
             tag_db = tag_model.Tag(standard_attr_id=res.standard_attr_id,
                                    tag=tag)
             context.session.add(tag_db)
     return body
示例#4
0
 def update_tags(self, context, resource, resource_id, body):
     with db_api.context_manager.writer.using(context):
         # We get and do all operations with objects in one session
         res = self._get_resource(context, resource, resource_id)
         new_tags = set(body['tags'])
         old_tags = {tag_db.tag for tag_db in res.standard_attr.tags}
         tags_added = new_tags - old_tags
         tags_removed = old_tags - new_tags
         for tag_db in res.standard_attr.tags:
             if tag_db.tag in tags_removed:
                 context.session.delete(tag_db)
         for tag in tags_added:
             tag_db = tag_model.Tag(standard_attr_id=res.standard_attr_id,
                                    tag=tag)
             context.session.add(tag_db)
     return body