317 |
317 |
318 by default true if the relation has single cardinality |
318 by default true if the relation has single cardinality |
319 """ |
319 """ |
320 return card in '1?' |
320 return card in '1?' |
321 |
321 |
|
322 @property |
|
323 def form_needs_multipart(self): |
|
324 """true if the form needs enctype=multipart/form-data""" |
|
325 if super(AutomaticEntityForm, self).form_needs_multipart: |
|
326 return True |
|
327 # take a look at inlined forms to check (recursively) if they |
|
328 # need multipart handling. |
|
329 # XXX: this is very suboptimal because inlined forms will be |
|
330 # selected / instantiated twice : here and during form rendering. |
|
331 # Potential solutions: |
|
332 # -> use subforms for inlined forms to get easiser access |
|
333 # -> use a simple onload js function to check if there is |
|
334 # a input type=file in the form |
|
335 # -> generate the <form> node when the content is rendered |
|
336 # and we know the correct enctype (formrenderer's w attribute |
|
337 # is not a StringIO) |
|
338 for rschema, targettypes, role in self.inlined_relations(): |
|
339 # inlined forms don't handle multiple target types |
|
340 if len(targettypes) != 1: |
|
341 continue |
|
342 targettype = targettypes[0] |
|
343 if self.should_inline_relation_form(rschema, targettype, role): |
|
344 entity = self.vreg['etypes'].etype_class(targettype)(self.req) |
|
345 subform = self.vreg['forms'].select('edition', self.req, entity=entity) |
|
346 if subform.form_needs_multipart: |
|
347 return True |
|
348 return False |
322 |
349 |
323 def etype_relation_field(etype, rtype, role='subject'): |
350 def etype_relation_field(etype, rtype, role='subject'): |
324 eschema = AutomaticEntityForm.schema.eschema(etype) |
351 eschema = AutomaticEntityForm.schema.eschema(etype) |
325 return AutomaticEntityForm.field_by_name(rtype, role, eschema) |
352 return AutomaticEntityForm.field_by_name(rtype, role, eschema) |
326 |
353 |