damned-lies r1268 - in trunk: . vertimus
- From: stephaner svn gnome org
- To: svn-commits-list gnome org
- Subject: damned-lies r1268 - in trunk: . vertimus
- Date: Tue, 30 Dec 2008 11:26:27 +0000 (UTC)
Author: stephaner
Date: Tue Dec 30 11:26:27 2008
New Revision: 1268
URL: http://svn.gnome.org/viewvc/damned-lies?rev=1268&view=rev
Log:
2008-12-30 StÃphane Raimbault <stephane raimbault gmail com>
* vertimus/forms.py:
* vertimus/models.py:
* vertimus/views.py: Added forms validators for file and comment.
Modified:
trunk/ChangeLog
trunk/vertimus/forms.py
trunk/vertimus/models.py
trunk/vertimus/views.py
Modified: trunk/vertimus/forms.py
==============================================================================
--- trunk/vertimus/forms.py (original)
+++ trunk/vertimus/forms.py Tue Dec 30 11:26:27 2008
@@ -23,7 +23,7 @@
from django import forms
from django.utils.translation import ugettext_lazy as _
-
+from vertimus.models import ActionAbstract
from stats.utils import po_file_stats
class ActionForm(forms.Form):
@@ -52,3 +52,17 @@
raise forms.ValidationError(".po file does not pass 'msgfmt -vc'. Please correct the file and try again.")
return data
+ def clean(self):
+ cleaned_data = self.cleaned_data
+ action = ActionAbstract.new_by_name(cleaned_data.get('action'))
+ comment = cleaned_data.get('comment')
+ file = cleaned_data.get('file')
+
+ if action.arg_is_required and not comment and not file:
+ raise forms.ValidationError(_("A comment or a file is needed for this action."))
+
+ if action.file_is_required and not file:
+ raise forms.ValidationError(_("A file is needed for this action."))
+
+ return cleaned_data
+
Modified: trunk/vertimus/models.py
==============================================================================
--- trunk/vertimus/models.py (original)
+++ trunk/vertimus/models.py Tue Dec 30 11:26:27 2008
@@ -287,9 +287,14 @@
def __unicode__(self):
return self.name
+
class ActionAbstract(object):
"""Abstract class"""
+ # A comment or a file is required
+ arg_is_required = False
+ file_is_required = False
+
@classmethod
def new_by_name(cls, action_name):
return eval('Action' + action_name)()
@@ -366,7 +371,8 @@
class ActionWC(ActionAbstract):
name = 'WC'
description = _('Write a comment')
-
+ arg_is_required = True
+
def _new_state(self):
return None
@@ -412,7 +418,7 @@
class ActionRT(ActionAbstract):
name = 'RT'
description = _('Reserve for translation')
-
+
def _new_state(self):
return StateTranslating()
@@ -423,7 +429,8 @@
class ActionUT(ActionAbstract):
name = 'UT'
description = _('Upload the new translation')
-
+ file_is_required = True
+
def _new_state(self):
return StateTranslated()
@@ -448,6 +455,7 @@
class ActionUP(ActionAbstract):
name = 'UP'
description = _('Upload for proofreading')
+ file_is_required = True
def _new_state(self):
return StateProofread()
@@ -503,6 +511,7 @@
class ActionTR(ActionAbstract):
name = 'TR'
description = _('Requiring review')
+ arg_is_required = True
def _new_state(self):
return StateToReview()
@@ -570,7 +579,7 @@
class ActionUNDO(ActionAbstract):
name = 'UNDO'
description = _('Undo the last state change')
-
+
def apply(self, state, person, comment=None, file=None):
self.save_action_db(state, person, comment, file)
Modified: trunk/vertimus/views.py
==============================================================================
--- trunk/vertimus/views.py (original)
+++ trunk/vertimus/views.py Tue Dec 30 11:26:27 2008
@@ -84,7 +84,7 @@
comment = action_form.cleaned_data['comment']
action = ActionAbstract.new_by_name(action)
- new_state = state.apply_action(action, person, comment, request.FILES.get('file',None))
+ new_state = state.apply_action(action, person, comment, request.FILES.get('file', None))
new_state.save()
return HttpResponseRedirect(
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]