web/views/cwproperties.py
brancholdstable
changeset 8746 88c71ad83d47
parent 8190 2a3c1b787688
child 8665 e65af61bde7d
equal deleted inserted replaced
8507:0c111b232927 8746:88c71ad83d47
     1 # copyright 2003-2011 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
     1 # copyright 2003-2012 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
     2 # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
     2 # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
     3 #
     3 #
     4 # This file is part of CubicWeb.
     4 # This file is part of CubicWeb.
     5 #
     5 #
     6 # CubicWeb is free software: you can redistribute it and/or modify it under the
     6 # CubicWeb is free software: you can redistribute it and/or modify it under the
    23 from logilab.mtconverter import xml_escape
    23 from logilab.mtconverter import xml_escape
    24 
    24 
    25 from logilab.common.decorators import cached
    25 from logilab.common.decorators import cached
    26 
    26 
    27 from cubicweb import UnknownProperty
    27 from cubicweb import UnknownProperty
    28 from cubicweb.selectors import (one_line_rset, none_rset, is_instance,
    28 from cubicweb.predicates import (one_line_rset, none_rset, is_instance,
    29                                 match_user_groups, objectify_selector,
    29                                  match_user_groups, logged_user_in_rset)
    30                                 logged_user_in_rset)
       
    31 from cubicweb.view import StartupView
    30 from cubicweb.view import StartupView
    32 from cubicweb.web import uicfg, stdmsgs
    31 from cubicweb.web import uicfg, stdmsgs
    33 from cubicweb.web.form import FormViewMixIn
    32 from cubicweb.web.form import FormViewMixIn
    34 from cubicweb.web.formfields import FIELDS, StringField
    33 from cubicweb.web.formfields import FIELDS, StringField
    35 from cubicweb.web.formwidgets import (Select, TextInput, Button, SubmitButton,
    34 from cubicweb.web.formwidgets import (Select, TextInput, Button, SubmitButton,
    36                                       FieldWidget)
    35                                       FieldWidget)
    37 from cubicweb.web.views import primary, formrenderers, editcontroller
    36 from cubicweb.web.views import primary, formrenderers, editcontroller
       
    37 from cubicweb.web.views.ajaxcontroller import ajaxfunc
    38 
    38 
    39 uicfg.primaryview_section.tag_object_of(('*', 'for_user', '*'), 'hidden')
    39 uicfg.primaryview_section.tag_object_of(('*', 'for_user', '*'), 'hidden')
    40 
    40 
    41 # some string we want to be internationalizable for nicer display of property
    41 # some string we want to be internationalizable for nicer display of property
    42 # groups
    42 # groups
   417         """return (path, parameters) which should be used as redirect
   417         """return (path, parameters) which should be used as redirect
   418         information when this entity is being deleted
   418         information when this entity is being deleted
   419         """
   419         """
   420         return 'view', {}
   420         return 'view', {}
   421 
   421 
       
   422 
       
   423 @ajaxfunc(output_type='xhtml')
       
   424 def prop_widget(self, propkey, varname, tabindex=None):
       
   425     """specific method for CWProperty handling"""
       
   426     entity = self._cw.vreg['etypes'].etype_class('CWProperty')(self._cw)
       
   427     entity.eid = varname
       
   428     entity['pkey'] = propkey
       
   429     form = self._cw.vreg['forms'].select('edition', self._cw, entity=entity)
       
   430     form.build_context()
       
   431     vfield = form.field_by_name('value')
       
   432     renderer = formrenderers.FormRenderer(self._cw)
       
   433     return vfield.render(form, renderer, tabindex=tabindex) \
       
   434            + renderer.render_help(form, vfield)
       
   435 
   422 _afs = uicfg.autoform_section
   436 _afs = uicfg.autoform_section
   423 _afs.tag_subject_of(('*', 'for_user', '*'), 'main', 'hidden')
   437 _afs.tag_subject_of(('*', 'for_user', '*'), 'main', 'hidden')
   424 _afs.tag_object_of(('*', 'for_user', '*'), 'main', 'hidden')
   438 _afs.tag_object_of(('*', 'for_user', '*'), 'main', 'hidden')
   425 _aff = uicfg.autoform_field
   439 _aff = uicfg.autoform_field
   426 _aff.tag_attribute(('CWProperty', 'pkey'), PropertyKeyField)
   440 _aff.tag_attribute(('CWProperty', 'pkey'), PropertyKeyField)