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 |
15 |
16 from cubicweb.schema import FormatConstraint |
16 from cubicweb.schema import FormatConstraint |
17 from cubicweb.utils import ustrftime |
17 from cubicweb.utils import ustrftime, compute_cardinality |
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) |
458 'subjschema rschema objschema' according to information found in the schema |
458 'subjschema rschema objschema' according to information found in the schema |
459 """ |
459 """ |
460 fieldclass = None |
460 fieldclass = None |
461 if role == 'subject': |
461 if role == 'subject': |
462 targetschema = rschema.objects(eschema)[0] |
462 targetschema = rschema.objects(eschema)[0] |
463 card = rschema.rproperty(eschema, targetschema, 'cardinality')[0] |
463 card = compute_cardinality(eschema, rschema, role) |
464 help = rschema.rproperty(eschema, targetschema, 'description') |
464 help = rschema.rproperty(eschema, targetschema, 'description') |
465 if rschema.is_final(): |
465 if rschema.is_final(): |
466 if rschema.rproperty(eschema, targetschema, 'internationalizable'): |
466 if rschema.rproperty(eschema, targetschema, 'internationalizable'): |
467 kwargs.setdefault('internationalizable', True) |
467 kwargs.setdefault('internationalizable', True) |
468 def get_default(form, es=eschema, rs=rschema): |
468 def get_default(form, es=eschema, rs=rschema): |
469 return es.default(rs) |
469 return es.default(rs) |
470 kwargs.setdefault('initial', get_default) |
470 kwargs.setdefault('initial', get_default) |
471 else: |
471 else: |
472 targetschema = rschema.subjects(eschema)[0] |
472 targetschema = rschema.subjects(eschema)[0] |
473 card = rschema.rproperty(targetschema, eschema, 'cardinality')[1] |
473 card = compute_cardinality(eschema, rschema, role) |
474 help = rschema.rproperty(targetschema, eschema, 'description') |
474 help = rschema.rproperty(targetschema, eschema, 'description') |
475 kwargs['required'] = card in '1+' |
475 kwargs['required'] = card in '1+' |
476 kwargs['name'] = rschema.type |
476 kwargs['name'] = rschema.type |
477 kwargs.setdefault('help', help) |
477 kwargs.setdefault('help', help) |
478 if rschema.is_final(): |
478 if rschema.is_final(): |