def approve(id, actor: user_id): comment = get(id) delete(id) commentactionloglib.create(comment=id, action=comment_actions.approved.value, actor=actor) ret = commentlib.create(**comment) signals.comment_approved.send('approved', comment=comment) return ret
def revert(id, actor: user_id): rejected_comment = get(id) delete(id) commentactionloglib.create(comment=id, action=comment_actions.reverted.value, actor=actor) del (rejected_comment['note']) del (rejected_comment['reason']) del (rejected_comment['commenter']) return pendingcommentlib.create(**rejected_comment)
def update(id, actor: user_id, **mod_data): updatables = ('editors_pick', 'content') update_dict = dict( (k, v) for (k, v) in list(mod_data.items()) if k in updatables) PendingComment.update(**update_dict).where( PendingComment.id == id).execute() if update_dict.get('editors_pick'): commentactionloglib.create(comment=id, action=comment_actions.picked.value, actor=actor)
def reject(id, actor: user_id, note='', reason=None): pending_comment = get(id) delete(id) commentactionloglib.create(comment=id, action=comment_actions.rejected.value, actor=actor) return rejectedcommentlib.create(**pending_comment, note=note, reason=reason or rejection_reasons.other.value)
def update(id, actor: user_id, **mod_data): updatables = ('editors_pick', ) update_dict = dict( (k, v) for (k, v) in list(mod_data.items()) if k in updatables) Comment.update(**update_dict).where(Comment.id == id).execute() if update_dict.get('editors_pick'): commentactionloglib.create(comment=id, action=comment_actions.picked.value, actor=actor) comment = get(id) signals.comment_featured.send('featured', comment=comment)
def reject(id, actor: user_id, note='', reason=None): for child_comment in get_by_parent(id): reject(child_comment['id'], actor, reason=rejection_reasons.parent_rejected.value) comment = get(id) delete(id) commentactionloglib.create(comment=id, action=comment_actions.rejected.value, actor=actor) return rejectedcommentlib.create(**comment, note=note, reason=reason or rejection_reasons.other.value)