| 1 |
# Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 2 |
# not use this file except in compliance with the License. You may obtain |
| 3 |
# a copy of the License at |
| 4 |
# |
| 5 |
# http://www.apache.org/licenses/LICENSE-2.0 |
| 6 |
# |
| 7 |
# Unless required by applicable law or agreed to in writing, software |
| 8 |
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 9 |
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 10 |
# License for the specific language governing permissions and limitations |
| 11 |
# under the License. |
| 12 |
|
| 13 |
from oslo_versionedobjects import fields as obj_fields |
| 14 |
|
| 15 |
|
| 16 |
STANDARD_ATTRIBUTES = { |
| 17 |
'revision_number': obj_fields.IntegerField(), |
| 18 |
'description': obj_fields.StringField(nullable=True), |
| 19 |
'created_at': obj_fields.DateTimeField(nullable=True, tzinfo_aware=False), |
| 20 |
'updated_at': obj_fields.DateTimeField(nullable=True, tzinfo_aware=False), |
| 21 |
} |
| 22 |
|
| 23 |
|
| 24 |
def add_standard_attributes(cls): |
| 25 |
"""Add standard attributes to the said class. |
| 26 |
|
| 27 |
:param cls: The class to add standard attributes to. |
| 28 |
:returns: None. |
| 29 |
""" |
| 30 |
# Don't use parent's fields in case child class doesn't create |
| 31 |
# its own instance of list |
| 32 |
cls.fields = cls.fields.copy() |
| 33 |
cls.fields.update(STANDARD_ATTRIBUTES) |
| 34 |
# those fields are updated by sqlalchemy itself |
| 35 |
cls.fields_no_update += ('created_at', 'updated_at') |
| 36 |
# revision numbers are managed by service plugin and are bumped |
| 37 |
# automatically; consumers should not bump them explicitly |
| 38 |
cls.fields_no_update.append('revision_number') |
| 39 |
|
| 40 |
|
| 41 |
def add_tag_filter_names(cls): |
| 42 |
"""Add tag filter names to the said class. |
| 43 |
|
| 44 |
:param cls: The class to add tag filter names to. |
| 45 |
:returns: None. |
| 46 |
""" |
| 47 |
cls.add_extra_filter_name("tags") |
| 48 |
cls.add_extra_filter_name("not-tags") |
| 49 |
cls.add_extra_filter_name("tags-any") |
| 50 |
cls.add_extra_filter_name("not-tags-any") |