Permalink
Browse files

Added optional validation to the ticket fields

  • Loading branch information...
1 parent 38b8920 commit 797d6c5c705da17090ef47261fe4e2cd215964f2 @daltonmatos committed Nov 25, 2009
Showing with 48 additions and 1 deletion.
  1. +46 −0 conditionalfields/0.11/conditionalfields/validation.py
  2. +2 −1 conditionalfields/0.11/setup.py
@@ -0,0 +1,46 @@
+
+
+
+from trac.core import *
+from trac.ticket.api import ITicketManipulator
+from trac.util.translation import _
+from trac.web.chrome import add_warning
+from trac.ticket import TicketSystem
+
+
+class ConditionalFieldsValidation(Component):
+ implements(ITicketManipulator)
+
+ def _is_empty(self, value):
+ if value is None:
+ return True
+
+ if len(value) == 0:
+ return True
+
+ return False
+
+ def _get_field_label(self, field_name):
+ label = [field['label'] for field in TicketSystem(self.env).get_ticket_fields() if field['name'] == field_name]
+ if len(label) > 0:
+ return label[0]
+ return field_name
+
+ #ITicketManipulator
+ def prepare_ticket(self, req, ticket, fields, actions):
+ pass
+
+ def validate_ticket(self, req, ticket):
+
+ all_fields = TicketSystem(self.env).get_ticket_fields()
+
+ i = 1
+ while self.config.get('conditional-fields', 'ticket_type_%d' % i) != ticket['type'] and\
+ len(self.config.getlist('conditional-fields', 'ticket_type_%d' % i)) > 0:
+ i += 1
+
+ required_fields = self.config.getlist('conditional-fields', 'required_fields_%d' % i)
+
+ return [(field_name, _('O campo %s deve ser preenchido') % self._get_field_label(field_name)) for\
+ field_name in required_fields if self._is_empty(ticket[field_name])]
+
@@ -12,7 +12,8 @@
license='GPLv2',
entry_points = {
'trac.plugins': [
- 'conditionalfields = conditionalfields.conditionalfields'
+ 'conditionalfields = conditionalfields.conditionalfields',
+ 'conditionalfields.validation = conditionalfields.validation'
]
},
package_data = {

0 comments on commit 797d6c5

Please sign in to comment.