1 # -*- coding: UTF-8 -*-
6 # Copyright (C) 2003-2006 Facundo Batista <facundo@taniquetil.com.ar>
7 # Copyright (C) 2003-2006 Mariano Draghi <chaghi@sion.com>
9 # This file is placed under the Python 2.3 license, see
10 # http://www.python.org/2.3/license.html
14 class ValidationSupervisor(object):
15 def __init__(self
, statusBar
, name
):
16 self
._statusBar
= statusBar
20 self
._editMessages
= {}
23 def registerAction(self
, action
):
24 self
._actions
.append(action
)
31 def registerEditor(self
, editor
, message
, initialState
=None):
32 # as it's a dictionary, creating and setting is the same...
33 self
._editMessages
[editor
] = message
34 self
.setEditorState(editor
, initialState
)
37 def setEditorState(self
, editor
, newState
):
38 self
._editors
[editor
] = newState
39 self
.checkValidations()
42 def checkValidations(self
):
43 # print "check validations in vs", self._name
49 # print "result:", state
51 # just do it in all the registered actions
52 for action
in self
._actions
:
53 f
= getattr(action
, "Enable")
57 def registerExternalValidator(self
, validator
, message
):
58 f
= getattr(validator
, "validate")
59 self
._externals
.append((f
, message
))
64 for (editor
, state
) in self
._editors
.items():
65 # print "checking editor", editor, state
69 self
._statusBar
(self
._editMessages
[editor
])
72 # check external validators
73 for (validator
, message
) in self
._externals
:
74 # print "checking external", editor, state
76 # print "it gave:", result
80 self
._statusBar
(message
)
88 # All external validators must have a "validate" method.
90 # If that method returns ... the supervisor will ...:
91 # True: keep looking in the next validators, if all returns True, clears the statusBar and enables the controllers
92 # False: shows the configured error message in the statusBar and disables the controllers
93 # None: does not touch the statusBar and disables the controllers
95 class ExistAccountValidator(object):
96 def __init__(self
, entriesReport
):
97 self
.entriesReport
= entriesReport
100 if self
.entriesReport
.cuenta
is None:
104 class DateFromToValidator(object):
105 def __init__(self
, dateSelectorFrom
, dateSelectorTo
):
106 self
.dsFrom
= dateSelectorFrom
107 self
.dsTo
= dateSelectorTo
110 dateFrom
= self
.dsFrom
.GetDate()
111 dateTo
= self
.dsTo
.GetDate()
112 if not self
.dsFrom
.IsEnabled() and not self
.dsTo
.IsEnabled():
114 if dateFrom
is None or dateTo
is None:
117 return dateFrom
<= dateTo