21
20
email = 'spe.stani.be@gmail.com'
24
summary = 'Please update your tags!'
23
summary = _('Please update your tags!')
26
25
def __init__(self, fields = NO_FIELDS):
27
26
"""For the paramters a Gui needs to be written"""
134
133
.replace('%(%(','<').replace(')s)s','>')%info
135
134
except KeyError, variable:
136
135
raise ValidationError(self.description,
137
_("The variable '%s' doesn't exist.")%variable,
138
_("The defined variables are: %s.")%
139
(', '.join(info.keys())))
136
"%s '%s' %s."%(_("The variable"),
137
variable,_("doesn't exist")),
138
"%s: %s."%(_('The defined variables are'),
139
(', '.join(info.keys()))))
141
141
def to_python(self,x):
147
147
def get_as_string(self):
148
148
"""For GUI: Translation, but no interpolation here"""
149
return translate(self.value_as_string)
149
return self.value_as_string
151
151
def set_as_string(self,x):
152
152
"""For GUI: Translation, but no interpolation here"""
153
self.value_as_string = to_english(x)
153
self.value_as_string = x
155
155
def get(self,info=None,value_as_string=None):
156
156
"""For code: Interpolated, but not translated
169
169
except SyntaxError:
170
170
raise ValidationError(self.description,
171
_('Invalid syntax "%s" for integer.')%x)
171
'%s "%s" %s.'%(_('Invalid syntax'),x,_('for integer')))
173
173
class IntegerField(Field):
177
177
def to_python(self,x):
178
178
error = ValidationError(self.description,
179
_('Invalid literal "%s" for integer.')%x)
179
'%s "%s" %s.'%(_('Invalid literal'),x,_('for integer')))
181
181
return int(round(self.eval(x)))
182
182
except ValueError:
192
192
value = super(PositiveIntegerField, self).to_python(x)
194
194
raise ValidationError(self.description,
195
_('The integer value "%s" is negative, but should be positive.')%x)
195
'%s "%s" %s.'%(('The integer value'),x,
196
_('is negative, but should be positive')))
198
199
class PositiveNonZeroIntegerField(PositiveIntegerField):
204
205
value = super(PositiveNonZeroIntegerField, self).to_python(x)
206
207
raise ValidationError(self.description,
207
_('The integer value "%s" is zero, but should be non-zero.')%x)
208
'%s "%s" %s.'%(_('The integer value'),x,
209
_('is zero, but should be non-zero.')))
210
212
class DpiField(PositiveNonZeroIntegerField):
222
224
return float(self.eval(x))
223
225
except ValueError, message:
224
226
raise ValidationError(self.description,
225
_('Invalid literal "%s" for float.')%x)
227
'%s "%s" %s.'%(_('Invalid literal'),x,_('for float')))
227
229
class BooleanField(Field):
228
230
description = _('boolean')
232
def to_string(self,x):
233
return super(BooleanField,self).to_string(x).lower()
230
235
def to_python(self,x):
231
if x.lower() in ['true','1',_('true')]: return True
232
if x.lower() in ['false','0',_('false')]: return False
236
if x.lower() in ['1','true']: return True
237
if x.lower() in ['0','false']: return False
233
238
raise ValidationError(self.description,
234
_('Invalid literal "%s" for boolean (%s,%s).')\
235
%(x,_('true'),_('false')))
239
'%s "%s" %s (%s,%s).'%(_('Invalid literal'), x,_('for boolean'),
240
_('true'),_('false')))
237
242
class CharField(Field):
238
description = 'string'
243
description = _('string')
241
246
class ChoiceField(CharField):
242
description = 'choice'
247
description = _('choice')
243
248
def __init__(self,value,choices,**keyw):
244
249
super(ChoiceField,self).__init__(value,**keyw)
245
250
self.choices = choices
255
260
super(ImageTypeField,self).__init__(value,ct.IMAGE_EXTENSIONS,**keyw)
257
262
def set_as_string(self,x):
258
264
if x and x[0]=='.':
260
266
super(ImageTypeField,self).set_as_string(x)