|
33 |
import types |
33 |
import types |
34 |
import sys |
34 |
import sys |
35 |
import re |
35 |
import re |
|
|
36 |
import copy |
36 |
import univention.config_registry |
37 |
import univention.config_registry |
37 |
import univention.debug |
38 |
import univention.debug |
38 |
|
39 |
|
|
210 |
return None |
211 |
return None |
211 |
|
212 |
|
212 |
def _replace( self, res, object ): |
213 |
def _replace( self, res, object ): |
213 |
return pattern_replace( res, object ) |
214 |
return pattern_replace( copy.copy(res), object ) |
214 |
|
215 |
|
215 |
def default(self, object): |
216 |
def default(self, object): |
|
|
217 |
base_default = copy.copy(self.base_default) |
216 |
if not object.set_defaults: |
218 |
if not object.set_defaults: |
217 |
if self.multivalue: |
219 |
if self.multivalue: |
218 |
return [] |
220 |
return [] |
219 |
else: |
221 |
else: |
220 |
return '' |
222 |
return '' |
221 |
|
223 |
|
222 |
if not self.base_default: |
224 |
if not base_default: |
223 |
return self.new() |
225 |
return self.new() |
224 |
|
226 |
|
225 |
if isinstance(self.base_default, (types.StringType, types.UnicodeType)): |
227 |
if isinstance(base_default, (types.StringType, types.UnicodeType)): |
226 |
return self._replace(self.base_default, object) |
228 |
return self._replace(base_default, object) |
227 |
|
229 |
|
228 |
# we can not import univention.admin.syntax here (recursive import) so we need to find another way to identify a complex syntax |
230 |
# we can not import univention.admin.syntax here (recursive import) so we need to find another way to identify a complex syntax |
229 |
if getattr( self.syntax, 'subsyntaxes', None ) is not None and isinstance( self.base_default[ 0 ], ( list, tuple ) ) and not self.multivalue: |
231 |
if getattr( self.syntax, 'subsyntaxes', None ) is not None and isinstance( base_default[ 0 ], ( list, tuple ) ) and not self.multivalue: |
230 |
return self.base_default[ 0 ] |
232 |
return base_default[ 0 ] |
231 |
# multivalue defaults will only be a part of templates, so not multivalue is the common way for modules |
233 |
# multivalue defaults will only be a part of templates, so not multivalue is the common way for modules |
232 |
elif (isinstance(self.base_default[0], (types.StringType, types.UnicodeType))) and not self.multivalue: |
234 |
elif (isinstance(base_default[0], (types.StringType, types.UnicodeType))) and not self.multivalue: |
233 |
res=self.base_default[0] |
235 |
res=base_default[0] |
234 |
for p in self.base_default[1]: |
236 |
for p in base_default[1]: |
235 |
if not object[p]: |
237 |
if not object[p]: |
236 |
return self.new() |
238 |
return self.new() |
237 |
res=res.replace('<'+p+'>', object[p]) |
239 |
res=res.replace('<'+p+'>', object[p]) |
238 |
return res |
240 |
return res |
239 |
|
241 |
|
240 |
elif (isinstance(self.base_default[0], (types.StringType, types.UnicodeType))): |
242 |
elif (isinstance(base_default[0], (types.StringType, types.UnicodeType))): |
241 |
for i in range(0,len(self.base_default)): |
243 |
for i in range(0,len(base_default)): |
242 |
if isinstance(self.base_default[i], (types.StringType, types.UnicodeType)): |
244 |
if isinstance(base_default[i], (types.StringType, types.UnicodeType)): |
243 |
self.base_default[i]=self._replace(self.base_default[i],object) |
245 |
base_default[i]=self._replace(base_default[i],object) |
244 |
else: # must be a list of loaded custom attributes then, so we return it if it has content |
246 |
else: # must be a list of loaded custom attributes then, so we return it if it has content |
245 |
if len(self.base_default[i])>0: |
247 |
if len(base_default[i])>0: |
246 |
if self.multivalue and type(self.base_default[i]) != types.ListType: |
248 |
if self.multivalue and type(base_default[i]) != types.ListType: |
247 |
return [self.base_default[i]] |
249 |
return [base_default[i]] |
248 |
else: |
250 |
else: |
249 |
return self.base_default[i] |
251 |
return base_default[i] |
250 |
else: |
252 |
else: |
251 |
# return the first element, this is only related to empty custom attributes which are loaded wrong, needs to be fixed elsewhere |
253 |
# return the first element, this is only related to empty custom attributes which are loaded wrong, needs to be fixed elsewhere |
252 |
if i>0: |
254 |
if i>0: |
253 |
if self.multivalue and not isinstance(self.base_default[0], types.ListType): |
255 |
if self.multivalue and not isinstance(base_default[0], types.ListType): |
254 |
return [self.base_default[0]] |
256 |
return [base_default[0]] |
255 |
else: |
257 |
else: |
256 |
return self.base_default[0] |
258 |
return base_default[0] |
257 |
else: |
259 |
else: |
258 |
return self.new() |
260 |
return self.new() |
259 |
return self.base_default |
261 |
return base_default |
260 |
|
262 |
|
261 |
elif isinstance(self.base_default[0], types.FunctionType) or callable( self.base_default[ 0 ] ): |
263 |
elif isinstance(base_default[0], types.FunctionType) or callable( base_default[ 0 ] ): |
262 |
for p in self.base_default[1]: |
264 |
for p in base_default[1]: |
263 |
if not object[p]: |
265 |
if not object[p]: |
264 |
return self.new() |
266 |
return self.new() |
265 |
return self.base_default[0](object, self.base_default[2]) |
267 |
return base_default[0](object, base_default[2]) |
266 |
else: |
268 |
else: |
267 |
return self.new() |
269 |
return self.new() |
268 |
|
270 |
|