12 |
12 |
13 from logilab.mtconverter import xml_escape |
13 from logilab.mtconverter import xml_escape |
14 from yams.constraints import (SizeConstraint, StaticVocabularyConstraint, |
14 from yams.constraints import (SizeConstraint, StaticVocabularyConstraint, |
15 FormatConstraint) |
15 FormatConstraint) |
16 |
16 |
17 from cubicweb.utils import ustrftime, compute_cardinality |
17 from cubicweb.utils import ustrftime |
18 from cubicweb.common import tags, uilib |
18 from cubicweb.common import tags, uilib |
19 from cubicweb.web import INTERNAL_FIELD_VALUE |
19 from cubicweb.web import INTERNAL_FIELD_VALUE |
20 from cubicweb.web.formwidgets import ( |
20 from cubicweb.web.formwidgets import ( |
21 HiddenInput, TextInput, FileInput, PasswordInput, TextArea, FCKEditor, |
21 HiddenInput, TextInput, FileInput, PasswordInput, TextArea, FCKEditor, |
22 Radio, Select, DateTimePicker) |
22 Radio, Select, DateTimePicker) |
488 def guess_field(eschema, rschema, role='subject', skip_meta_attr=True, **kwargs): |
488 def guess_field(eschema, rschema, role='subject', skip_meta_attr=True, **kwargs): |
489 """return the most adapated widget to edit the relation |
489 """return the most adapated widget to edit the relation |
490 'subjschema rschema objschema' according to information found in the schema |
490 'subjschema rschema objschema' according to information found in the schema |
491 """ |
491 """ |
492 fieldclass = None |
492 fieldclass = None |
|
493 card = eschema.cardinality(rschema, role) |
493 if role == 'subject': |
494 if role == 'subject': |
494 targetschema = rschema.objects(eschema)[0] |
495 targetschema = rschema.objects(eschema)[0] |
495 card = compute_cardinality(eschema, rschema, role) |
|
496 help = rschema.rproperty(eschema, targetschema, 'description') |
496 help = rschema.rproperty(eschema, targetschema, 'description') |
497 if rschema.is_final(): |
497 if rschema.is_final(): |
498 if rschema.rproperty(eschema, targetschema, 'internationalizable'): |
498 if rschema.rproperty(eschema, targetschema, 'internationalizable'): |
499 kwargs.setdefault('internationalizable', True) |
499 kwargs.setdefault('internationalizable', True) |
500 def get_default(form, es=eschema, rs=rschema): |
500 def get_default(form, es=eschema, rs=rschema): |
501 return es.default(rs) |
501 return es.default(rs) |
502 kwargs.setdefault('initial', get_default) |
502 kwargs.setdefault('initial', get_default) |
503 else: |
503 else: |
504 targetschema = rschema.subjects(eschema)[0] |
504 targetschema = rschema.subjects(eschema)[0] |
505 card = compute_cardinality(eschema, rschema, role) |
|
506 help = rschema.rproperty(targetschema, eschema, 'description') |
505 help = rschema.rproperty(targetschema, eschema, 'description') |
507 kwargs['required'] = card in '1+' |
506 kwargs['required'] = card in '1+' |
508 kwargs['name'] = rschema.type |
507 kwargs['name'] = rschema.type |
509 kwargs.setdefault('help', help) |
508 kwargs.setdefault('help', help) |
510 if rschema.is_final(): |
509 if rschema.is_final(): |