def approve_comment(self): _ = self.macro.request.getText # Source origin = os.path.join(self.approval_dir, get_input(self.macro, "file")) comment = read_comment(origin) # Destination page = Page(self.macro.request, comment["page"]) if not page.exists(): self.msg.append(_("The page this comment was written for don't exist any more")) return dest_dir = page.getPagePath("comments", check_create=1) destination = os.path.join(dest_dir, get_input(self.macro, "file")) # Rename the file: os.rename(origin, destination) self.msg.append(_("Comment approved")) # Notify page subscribers: notify_subscribers(self.macro, comment)
def save_comment( self ): _ = self.macro.request.getText if get_input(self.macro, 'do' ) != u'comment_add': # This is not a comment post do nothing return if get_cfg(self.macro, 'comment_recaptcha', False ) and not self.passpartout: import captcha self.captcha = captcha.submit ( get_input(self.macro, 'recaptcha_challenge_field'), get_input(self.macro, 'recaptcha_response_field'), get_cfg(self.macro, 'comment_recaptcha_private_key'), self.macro.request.remote_addr ) self.get_comment() self.errors = self.errors_check() if not self.errors: # Save the comment # Find out where to save the comment: if self.moderate: # This commet will be added to the moderation queue page = Page(self.macro.request, get_cfg(self.macro, 'comment_approval_page', 'CommentsApproval')) comment_dir = page.getPagePath('', check_create=0) else: # The comment will be immediately posted page = Page(self.macro.request,self.page_name) comment_dir = page.getPagePath('comments', check_create=1) # Compose the comment structure and write it now = datetime.now() random_str = ''.join([choice(letters + digits) for i in range(20)]) comment_file = '%s-%s.txt' % (now.strftime("%s"), random_str) file_name = os.path.join(comment_dir, comment_file) comment = self.comment comment['page'] = self.page_name comment['time'] = now if get_cfg(self.macro, 'comment_store_addr', False): comment['remote_addr'] = self.macro.request.remote_addr if self.moderate: self.msg = _('Your comment awaits moderation. Thank you.') else: self.msg = _('Your comment has been posted. Thank you.') write_comment( file_name, comment ) if self.moderate: # If we have defined a list of moderators to notify and this user is # moderated then a message is sent to the moderator list moderators = get_cfg(self.macro, 'comment_moderators', None) if moderators: sendmail.sendmail( self.macro.request, moderators.split(','), _('New comment awaits moderation for page %(page)s' % self.comment ), _('New comment awaits moderation:\n\nPage: %(page)s\nFrom: %(user_name)s\nMessage:\n\n%(comment)s\n\n--' % self.comment )) else: # Send notification to page subscribers if the page notify_subscribers(self.macro, self.comment) # clean up the fields to display self.reset_comment()