# HG changeset patch # User Sylvain Thénault # Date 1253296138 -7200 # Node ID 44efba78afac088e07e8c4050fb5628af2f8ba09 # Parent e3089ceee1eaac4092de571a72d383ef3c9ecaf2 fix/enhance i18n context usage for inlined forms diff -r e3089ceee1ea -r 44efba78afac devtools/devctl.py --- a/devtools/devctl.py Fri Sep 18 19:47:07 2009 +0200 +++ b/devtools/devctl.py Fri Sep 18 19:48:58 2009 +0200 @@ -160,7 +160,9 @@ add_msg(w, 'add a %s' % tschema, 'inlined:%s.%s.%s' % (etype, rschema, role)) add_msg(w, 'remove this %s' % tschema, - 'inlined:%s:%s:%s' % (etype, rschema, role)) + 'inlined:%s.%s.%s' % (etype, rschema, role)) + add_msg(w, 'This %s' % tschema, + 'inlined:%s.%s.%s' % (etype, rschema, role)) if appearsin_addmenu.etype_get(eschema, rschema, role, tschema) and \ (libconfig is None or not libappearsin_addmenu.etype_get(eschema, rschema, role, tschema)): diff -r e3089ceee1ea -r 44efba78afac web/data/cubicweb.edition.js --- a/web/data/cubicweb.edition.js Fri Sep 18 19:47:07 2009 +0200 +++ b/web/data/cubicweb.edition.js Fri Sep 18 19:48:58 2009 +0200 @@ -243,9 +243,9 @@ * @param ttype : the target (inlined) entity type * @param rtype : the relation type between both entities */ -function addInlineCreationForm(peid, ttype, rtype, role, insertBefore) { +function addInlineCreationForm(peid, ttype, rtype, role, i18nctx, insertBefore) { insertBefore = insertBefore || getNode('add' + rtype + ':' + peid + 'link').parentNode; - var d = asyncRemoteExec('inline_creation_form', peid, ttype, rtype, role); + var d = asyncRemoteExec('inline_creation_form', peid, ttype, rtype, role, i18nctx); d.addCallback(function (response) { var dom = getDomFromResponse(response); preprocessAjaxLoad(null, dom); diff -r e3089ceee1ea -r 44efba78afac web/views/basecontrollers.py --- a/web/views/basecontrollers.py Fri Sep 18 19:47:07 2009 +0200 +++ b/web/views/basecontrollers.py Fri Sep 18 19:48:58 2009 +0200 @@ -376,12 +376,12 @@ @check_pageid @xhtmlize - def js_inline_creation_form(self, peid, ttype, rtype, role): + def js_inline_creation_form(self, peid, ttype, rtype, role, i18nctx): view = self.vreg['views'].select('inline-creation', self.req, etype=ttype, peid=peid, rtype=rtype, role=role) return self._call_view(view, etype=ttype, peid=peid, - rtype=rtype, role=role) + rtype=rtype, role=role, i18nctx=i18nctx) @jsonize def js_validate_form(self, action, names, values): diff -r e3089ceee1ea -r 44efba78afac web/views/editforms.py --- a/web/views/editforms.py Fri Sep 18 19:47:07 2009 +0200 +++ b/web/views/editforms.py Fri Sep 18 19:48:58 2009 +0200 @@ -454,7 +454,7 @@ for i in xrange(len(rset)): self.wview(self.id, rset, row=i, **kwargs) - def cell_call(self, row, col, peid, rtype, role='subject', **kwargs): + def cell_call(self, row, col, peid, rtype, role, i18nctx, **kwargs): """ :param peid: the parent entity's eid hosting the inline form :param rtype: the relation bridging `etype` and `peid` @@ -463,23 +463,25 @@ entity = self.entity(row, col) divonclick = "restoreInlinedEntity('%s', '%s', '%s')" % (peid, rtype, entity.eid) - self.render_form(entity, peid, rtype, role, divonclick=divonclick) + self.render_form(entity, peid, rtype, role, i18nctx, + divonclick=divonclick) - def render_form(self, entity, peid, rtype, role, **kwargs): + def render_form(self, entity, peid, rtype, role, i18nctx, **kwargs): """fetch and render the form""" form = self.vreg['forms'].select('edition', self.req, entity=entity, form_renderer_id='inline', mainform=False, copy_nav_params=False) self.add_hiddens(form, entity, peid, rtype, role) divid = '%s-%s-%s' % (peid, rtype, entity.eid) - title = self.schema.rschema(rtype).display_name(self.req, role) - removejs = self.removejs % (peid, rtype,entity.eid) + title = self.req.pgettext(i18nctx, 'This %s' % entity.e_schema) + removejs = self.removejs % (peid, rtype, entity.eid) countkey = '%s_count' % rtype try: self.req.data[countkey] += 1 except: self.req.data[countkey] = 1 self.w(form.form_render(divid=divid, title=title, removejs=removejs, + i18nctx=i18nctx, counter=self.req.data[countkey], **kwargs)) def add_hiddens(self, form, entity, peid, rtype, role): @@ -511,7 +513,7 @@ & specified_etype_implements('Any')) removejs = "removeInlineForm('%s', '%s', '%s')" - def call(self, etype, peid, rtype, role='subject', **kwargs): + def call(self, etype, peid, rtype, role, i18nctx, **kwargs): """ :param etype: the entity type being created in the inline form :param peid: the parent entity's eid hosting the inline form @@ -525,4 +527,4 @@ return self.initialize_varmaker() entity.eid = self.varmaker.next() - self.render_form(entity, peid, rtype, role) + self.render_form(entity, peid, rtype, role, i18nctx) diff -r e3089ceee1ea -r 44efba78afac web/views/formrenderers.py --- a/web/views/formrenderers.py Fri Sep 18 19:47:07 2009 +0200 +++ b/web/views/formrenderers.py Fri Sep 18 19:48:58 2009 +0200 @@ -489,6 +489,7 @@ def inline_relation_form(self, w, form, rschema, targettype, role): entity = form.edited_entity __ = self.req.pgettext + i18nctx = 'inlined:%s.%s.%s' % (entity.e_schema, rschema, role) w(u'
' % rschema) existant = entity.has_eid() and entity.related(rschema) if existant: @@ -504,7 +505,7 @@ if form.should_display_inline_creation_form(rschema, existant, card): w(form.view('inline-creation', None, etype=targettype, peid=entity.eid, ptype=entity.e_schema, - rtype=rschema, role=role)) + rtype=rschema, role=role, i18nctx=i18nctx)) existant = True # we can create more than one related entity, we thus display a link # to add new related entities @@ -512,13 +513,12 @@ divid = "addNew%s%s%s:%s" % (targettype, rschema, role, entity.eid) w(u'
' % divid) - js = "addInlineCreationForm('%s', '%s', '%s', '%s')" % ( - entity.eid, targettype, rschema, role) - if card in '1?': + js = "addInlineCreationForm('%s', '%s', '%s', '%s', '%s')" % ( + entity.eid, targettype, rschema, role, i18nctx) + if form.should_hide_add_new_relation_link(rschema, card): js = "toggleVisibility('%s'); %s" % (divid, js) - ctx = 'inlined:%s.%s.%s' % (entity.e_schema, rschema, role) w(u'+ %s.' - % (rschema, entity.eid, js, __(ctx, 'add a %s' % targettype))) + % (rschema, entity.eid, js, __(i18nctx, 'add a %s' % targettype))) w(u'
') w(u'
 
') w(u'
') @@ -542,7 +542,9 @@ w(u'
%s
' % ( values['divid'], self.req._('click on the box to cancel the deletion'))) w(u'
') - values['removemsg'] = self.req.__('remove this %s' % form.edited_entity.e_schema) + eschema = form.edited_entity.e_schema + ctx = values.pop('i18nctx') + values['removemsg'] = self.req.pgettext(ctx, 'remove this %s' % eschema) w(u'
%(title)s ' '#%(counter)s ' '[%(removemsg)s]
'