aboutsummaryrefslogtreecommitdiffstats
path: root/techlibs/common/.gitignore
blob: 0a1e7b68d5fd41cc7085037c6f9b42e69f4db992 (plain)
1
2
ob'>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
from xen.sv.util import *
from xen.sv.HTMLBase import HTMLBase
from xen.sv.GenTabbed import GenTabbed, ActionTab
from xen.xend import sxp

import re

DEBUG = 0

class Wizard( GenTabbed ):

    def __init__( self, urlWriter, title, sheets ):
        self.title = title
        self.sheets = sheets
        self.urlWriter = urlWriter
        self.offset = 0
        GenTabbed.__init__( self, title, urlWriter, map( lambda x: x.title, sheets ), sheets ) 
        
    def write_MENU( self, request ):
    	request.write( "<p class='small'><a href='%s'>%s</a></p>" % (self.urlWriter( '' ), self.title) ) 
    
    def write_BODY( self, request ):
        GenTabbed.write_BODY( self, request )
        actionTab = ActionTab( { ("tab", str(self.tab-1)) : "< Prev", ("tab", str(self.tab+1)) : "Next >", "finish" : "Finish" } )
        actionTab.write_BODY( request )

    def perform( self, request ):
        try:
            action = getVar( 'op', request, 0 )
            if action == "tab":
                self.tab = int( getVar( 'args', request ) )
                oldtab = int( getVar( 'tab', request ) )
                if not self.tabObjects[ oldtab ]( self.urlWriter ).validate( request ):
                    self.tab = oldtab
            else:
                self.tab = int( getVar( 'tab', request, 0 ) )
                self.tabObjects[ self.tab ]( self.urlWriter ).perform( request )
                getattr( self, "op_" +  getVar( "op", request ), None )( request )
        except:
            pass
            
    def op_finish( self, request ):
    	pass  
        
class Sheet( HTMLBase ):

    def __init__( self, urlWriter, title, location ):
        HTMLBase.__init__( self )
        self.urlWriter = urlWriter
        self.fields = []
        self.title = title
        self.location = location
        self.passback = None
        
    def parseForm( self, request ):
    	do_not_parse = [ 'mod', 'op', 'passback' ] 
    
    	passed_back = request.args
        
        temp_passback = passed_back.get( "passback" )
        
        if temp_passback is not None and len( temp_passback ) > 0:
            temp_passback = temp_passback[ len( temp_passback )-1 ]
        else:
            temp_passback = "( )"        
        
        last_passback = ssxp2hash( string2sxp( temp_passback ) ) #use special function - will work with no head on sxp
        
        if DEBUG: print last_passback
        
        for (key, value) in passed_back.items():
            if key not in do_not_parse:
                last_passback[ key ] = value[ len( value ) - 1 ]
                
        self.passback = sxp2string( hash2sxp( last_passback ) ) #store the sxp
        
        if DEBUG: print self.passback
        
    def write_BODY( self, request ):
    
    	if not self.passback: self.parseForm( request )
        
   	request.write( "<p>%s</p>" % self.title )
    
    	previous_values = ssxp2hash( string2sxp( self.passback ) ) #get the hash for quick reference
        
        request.write( "<table width='100%' cellpadding='0' cellspacing='1' border='0'>" )
        
    	for (field, control) in self.fields:
            control.write_Control( request, previous_values.get( field ) )
            if previous_values.get( field ) is not None and not control.validate( previous_values.get( field ) ):
            	control.write_Help( request )
            
        request.write( "</table>" )
            
        request.write( "<input type='hidden' name='passback' value=\"%s\"></p>" % self.passback )
        #request.write( "<input type='hidden' name='visited-sheet%s' value='True'></p>" % self.location )
                
    def addControl( self, control ):
    	self.fields.append( [ control.getName(), control ] )
        
    def validate( self, request ):
    
        if not self.passback: self.parseForm( request )
            
    	check = True
        
        previous_values = ssxp2hash( string2sxp( self.passback ) ) #get the map for quick reference
    	if DEBUG: print previous_values
      
      	for (field, control) in self.fields:
            if not control.validate( previous_values.get( field ) ):
                check = False
                if DEBUG: print "> %s = %s" % (field, previous_values.get( field ))

        return check
        
class SheetControl( HTMLBase ):

    def __init__( self, reg_exp = ".*" ):
        HTMLBase.__init__( self )
        self.name = ""
        self.reg_exp = reg_exp 
        
    def write_Control( self, request, persistedValue ):
        request.write( "<tr colspan='2'><td>%s</td></tr>" % persistedValue )
        
    def write_Help( self, request ):
        request.write( "<tr><td align='right' colspan='2'><p class='small'>Text must match pattern:" )
        request.write( " %s</p></td></tr>" % self.reg_exp )
        
    def validate( self, persistedValue ):
    	if persistedValue is None:
            persistedValue = ""
            
        return not re.compile( self.reg_exp ).match( persistedValue ) is None

    def getName( self ):
    	return self.name
        
    def setName( self, name ):
    	self.name = name
        
class InputControl( SheetControl ):

    def __init__( self, name, defaultValue, humanText,  reg_exp = ".*", help_text = "You must enter the appropriate details in this field." ):
        SheetControl.__init__( self, reg_exp )
        self.setName( name )
        
        self.defaultValue = defaultValue
        self.humanText = humanText
        self.help_text = help_text
        
    def write_Control( self, request, persistedValue ):
    	if persistedValue is None:
            persistedValue = self.defaultValue
        
        request.write( "<tr><td width='50%%'><p>%s</p></td><td width='50%%'><input size='40'type='text' name='%s' value=\"%s\"></td></tr>" % (self.humanText, self.getName(), persistedValue) )

    def write_Help( self, request ):
        request.write( "<tr><td align='right' colspan='2'><p class='small'>" )
        request.write( " %s</p></td></tr>" % self.help_text )         
        
class TextControl( SheetControl ):

    def __init__( self, text ):
    	SheetControl.__init__( self )
        self.text = text
        
    def write_Control( self, request, persistedValue ):
    	request.write( "<tr><td colspan='2'><p>%s</p></td></tr>" % self.text )

class SmallTextControl( SheetControl ):

    def __init__( self, text ):
    	SheetControl.__init__( self )
        self.text = text
        
    def write_Control( self, request, persistedValue ):
    	request.write( "<tr><td colspan='2'><p class='small'>%s</p></tr></td>" % self.text )
        
class ListControl( SheetControl ):

    def __init__( self, name, options, humanText ):
    	SheetControl.__init__( self )
        self.setName( name )
        self.options = options
        self.humanText = humanText
        
    def write_Control( self, request, persistedValue ):
        request.write( "<tr><td width='50%%'><p>%s</p></td><td width='50%%'>" % self.humanText )
    	request.write( "<select name='%s'>" % self.getName() )
        for (value, text) in self.options:
            if value == persistedValue:
            	request.write( "<option value='%s' selected>%s\n" % (value, text) )
            else:
                request.write( "<option value='%s'>%s\n" % (value, text) )
        request.write( "</select></td></tr>" )

    def validate( self, persistedValue ):
        for (value, text) in self.options:
            if value == persistedValue:
                return True
                
        return False
        
class FileControl( InputControl ):

    def __init__( self, name, defaultValue, humanText,  reg_exp = ".*", help_text = "You must enter the appropriate details in this field." ):
	InputControl.__init__( self, name, defaultValue, humanText )
        
    def validate( self, persistedValue ):
        if persistedValue is None: return False
        try:
            open( persistedValue )
            return True
        except IOError, TypeError:
            return False
    
    def write_Help( self, request ):
        request.write( "<tr><td colspan='2' align='right'><p class='small'>File does not exist: you must enter a valid, absolute file path.</p></td></tr>" )

class TickControl( SheetControl ):

    def __init__( self, name, defaultValue, humanText ):
        SheetControl.__init__( self )
        self.setName( name )
        self.defaultValue = defaultValue
        self.humanText = humanText
        
    def write_Control( self, request, persistedValue ):
        request.write( "<tr><td width='50%%'><p>%s</p></td><td width='50%%'>" % self.humanText )

        #request.write( str( persistedValue ) )

        #TODO: Theres a problem with this: it doesn't persist an untick, because the browsers don't pass it back. Need a fix...
        
        if persistedValue == 'True':
    	    request.write( "<input type='checkbox' name='%s' value='True' checked>" % self.getName() )
        else:
    	    request.write( "<input type='checkbox' name='%s' value='True'>" % self.getName() )
            
        request.write( "</td></tr>" )