Created
May 21, 2015 17:14
-
-
Save dolph/95a7a7387291de99d464 to your computer and use it in GitHub Desktop.
Example of a keystone object model
This file contains hidden or 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
class BaseModel(object): | |
def __init__(self, id=None): | |
self.id = id or uuid.uuid4().hex | |
@property | |
def name(self): | |
return self._name | |
class ProjectModel(BaseModel): | |
def __init__(self, id=None, name): | |
super(ProjectModel, self).__init__(id) | |
self._name = name | |
@property | |
def name(self): | |
return self._name | |
@name.setter | |
def name(self, value): | |
self._name = value | |
class ValidatedProjectModel(ProjectModel): | |
@name.setter | |
def name(self, value): | |
if not value: | |
raise EmptyNameValueError(_('Name is required.')) | |
if not isinstance(value, six.string): | |
raise NameTypeMismatchValueError(_('Name must be a string.')) | |
if len(value) > 64: | |
raise NameTooLongValueError(_('Name is too long (must be less than 64 chars).')) | |
if len(value) < 1: | |
raise NameTooShortValueError(_('Name is too short (must be greater than 1 char).')) | |
super(ValidatedProjectModel, self).name = value |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment