app/soc/modules/ghop/logic/cleaning.py
changeset 2820 eb57ebee8b91
child 2860 ea9909161840
equal deleted inserted replaced
2819:03e03b0ef0c6 2820:eb57ebee8b91
       
     1 #!/usr/bin/python2.5
       
     2 #
       
     3 # Copyright 2009 the Melange authors.
       
     4 #
       
     5 # Licensed under the Apache License, Version 2.0 (the "License");
       
     6 # you may not use this file except in compliance with the License.
       
     7 # You may obtain a copy of the License at
       
     8 #
       
     9 #   http://www.apache.org/licenses/LICENSE-2.0
       
    10 #
       
    11 # Unless required by applicable law or agreed to in writing, software
       
    12 # distributed under the License is distributed on an "AS IS" BASIS,
       
    13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
       
    14 # See the License for the specific language governing permissions and
       
    15 # limitations under the License.
       
    16 
       
    17 """GHOP module cleaning methods.
       
    18 """
       
    19 
       
    20 __authors__ = [
       
    21     '"Madhusudan.C.S" <madhusudancs@gmail.com>',
       
    22     ]
       
    23 
       
    24 
       
    25 from django import forms
       
    26 from django.utils.translation import ugettext
       
    27 
       
    28 
       
    29 def cleanTaskComment(comment_field, action_field, ws_field):
       
    30   """Cleans the comment form and checks to see if there is either
       
    31   action or comment content.
       
    32 
       
    33   Raises ValidationError if:
       
    34     -There is no action taking place and no comment present
       
    35     -The action is needs_review and there is no comment or work submission
       
    36      present
       
    37   """
       
    38 
       
    39   def wrapper(self):
       
    40     """Decorator wrapper method.
       
    41     """
       
    42     cleaned_data = self.cleaned_data
       
    43 
       
    44     content = cleaned_data.get(comment_field)
       
    45     action = cleaned_data.get(action_field)
       
    46     work_submission = cleaned_data.get(ws_field)
       
    47 
       
    48     if action == 'noaction' and not content:
       
    49       raise forms.ValidationError(
       
    50           ugettext('You cannot have comment field empty with no action.'))
       
    51     if action == 'needs_review' and not content and not work_submission:
       
    52       raise forms.ValidationError(
       
    53           ugettext('You cannot have both comment field and work '
       
    54                    'submission fields empty.'))
       
    55 
       
    56     return cleaned_data
       
    57 
       
    58   return wrapper