web/views/editforms.py
branchtls-sprint
changeset 1455 a2c8b07d61b4
parent 1453 a9841184be7c
child 1458 3a3ad51a591e
equal deleted inserted replaced
1454:1668989a8f0e 1455:a2c8b07d61b4
   264         called.
   264         called.
   265         """
   265         """
   266         try:
   266         try:
   267             return super(AutomaticEntityForm, cls_or_self).field_by_name(name, role)
   267             return super(AutomaticEntityForm, cls_or_self).field_by_name(name, role)
   268         except FieldNotFound: # XXX should raise more explicit exception
   268         except FieldNotFound: # XXX should raise more explicit exception
   269             if eclass is None:
   269             if eclass is None or not name in self.schema:
   270                 raise
   270                 raise
   271             field = guess_field(eschema, cls_or_self.schema.rschema(name), role,
   271             rschema = cls_or_self.schema.rschema(name)
   272                                 eidparam=True)
   272             fieldcls = cls_or_self.rfields.etype_rtag(eschema, rschema, role)
       
   273             if fieldcls:
       
   274                 return fieldcls(name=name, role=role, eidparam=True)
       
   275             widget = cls_or_self.rwidgets.etype_rtag(eschema, rschema, role)
       
   276             if widget:
       
   277                 field = guess_field(eschema, rschema, role,
       
   278                                     eidparam=True, widget=widget)
       
   279             else:
       
   280                 field = guess_field(eschema, rschema, role, eidparam=True)
   273             if field is None:
   281             if field is None:
   274                 raise
   282                 raise
   275             return field
   283             return field
   276 
   284 
   277     def __init__(self, *args, **kwargs):
   285     def __init__(self, *args, **kwargs):
   278         super(AutomaticEntityForm, self).__init__(*args, **kwargs)
   286         super(AutomaticEntityForm, self).__init__(*args, **kwargs)
   279         if self.edited_entity.has_eid():
   287         entity = self.edited_entity
   280             self.edited_entity.complete()
   288         if entity.has_eid():
       
   289             entity.complete()
   281         for rschema, role in self.editable_attributes():
   290         for rschema, role in self.editable_attributes():
   282             try:
   291             try:
   283                 self.field_by_name(rschema.type, role)
   292                 self.field_by_name(rschema.type, role)
   284                 continue # explicitly specified
   293                 continue # explicitly specified
   285             except FieldNotFound:
   294             except FieldNotFound:
   286                 pass # has to be guessed
   295                 # has to be guessed
   287             fieldcls = self.rfields.etype_rtag(self.edited_entity.id, rschema,
   296                 try:
   288                                                role)
   297                     field = self.field_by_name(rschema.type, role,
   289             if fieldcls:
   298                                                eschema=entity.e_schema)
   290                 field = fieldcls(name=rschema.type, role=role, eidparam=True)
   299                     self.fields.append(field)
   291                 self.fields.append(field)
   300                 except FieldNotFound:
   292                 continue
   301                     # meta attribute such as <attr>_format
   293             widget = self.rwidgets.etype_rtag(self.edited_entity.id, rschema,
   302                     continue
   294                                               role)
       
   295             if widget:
       
   296                 field = guess_field(self.edited_entity.e_schema, rschema, role,
       
   297                                     eidparam=True, widget=widget)
       
   298             else:
       
   299                 field = guess_field(self.edited_entity.e_schema, rschema, role,
       
   300                                     eidparam=True)
       
   301             if field is not None:
       
   302                 self.fields.append(field)
       
   303         self.maxrelitems = self.req.property_value('navigation.related-limit')
   303         self.maxrelitems = self.req.property_value('navigation.related-limit')
   304         self.force_display = bool(self.req.form.get('__force_display'))
   304         self.force_display = bool(self.req.form.get('__force_display'))
   305 
   305 
   306     @property
   306     @property
   307     def related_limit(self):
   307     def related_limit(self):
   430         by default true if there is no related entity or if the relation has
   430         by default true if there is no related entity or if the relation has
   431         multiple cardinality
   431         multiple cardinality
   432         """
   432         """
   433         return not existant or card in '+*'
   433         return not existant or card in '+*'
   434 
   434 
       
   435 def etype_relation_field(etype, rtype, role='subject'):
       
   436     eschema = AutomaticEntityForm.schema.eschema(etype)
       
   437     return AutomaticEntityForm.field_by_name(rtype, role, eschema)
   435 
   438 
   436 class EditionFormView(FormViewMixIn, EntityView):
   439 class EditionFormView(FormViewMixIn, EntityView):
   437     """display primary entity edition form"""
   440     """display primary entity edition form"""
   438     id = 'edition'
   441     id = 'edition'
   439     # add yes() so it takes precedence over deprecated views in baseforms,
   442     # add yes() so it takes precedence over deprecated views in baseforms,