web/views/editforms.py
branchtls-sprint
changeset 1285 d5ce82d65c2b
parent 1277 2eeef019e186
child 1286 cb68c8af3858
equal deleted inserted replaced
1284:63ed4f4ff38d 1285:d5ce82d65c2b
    15 from logilab.mtconverter import html_escape
    15 from logilab.mtconverter import html_escape
    16 
    16 
    17 from cubicweb import typed_eid
    17 from cubicweb import typed_eid
    18 from cubicweb.selectors import (match_kwargs, one_line_rset, non_final_entity,
    18 from cubicweb.selectors import (match_kwargs, one_line_rset, non_final_entity,
    19                                 specified_etype_implements, yes)
    19                                 specified_etype_implements, yes)
    20 from cubicweb.rtags import RelationTags
       
    21 from cubicweb.utils import make_uid
    20 from cubicweb.utils import make_uid
    22 from cubicweb.view import EntityView
    21 from cubicweb.view import EntityView
    23 from cubicweb.common import tags
    22 from cubicweb.common import tags
    24 from cubicweb.web import INTERNAL_FIELD_VALUE, stdmsgs, formwidgets
    23 from cubicweb.web import INTERNAL_FIELD_VALUE, stdmsgs, formwidgets, uicfg
    25 from cubicweb.web.form import (FieldNotFound, CompositeForm, EntityFieldsForm,
    24 from cubicweb.web.form import (FieldNotFound, CompositeForm, EntityFieldsForm,
    26                                FormMixIn)
    25                                FormMixIn)
    27 from cubicweb.web.formfields import guess_field
    26 from cubicweb.web.formfields import guess_field
    28 from cubicweb.web.formrenderers import (FormRenderer, EntityFormRenderer,
    27 from cubicweb.web.formrenderers import (FormRenderer, EntityFormRenderer,
    29                                         EntityCompositeFormRenderer,
    28                                         EntityCompositeFormRenderer,
   147     needs_js = EntityFieldsForm.needs_js + ('cubicweb.ajax.js',)
   146     needs_js = EntityFieldsForm.needs_js + ('cubicweb.ajax.js',)
   148     cwtarget = 'eformframe'
   147     cwtarget = 'eformframe'
   149     cssclass = 'entityForm'
   148     cssclass = 'entityForm'
   150     copy_nav_params = True
   149     copy_nav_params = True
   151     attrcategories = ('primary', 'secondary')
   150     attrcategories = ('primary', 'secondary')
   152     
   151     # class attributes below are actually stored in the uicfg module since we
   153     # relations'category (eg primary/secondary/generic/metadata/generated)
   152     # don't want them to be reloaded
   154     rcategories = RelationTags()
   153     rcategories = uicfg.rcategories
   155     # use primary and not generated for eid since it has to be an hidden
   154     rwidgets = uicfg.rwidgets
   156     rcategories.set_rtag('primary', 'eid', 'subject')
   155     rinlined = uicfg.rinlined
   157     rcategories.set_rtag('metadata', 'creation_date', 'subject')
   156     rpermissions_overrides = uicfg.rpermissions_overrides
   158     rcategories.set_rtag('metadata', 'modification_date', 'subject')
   157         
   159     rcategories.set_rtag('generated', 'has_text', 'subject')
       
   160     rcategories.set_rtag('metadata', 'owned_by', 'subject')
       
   161     rcategories.set_rtag('metadata', 'created_by', 'subject')
       
   162     rcategories.set_rtag('generated', 'is', 'subject')
       
   163     rcategories.set_rtag('generated', 'is', 'object')
       
   164     rcategories.set_rtag('generated', 'is_instance_of', 'subject')
       
   165     rcategories.set_rtag('generated', 'is_instance_of', 'object')
       
   166     rcategories.set_rtag('generated', 'identity', 'subject')
       
   167     rcategories.set_rtag('generated', 'identity', 'object')
       
   168     rcategories.set_rtag('generated', 'require_permission', 'subject')
       
   169     rcategories.set_rtag('primary', 'in_state', 'subject')
       
   170     rcategories.set_rtag('generated', 'wf_info_for', 'subject')
       
   171     rcategories.set_rtag('generated', 'wf_info_for', 'subject')
       
   172     rcategories.set_rtag('secondary', 'description', 'subject')
       
   173 
       
   174     # relations'widget (eg one of available class name in cubicweb.web.formwidgets)
       
   175     rwidgets = RelationTags()
       
   176     # inlined view flag for non final relations: when True for an entry, the
       
   177     # entity(ies) at the other end of the relation will be editable from the
       
   178     # form of the edited entity
       
   179     rinlined = RelationTags()
       
   180     # set of tags of the form <action>_on_new on relations. <action> is a
       
   181     # schema action (add/update/delete/read), and when such a tag is found
       
   182     # permissions checking is by-passed and supposed to be ok
       
   183     rpermissions_overrides = RelationTags(use_set=True)
       
   184 
       
   185     @classmethod
   158     @classmethod
   186     def registered(cls, registry):
   159     def vreg_initialization_completed(cls):
   187         """build class using descriptor at registration time"""
       
   188         super(AutomaticEntityForm, cls).registered(registry)
       
   189         cls.init_rcategories()
       
   190         return cls
       
   191         
       
   192     @classmethod
       
   193     def init_rcategories(cls):
       
   194         """set default category tags for relations where it's not yet defined in
   160         """set default category tags for relations where it's not yet defined in
   195         the category relation tags
   161         the category relation tags
   196         """
   162         """
   197         for eschema in cls.schema.entities():
   163         for eschema in cls.schema.entities():
   198             for rschema, tschemas, role in eschema.relation_definitions(True):
   164             for rschema, tschemas, role in eschema.relation_definitions(True):