From b7b0b1801be49577f2023459454b22ff0a0f27c3 Mon Sep 17 00:00:00 2001 From: Timo Stollenwerk Date: Sun, 21 Jun 2009 07:48:33 +0000 Subject: [PATCH] very basic form validation added to comments viewlet. svn path=/plone.app.discussion/trunk/; revision=27564 --- plone/app/discussion/browser/comments.py | 56 ++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/plone/app/discussion/browser/comments.py b/plone/app/discussion/browser/comments.py index 9294bf0..6532232 100644 --- a/plone/app/discussion/browser/comments.py +++ b/plone/app/discussion/browser/comments.py @@ -18,6 +18,10 @@ from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile from Products.CMFCore.utils import getToolByName +from Products.CMFPlone import PloneMessageFactory as _ + +from Products.statusmessages.interfaces import IStatusMessage + from plone.registry.interfaces import IRegistry from plone.app.layout.viewlets.common import ViewletBase @@ -142,6 +146,32 @@ class AddComment(BrowserView): author_username = self.request.get('author_username') author_email = self.request.get('author_email') + # Check the form input + if author_username == '': + IStatusMessage(self.request).addStatusMessage(\ + _("Username field is empty."), + type="info") + self.request.response.redirect(aq_parent(aq_inner(self.context)).absolute_url()) + return None + if author_email == '': + IStatusMessage(self.request).addStatusMessage(\ + _("Email field is empty."), + type="info") + self.request.response.redirect(aq_parent(aq_inner(self.context)).absolute_url()) + return None + if subject == '': + IStatusMessage(self.request).addStatusMessage(\ + _("Subject field is empty."), + type="info") + self.request.response.redirect(aq_parent(aq_inner(self.context)).absolute_url()) + return None + if text == '': + IStatusMessage(self.request).addStatusMessage(\ + _("Comment field is empty."), + type="info") + self.request.response.redirect(aq_parent(aq_inner(self.context)).absolute_url()) + return None + # The add-comment view is called on the conversation object conversation = self.context @@ -190,6 +220,32 @@ class ReplyToComment(BrowserView): author_username = self.request.get('author_username') author_email = self.request.get('author_email') + # Check the form input + if author_username == '': + IStatusMessage(self.request).addStatusMessage(\ + _("Username field is empty."), + type="info") + self.request.response.redirect(aq_parent(aq_inner(self.context)).absolute_url()) + return None + if author_email == '': + IStatusMessage(self.request).addStatusMessage(\ + _("Email field is empty."), + type="info") + self.request.response.redirect(aq_parent(aq_inner(self.context)).absolute_url()) + return None + if subject == '': + IStatusMessage(self.request).addStatusMessage(\ + _("Subject field is empty."), + type="info") + self.request.response.redirect(aq_parent(aq_inner(self.context)).absolute_url()) + return None + if text == '': + IStatusMessage(self.request).addStatusMessage(\ + _("Comment field is empty."), + type="info") + self.request.response.redirect(aq_parent(aq_inner(self.context)).absolute_url()) + return None + # The add-comment view is called on the conversation object conversation = self.context