[damned-lies] [vertimus] Do not accept comment submission with only an uploaded file
- From: Claude Paroz <claudep src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [damned-lies] [vertimus] Do not accept comment submission with only an uploaded file
- Date: Sat, 6 Mar 2010 20:15:04 +0000 (UTC)
commit 477d42fe5b729d992b13304e8a38690daf1a879b
Author: Claude Paroz <claude 2xlibre net>
Date: Sat Mar 6 21:14:09 2010 +0100
[vertimus] Do not accept comment submission with only an uploaded file
vertimus/forms.py | 3 +++
vertimus/models.py | 3 ++-
vertimus/tests/__init__.py | 7 +++----
3 files changed, 8 insertions(+), 5 deletions(-)
---
diff --git a/vertimus/forms.py b/vertimus/forms.py
index ff33b97..148aad6 100644
--- a/vertimus/forms.py
+++ b/vertimus/forms.py
@@ -73,6 +73,9 @@ class ActionForm(forms.Form):
comment = cleaned_data.get('comment')
file = cleaned_data.get('file')
+ if action.comment_is_required and not comment:
+ raise forms.ValidationError(_("A comment is needed for this action."))
+
if action.arg_is_required and not comment and not file:
raise forms.ValidationError(_("A comment or a file is needed for this action."))
diff --git a/vertimus/models.py b/vertimus/models.py
index ca2abf1..d21ba0b 100644
--- a/vertimus/models.py
+++ b/vertimus/models.py
@@ -420,6 +420,7 @@ class ActionAbstract(object):
# A comment or a file is required
arg_is_required = False
+ comment_is_required = False
file_is_required = False
file_is_prohibited = False
@@ -540,7 +541,7 @@ The new state of %(module)s - %(branch)s - %(domain)s (%(language)s) is now '%(n
class ActionWC(ActionAbstract):
name = 'WC'
description = _('Write a comment')
- arg_is_required = True
+ comment_is_required = True
def _new_state(self):
return None
diff --git a/vertimus/tests/__init__.py b/vertimus/tests/__init__.py
index fe261cd..da35a33 100644
--- a/vertimus/tests/__init__.py
+++ b/vertimus/tests/__init__.py
@@ -36,9 +36,6 @@ class VertimusTest(TeamTest):
def setUp(self):
super(VertimusTest, self).setUp()
- self.l = Language(name='french', locale='fr', team=self.t)
- self.l.save()
-
self.m = Module(name='gedit', description='GNOME Editor',
bugs_base="http://bugzilla.gnome.org/",
bugs_product='gedit', bugs_component='general',
@@ -70,7 +67,6 @@ class VertimusTest(TeamTest):
self.r.delete()
self.b.delete()
self.m.delete()
- self.l.delete()
super(VertimusTest, self).tearDown()
def test_state_none(self):
@@ -230,6 +226,9 @@ class VertimusTest(TeamTest):
action = ActionAbstract.new_by_name('WC')
new_state = state.apply_action(action, self.pt, "Hi!", None)
new_state.save()
+ # Test that submitting a comment without text generates a validation error
+ form = ActionForm([('WC', u'Write a comment')], QueryDict('action=WC&comment='))
+ self.assertTrue("A comment is needed" in str(form.errors))
def test_action_rt(self):
state = StateDb(branch=self.b, domain=self.d, language=self.l, name='None').get_state()
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]