434 rows, cols = 10, 80 |
434 rows, cols = 10, 80 |
435 kwargs.setdefault('rows', rows) |
435 kwargs.setdefault('rows', rows) |
436 kwargs.setdefault('cols', cols) |
436 kwargs.setdefault('cols', cols) |
437 |
437 |
438 |
438 |
439 def guess_field(eclass, rschema, role='subject', skip_meta_attr=True, **kwargs): |
439 def guess_field(eschema, rschema, role='subject', skip_meta_attr=True, **kwargs): |
440 """return the most adapated widget to edit the relation |
440 """return the most adapated widget to edit the relation |
441 'subjschema rschema objschema' according to information found in the schema |
441 'subjschema rschema objschema' according to information found in the schema |
442 """ |
442 """ |
443 fieldclass = None |
443 fieldclass = None |
444 eschema = eclass.e_schema |
|
445 if role == 'subject': |
444 if role == 'subject': |
446 targetschema = rschema.objects(eschema)[0] |
445 targetschema = rschema.objects(eschema)[0] |
447 card = rschema.rproperty(eschema, targetschema, 'cardinality')[0] |
446 card = rschema.rproperty(eschema, targetschema, 'cardinality')[0] |
448 help = rschema.rproperty(eschema, targetschema, 'description') |
447 help = rschema.rproperty(eschema, targetschema, 'description') |
449 if rschema.is_final(): |
448 if rschema.is_final(): |
482 return stringfield_from_constraints(constraints, **kwargs) |
481 return stringfield_from_constraints(constraints, **kwargs) |
483 if fieldclass is FileField: |
482 if fieldclass is FileField: |
484 for metadata in ('format', 'encoding'): |
483 for metadata in ('format', 'encoding'): |
485 metaschema = eschema.has_metadata(rschema, metadata) |
484 metaschema = eschema.has_metadata(rschema, metadata) |
486 if metaschema is not None: |
485 if metaschema is not None: |
487 kwargs['%s_field' % metadata] = guess_field(eclass, metaschema, |
486 kwargs['%s_field' % metadata] = guess_field(eschema, metaschema, |
488 skip_meta_attr=False) |
487 skip_meta_attr=False) |
489 return fieldclass(**kwargs) |
488 return fieldclass(**kwargs) |
490 kwargs['role'] = role |
489 kwargs['role'] = role |
491 return RelationField.fromcardinality(card, **kwargs) |
490 return RelationField.fromcardinality(card, **kwargs) |
492 |
491 |