def __init__(self, backend, node, user, content=None, ctime=None, mtime=None): """ Construct a DjangoComment. :param node: a Node instance :param user: a User instance :param content: the comment content :param ctime: The creation time as datetime object :param mtime: The modification time as datetime object :return: a Comment object associated to the given node and user """ super().__init__(backend) lang.type_check(user, users.DjangoUser) # pylint: disable=no-member arguments = { 'dbnode': node.dbmodel, 'user': user.dbmodel, 'content': content, } if ctime: lang.type_check(ctime, datetime, f'the given ctime is of type {type(ctime)}') arguments['ctime'] = ctime if mtime: lang.type_check(mtime, datetime, f'the given mtime is of type {type(mtime)}') arguments['mtime'] = mtime self._dbmodel = ModelWrapper(models.DbComment(**arguments), auto_flush=self._auto_flush)
def _(dbmodel, backend): """ Convert a dbcomment to the backend entity """ from . import comments djcomment = djmodels.DbComment(id=dbmodel.id, uuid=dbmodel.uuid, dbnode_id=dbmodel.dbnode_id, ctime=dbmodel.ctime, mtime=dbmodel.mtime, user_id=dbmodel.user_id, content=dbmodel.content) return comments.DjangoComment.from_dbmodel(djcomment, backend)