web/views/autoform.py
changeset 4587 70d47389630c
parent 4567 bf3453789887
parent 4585 912aba7e6400
child 4625 d8c3a50a8ee7
equal deleted inserted replaced
4567:bf3453789887 4587:70d47389630c
    83     _select_attrs = ('peid', 'rtype', 'role', 'pform', 'etype')
    83     _select_attrs = ('peid', 'rtype', 'role', 'pform', 'etype')
    84     removejs = "removeInlinedEntity('%s', '%s', '%s')"
    84     removejs = "removeInlinedEntity('%s', '%s', '%s')"
    85 
    85 
    86     def __init__(self, *args, **kwargs):
    86     def __init__(self, *args, **kwargs):
    87         for attr in self._select_attrs:
    87         for attr in self._select_attrs:
    88             setattr(self, attr, kwargs.pop(attr, None))
    88             # don't pop attributes from kwargs, so the end-up in
       
    89             # self.cw_extra_kwargs which is then passed to the edition form (see
       
    90             # the .form method)
       
    91             setattr(self, attr, kwargs.get(attr))
    89         super(InlineEntityEditionFormView, self).__init__(*args, **kwargs)
    92         super(InlineEntityEditionFormView, self).__init__(*args, **kwargs)
    90 
    93 
    91     def _entity(self):
    94     def _entity(self):
    92         assert self.cw_row is not None, self
    95         assert self.cw_row is not None, self
    93         return self.cw_rset.get_entity(self.cw_row, self.cw_col)
    96         return self.cw_rset.get_entity(self.cw_row, self.cw_col)
   382         pending_deletes = get_pending_deletes(form._cw, entity.eid)
   385         pending_deletes = get_pending_deletes(form._cw, entity.eid)
   383         for label, rschema, role in self.relations:
   386         for label, rschema, role in self.relations:
   384             related = []
   387             related = []
   385             if entity.has_eid():
   388             if entity.has_eid():
   386                 rset = entity.related(rschema, role, limit=form.related_limit)
   389                 rset = entity.related(rschema, role, limit=form.related_limit)
   387                 if rschema.has_perm(form._cw, 'delete'):
   390                 if role == 'subject':
       
   391                     haspermkwargs = {'fromeid': entity.eid}
       
   392                 else:
       
   393                     haspermkwargs = {'toeid': entity.eid}
       
   394                 if rschema.has_perm(form._cw, 'delete', **haspermkwargs):
   388                     toggleable_rel_link_func = toggleable_relation_link
   395                     toggleable_rel_link_func = toggleable_relation_link
   389                 else:
   396                 else:
   390                     toggleable_rel_link_func = lambda x, y, z: u''
   397                     toggleable_rel_link_func = lambda x, y, z: u''
   391                 for row in xrange(rset.rowcount):
   398                 for row in xrange(rset.rowcount):
   392                     nodeid = relation_id(entity.eid, rschema, role,
   399                     nodeid = relation_id(entity.eid, rschema, role,
   648         """return a list of (relation schema, role) to edit for the entity"""
   655         """return a list of (relation schema, role) to edit for the entity"""
   649         if self.display_fields is not None:
   656         if self.display_fields is not None:
   650             return self.display_fields
   657             return self.display_fields
   651         # XXX we should simply put eid in the generated section, no?
   658         # XXX we should simply put eid in the generated section, no?
   652         return [(rtype, role) for rtype, _, role in self._relations_by_section(
   659         return [(rtype, role) for rtype, _, role in self._relations_by_section(
   653             'attributes', strict=strict) if rtype != 'eid']
   660             'attributes', 'update', strict) if rtype != 'eid']
   654 
   661 
   655     def editable_relations(self):
   662     def editable_relations(self):
   656         """return a sorted list of (relation's label, relation'schema, role) for
   663         """return a sorted list of (relation's label, relation'schema, role) for
   657         relations in the 'relations' section
   664         relations in the 'relations' section
   658         """
   665         """