class Revision(APIResource): """Encapsulates a single revision returned from a History lookup""" def __init__(self, record, raw): super(Revision, self).__init__(record._swimlane, raw) self.record = record self.modified_date = pendulum.parse(self._raw['modifiedDate']) self.revision_number = int(self._raw['revisionNumber']) self.status = self._raw['status'] # UserGroupSelection, can't set as User without additional lookup self.user = UserGroup(self._swimlane, self._raw['userId']) # Avoid circular imports from swimlane.core.resources.record import Record self.version = Record(self.record.app, self._raw['version']) def __str__(self): return '{} ({})'.format(self.version, self.revision_number) def for_json(self): """Return revision metadata""" return { 'modifiedDate': self._raw['modifiedDate'], 'revisionNumber': self.revision_number, 'user': self.user.for_json() }
class Comment(APIResource): """Abstraction of a single comment from a comment field Attributes: user (UserGroup): UserGroup instance of user who created the comment created_date (pendulum.DateTime): Pendulum datetime of when comment was created message (str): Comment message body """ def __init__(self, swimlane, raw): super(Comment, self).__init__(swimlane, raw) self.user = UserGroup(swimlane, self._raw['createdByUser']) self.created_date = pendulum.parse(self._raw['createdDate']) self.message = self._raw['message'] self.is_rich_text = self._raw.get('isRichText', False) def __str__(self): return self.message def for_json(self): """Called by CommentField.for_json(), returns relevant Comment attributes in JSON-compatible format""" return { 'message': self.message, 'createdDate': self._raw['createdDate'], 'createdByUser': self.user.for_json() }
class RevisionBase(APIResource): """ The base class representing a single revision returned from a History lookup. Attributes: Attributes: modified_date: The date this revision was created. revision_number: The revision number of this revision. status: Indicates whether this revision is the current revision or a historical revision. user: The user that saved this revision. """ def __init__(self, swimlane, raw): super(RevisionBase, self).__init__(swimlane, raw) self.modified_date = pendulum.parse(self._raw['modifiedDate']) self.revision_number = self._raw['revisionNumber'] self.status = self._raw['status'] # UserGroupSelection, can't set as User without additional lookup self.user = UserGroup(self._swimlane, self._raw['userId']) self._raw_version = self._raw['version'] self._version = None def __str__(self): return '{} ({})'.format(self.version, self.revision_number) @property def version(self): raise NotImplementedError def for_json(self): """Return revision metadata""" return { 'modifiedDate': self._raw['modifiedDate'], 'revisionNumber': self.revision_number, 'user': self.user.for_json() }