#246 — New translations do not get a proper id

State Confirmed
Version:
Area Functionality
Issue type Bug
Severity Medium
Submitted by Wichert Akkerman
Submitted on May 31, 2010
Responsible
Target release: 4.x
When you create a new translation an object is created with <original-id>-<language> as id. checkCreationFlag on it is set, so AT should give it a proper id after the first edit. This does not happen since isIDAutoGenerated returns False for this case.
Steps to reproduce:
1. Create canonical object with title 'Page'
2. Translate object to Dutch. Notice URL on translation page is 'page-nl/edit'.
3. Enter 'dummy' in the field field and save
4. Notice id is still 'page-nl', when 'dummy' is expected.
Added by Wichert Akkerman on May 31, 2010 09:25 PM
Possible (probably too simplistic) fix:

Index: I18NBaseObject.py
===================================================================
--- I18NBaseObject.py (revision 36867)
+++ I18NBaseObject.py (working copy)
@@ -535,5 +535,12 @@
                 return obj
         return None
 
+ security.declarePrivate('_isIDAutoGenerated')
+ def _isIDAutoGenerated(self, id):
+ if not self.isCanonical():
+ canonical = self.getCanonical()
+ if id.startswith("%s-" % canonical.id):
+ return True
+ return super(I18NBaseObject, self)._isIDAutoGenerated(id)
 
 InitializeClass(I18NBaseObject)
Added by Mikel Larreategi on Jul 21, 2010 06:52 AM
I can confirm the bug. This could be a regression again, the same as happened before and was fixed some time ago: http://plone.org/products/linguaplone/issues/233
Added by Hanno Schlichting on Jul 29, 2010 02:14 PM
Issue state: UnconfirmedConfirmed
Target release: None4.x
Indeed. The tricky part is to make sure it also works when "edit shortnames" is enabled and someone provides an explicit new id. That one should trump the automatically generated one.
Added by Joe Medicis on Oct 07, 2010 12:11 PM
Wichert Akkerman's fix above by itself did not work for me on LinguaPlone 4.0a4 with Plone 4 (maybe I missed something). His fix with a change in line 426 of I18NBaseObject.py seems to work fine though.
Patch follows. Cheers (and apologies if Wichert's fix works fine and the mistake was mine)
========= Patch below =========

426c426
< explicit_id = True
---
> explicit_id = self._isIDAutoGenerated(REQUEST.form.get('id'))
567a568,574
> security.declarePrivate('_isIDAutoGenerated')
> def _isIDAutoGenerated(self, id):
> if not self.isCanonical():
> canonical = self.getCanonical()
> if id.startswith("%s-" % canonical.id):
> return True
> return super(I18NBaseObject, self)._isIDAutoGenerated(id)
Added by Mikel Larreategi on Nov 03, 2010 03:34 PM
@Joe

I had to delete your last line because I was getting an error::

 2010-11-03 15:15:28 ERROR Zope.SiteErrorLog 1288797328.270.00593952772862 http://eibar.cs/es/modeloa/translate_item
Traceback (innermost last):
  Module z3c.soap.patch, line 88, in publish
  Module ZPublisher.mapply, line 77, in mapply
  Module ZPublisher.Publish, line 47, in call_object
  Module Products.CMFFormController.FSControllerPageTemplate, line 91, in __call__
  Module Products.CMFFormController.BaseControllerPageTemplate, line 28, in _call
  Module Products.CMFFormController.ControllerBase, line 231, in getNext
  Module Products.CMFFormController.Actions.TraverseTo, line 38, in __call__
  Module ZPublisher.mapply, line 77, in mapply
  Module ZPublisher.Publish, line 47, in call_object
  Module Products.CMFFormController.FSControllerPythonScript, line 105, in __call__
  Module Products.CMFFormController.Script, line 145, in __call__
  Module Products.CMFCore.FSPythonScript, line 130, in __call__
  Module Shared.DC.Scripts.Bindings, line 324, in __call__
  Module Shared.DC.Scripts.Bindings, line 361, in _bindAndExec
  Module Products.PythonScripts.PythonScript, line 344, in _exec
  Module script, line 4, in translate_edit
   - <FSControllerPythonScript at /eibar/translate_edit used for /eibar/es/modeloa>
   - Line 4
  Module Products.LinguaPlone.I18NBaseObject, line 413, in processForm
  Module Products.Archetypes.BaseObject, line 661, in processForm
  Module Products.Archetypes.BaseObject, line 744, in _renameAfterCreation
  Module Products.LinguaPlone.I18NBaseObject, line 575, in _isIDAutoGenerated
TypeError: super(type, obj): obj must be an instance or subtype of type


My diff looks like this (against the trunk):

  erral@lindari:/var/zope/instances/3199eibarkoudala/src/Products.LinguaPlone$ svn diff
Index: Products/LinguaPlone/I18NBaseObject.py
===================================================================
--- Products/LinguaPlone/I18NBaseObject.py (revision 45129)
+++ Products/LinguaPlone/I18NBaseObject.py (working copy)
@@ -423,7 +423,7 @@
 
         if REQUEST is not None:
             if 'id' in REQUEST.form and REQUEST.form.get('id'):
- explicit_id = True
+ explicit_id = self._isIDAutoGenerated(REQUEST.form.get('id'))
 
         if values is not None:
             if 'id' in values and values.get('id'):
@@ -565,5 +565,14 @@
                 return obj
         return None
 
+ security.declarePrivate('_isIDAutoGenerated')
+ def _isIDAutoGenerated(self, id):
+ if not self.isCanonical():
+ canonical = self.getCanonical()
+ if id.startswith("%s-" % canonical.id):
+ return True
 
+ ##return super(I18NBaseObject, self)._isIDAutoGenerated(id)
+
+
 InitializeClass(I18NBaseObject)
Added by Peter Holzer on Apr 25, 2011 02:35 PM
this bug is really annoying
what speaks against fixing this and reopen an issue for the edit-shortnames-problem?

the fix works for me
peter

No responses can be added.