|
Lines 240-297
class property:
Link Here
|
| 240 |
|
240 |
|
| 241 |
def default(self, object): |
241 |
def default(self, object): |
| 242 |
if not object.set_defaults: |
242 |
if not object.set_defaults: |
| 243 |
if self.multivalue: |
243 |
return [] if self.multivalue else '' |
| 244 |
return [] |
|
|
| 245 |
else: |
| 246 |
return '' |
| 247 |
|
244 |
|
| 248 |
if not self.base_default: |
245 |
if not self.base_default: |
| 249 |
return self.new() |
246 |
return self.new() |
| 250 |
|
247 |
|
| 251 |
if isinstance(self.base_default, (types.StringType, types.UnicodeType)): |
248 |
if isinstance(self.base_default, basestring): |
| 252 |
return self._replace(self.base_default, object) |
249 |
return self._replace(self.base_default, object) |
| 253 |
|
250 |
|
|
|
251 |
bd0 = self.base_default[0] |
| 252 |
|
| 254 |
# we can not import univention.admin.syntax here (recursive import) so we need to find another way to identify a complex syntax |
253 |
# we can not import univention.admin.syntax here (recursive import) so we need to find another way to identify a complex syntax |
| 255 |
if getattr(self.syntax, 'subsyntaxes', None) is not None and isinstance(self.base_default[0], (list, tuple)) and not self.multivalue: |
254 |
if getattr(self.syntax, 'subsyntaxes', None) is not None and isinstance(bd0, (list, tuple)) and not self.multivalue: |
| 256 |
return self.base_default[0] |
255 |
return bd0 |
| 257 |
# multivalue defaults will only be a part of templates, so not multivalue is the common way for modules |
256 |
|
| 258 |
elif (isinstance(self.base_default[0], (types.StringType, types.UnicodeType))) and not self.multivalue: |
257 |
if isinstance(bd0, basestring): |
| 259 |
res = self.base_default[0] |
258 |
# multivalue defaults will only be a part of templates, so not multivalue is the common way for modules |
| 260 |
for p in self.base_default[1]: |
259 |
if not self.multivalue: # default=(template-str, [list-of-required-properties]) |
| 261 |
if not object[p]: |
260 |
if all(object[p] for p in self.base_default[1]): |
| 262 |
return self.new() |
261 |
for p in self.base_default[1]: |
| 263 |
res = res.replace('<' + p + '>', object[p]) |
262 |
bd0 = bd0.replace('<%s>' % (p,), object[p]) |
| 264 |
return res |
263 |
return bd0 |
| 265 |
|
264 |
return self.new() |
| 266 |
elif (isinstance(self.base_default[0], (types.StringType, types.UnicodeType))): |
265 |
else: # multivalue |
| 267 |
for i in range(0, len(self.base_default)): |
266 |
if all(isinstance(bd, basestring) for bd in self.base_default): |
| 268 |
if isinstance(self.base_default[i], (types.StringType, types.UnicodeType)): |
267 |
return [self._replace(bd, object) for bd in self.base_default] |
| 269 |
self.base_default[i] = self._replace(self.base_default[i], object) |
268 |
# must be a list of loaded extended attributes then, so we return it if it has content |
| 270 |
else: # must be a list of loaded extended attributes then, so we return it if it has content |
269 |
# return the first element, this is only related to empty extended attributes which are loaded wrong, needs to be fixed elsewhere |
| 271 |
if len(self.base_default[i]) > 0: |
270 |
if bd0: |
| 272 |
if self.multivalue and not isinstance(self.base_default[i], types.ListType): |
271 |
return [bd0] |
| 273 |
return [self.base_default[i]] |
272 |
return self.new() |
| 274 |
else: |
273 |
|
| 275 |
return self.base_default[i] |
274 |
if callable(bd0): # default=(func_obj_extra, [list-of-required-properties], extra-arg) |
| 276 |
else: |
275 |
if all(object[p] for p in self.base_default[1]): |
| 277 |
# return the first element, this is only related to empty extended attributes which are loaded wrong, needs to be fixed elsewhere |
276 |
return bd0(object, self.base_default[2]) |
| 278 |
if i > 0: |
|
|
| 279 |
if self.multivalue and not isinstance(self.base_default[0], types.ListType): |
| 280 |
return [self.base_default[0]] |
| 281 |
else: |
| 282 |
return self.base_default[0] |
| 283 |
else: |
| 284 |
return self.new() |
| 285 |
return self.base_default |
| 286 |
|
| 287 |
elif isinstance(self.base_default[0], types.FunctionType) or callable(self.base_default[0]): |
| 288 |
for p in self.base_default[1]: |
| 289 |
if not object[p]: |
| 290 |
return self.new() |
| 291 |
return self.base_default[0](object, self.base_default[2]) |
| 292 |
else: |
| 293 |
return self.new() |
277 |
return self.new() |
| 294 |
|
278 |
|
|
|
279 |
return self.new() |
| 280 |
|
| 295 |
def safe_default(self, object): |
281 |
def safe_default(self, object): |
| 296 |
def safe_parse(default): |
282 |
def safe_parse(default): |
| 297 |
if not default: |
283 |
if not default: |
|
Lines 302-308
class property:
Link Here
|
| 302 |
except: |
288 |
except: |
| 303 |
return False |
289 |
return False |
| 304 |
defaults = self.default(object) |
290 |
defaults = self.default(object) |
| 305 |
if isinstance(defaults, types.ListType): |
291 |
if isinstance(defaults, list): |
| 306 |
return [self.syntax.parse(d) for d in defaults if safe_parse(d)] |
292 |
return [self.syntax.parse(d) for d in defaults if safe_parse(d)] |
| 307 |
elif safe_parse(defaults): |
293 |
elif safe_parse(defaults): |
| 308 |
return self.syntax.parse(defaults) |
294 |
return self.syntax.parse(defaults) |
|
Lines 311-317
class property:
Link Here
|
| 311 |
def check_default(self, object): |
297 |
def check_default(self, object): |
| 312 |
defaults = self.default(object) |
298 |
defaults = self.default(object) |
| 313 |
try: |
299 |
try: |
| 314 |
if isinstance(defaults, types.ListType): |
300 |
if isinstance(defaults, list): |
| 315 |
for d in defaults: |
301 |
for d in defaults: |
| 316 |
if d: |
302 |
if d: |
| 317 |
self.syntax.parse(d) |
303 |
self.syntax.parse(d) |