def save(self, id=None): try: id = int(id) except: abort(400) comment_q = meta.Session.query(model.Comment) comment = comment_q.filter_by(id=id).first() if comment is None: abort(404) if self.form_result.has_key('rememberme'): del self.form_result['rememberme'] if self.form_result.has_key('wurdig_comment_question'): del self.form_result['wurdig_comment_question'] for k,v in self.form_result.items(): if getattr(comment, k) != v: setattr(comment, k, v) comment.content = h.mytidy(comment.content) comment.content = h.auto_link(comment.content) meta.Session.commit() session['flash'] = _('Comment successfully updated.') session.save() return redirect_to(controller='comment', action='list')
def save(self, id=None): if id is None: abort(404) comment_q = meta.Session.query(model.Comment) comment = comment_q.filter_by(id=id).first() if comment is None: abort(404) if not h.auth.authorized(h.auth.is_valid_user) and not h.wurdig_use_akismet(): if hasattr(self.form_result, 'wurdig_comment_question'): del self.form_result['wurdig_comment_question'] for k,v in self.form_result.items(): if getattr(comment, k) != v: setattr(comment, k, v) comment.content = h.mytidy(comment.content) comment.content = h.auto_link(comment.content) meta.Session.commit() session['flash'] = 'Comment successfully updated.' session.save() return redirect_to(controller='comment', action='list')
def create(self, action, post_id=None): if post_id is None: abort(404) post_q = meta.Session.query(model.Post) c.post = post_id and post_q.filter_by(id=int(post_id)).first() or None if c.post is None: abort(404) if not h.auth.authorized(h.auth.is_valid_user) and not h.wurdig_use_akismet(): if hasattr(self.form_result, 'wurdig_comment_question'): del self.form_result['wurdig_comment_question'] comment = model.Comment() for k, v in self.form_result.items(): setattr(comment, k, v) comment.post_id = c.post.id comment.created_on = datetime.datetime.now() comment.content = h.nl2br(comment.content) comment.content = h.mytidy(comment.content) comment.content = h.comment_filter(comment.content) comment.content = h.auto_link(comment.content) if h.auth.authorized(h.auth.is_valid_user): comment.approved = True session['flash'] = 'Your comment has been approved.' else: session['flash'] = 'Your comment is currently being moderated.' # @todo: email administrator w/ each new comment session.save() meta.Session.add(comment) meta.Session.commit() return redirect_to(controller='post', action='view', year=c.post.posted_on.strftime('%Y'), month=c.post.posted_on.strftime('%m'), slug=c.post.slug )
def create(self, post_id=None): try: post_id = int(post_id) except: abort(400) post_q = meta.Session.query(model.Post) c.post = post_id and post_q.filter_by(id=int(post_id)).first() or None if c.post is None: abort(404) # if rememberme is part of the form_result dict and true, set # a cookie based on user input. If rememberme is false, # delete the cookie. Finally, remove the form item from form_result # so that the session does not attempt to save value to database, # where there is no rememberme field for comments if self.form_result.has_key('rememberme'): if self.form_result['rememberme']: h.set_rememberme_cookie({ 'name': self.form_result['name'], 'email': self.form_result['email'], 'url': self.form_result['url'], 'rememberme': True }) else: h.delete_rememberme_cookie() del self.form_result['rememberme'] # remove comment question from form_result dict # so that the session does not attempt to save value to database, # where there is no wurdig_comment_question field for comments if self.form_result.has_key('wurdig_comment_question'): del self.form_result['wurdig_comment_question'] comment = model.Comment() for k, v in self.form_result.items(): setattr(comment, k, v) comment.post_id = c.post.id comment.created_on = datetime.datetime.utcnow() comment.content = h.mytidy(comment.content) comment.content = h.comment_filter(comment.content) comment.content = h.auto_link(comment.content) if h.auth.authorized(h.auth.is_valid_user): comment.approved = True session.save() meta.Session.add(comment) meta.Session.commit() if not h.auth.authorized(h.auth.is_valid_user): # Send email to admin notifying of new comment c.comment = comment message = EmailMessage(subject=_('New Comment for "%s"') % c.post.title, body=render('/email/new_comment.html'), from_email='%s <%s>' % (comment.name, comment.email), to=[h.wurdig_contact_email()]) message.send(fail_silently=True) session['flash'] = _('Your comment is currently being moderated.') else: session['flash'] = _('Your comment has been approved.') return redirect_to(controller='post', action='view', year=c.post.posted_on.strftime('%Y'), month=c.post.posted_on.strftime('%m'), slug=c.post.slug)
def _to_python(self, value, state): if value['content'] not in ['', u'', None]: value['content'] = h.mytidy(value['content']) return value