[Zope3-checkins] SVN: Zope3/trunk/ Fixed issue 400: i18n image
broken in trunk
Dmitry Vasiliev
dima at hlabs.spb.ru
Thu Jun 2 06:06:17 EDT 2005
Log message for revision 30597:
Fixed issue 400: i18n image broken in trunk
Changed:
U Zope3/trunk/doc/CHANGES.txt
U Zope3/trunk/doc/TODO.txt
U Zope3/trunk/src/zope/app/i18nfile/browser/file_edit.pt
A Zope3/trunk/src/zope/app/i18nfile/browser/ftests.py
A Zope3/trunk/src/zope/app/i18nfile/browser/i18nfile.txt
U Zope3/trunk/src/zope/app/i18nfile/browser/i18nimage.py
A Zope3/trunk/src/zope/app/i18nfile/browser/i18nimage.txt
U Zope3/trunk/src/zope/app/i18nfile/browser/image_edit.pt
U Zope3/trunk/src/zope/app/i18nfile/configure.zcml
U Zope3/trunk/src/zope/app/i18nfile/i18nfile.py
U Zope3/trunk/src/zope/app/i18nfile/i18nimage.py
U Zope3/trunk/src/zope/app/i18nfile/interfaces.py
-=-
Modified: Zope3/trunk/doc/CHANGES.txt
===================================================================
--- Zope3/trunk/doc/CHANGES.txt 2005-06-02 03:12:38 UTC (rev 30596)
+++ Zope3/trunk/doc/CHANGES.txt 2005-06-02 10:06:17 UTC (rev 30597)
@@ -599,6 +599,8 @@
Bug Fixes
+ - Fixed issue #400: i18n image broken in trunk
+
- Fix #392 : adapter registry subscribers method can return None
when it shouldn't
@@ -609,7 +611,7 @@
authentication too.
- Fix #313 : importchecker.py ignores assignment to module attributes
-
+
- Fix #327 : File type change clears object content
- Disabled automatic translation of message id's in TAL.
Modified: Zope3/trunk/doc/TODO.txt
===================================================================
--- Zope3/trunk/doc/TODO.txt 2005-06-02 03:12:38 UTC (rev 30596)
+++ Zope3/trunk/doc/TODO.txt 2005-06-02 10:06:17 UTC (rev 30597)
@@ -53,8 +53,6 @@
* 397: DisplayView shouldn't display fields with private suffix
- * 400: i18n image broken in trunk
-
Bugs starting with * represent bugs that must be fixed for the 3.0.x branch as
well.
Modified: Zope3/trunk/src/zope/app/i18nfile/browser/file_edit.pt
===================================================================
--- Zope3/trunk/src/zope/app/i18nfile/browser/file_edit.pt 2005-06-02 03:12:38 UTC (rev 30596)
+++ Zope3/trunk/src/zope/app/i18nfile/browser/file_edit.pt 2005-06-02 10:06:17 UTC (rev 30597)
@@ -1,4 +1,5 @@
-<html metal:use-macro="context/@@standard_macros/view">
+<html metal:use-macro="context/@@standard_macros/view"
+ i18n:domain="zope">
<head>
<style metal:fill-slot="headers" type="text/css">
<!--
@@ -21,7 +22,7 @@
Message will go here.
</p>
- <p tal:content="view/description">
+ <p tal:content="view/description" i18n:translate="">
Description of the Form.
</p>
@@ -34,7 +35,7 @@
tal:attributes="value context/contentType" />
</div>
</div>
-
+
<div class="row">
<div class="label" i18n:translate="">Default Language</div>
<div class="field">
@@ -94,5 +95,3 @@
</div>
</body>
</html>
-
-
Added: Zope3/trunk/src/zope/app/i18nfile/browser/ftests.py
===================================================================
--- Zope3/trunk/src/zope/app/i18nfile/browser/ftests.py 2005-06-02 03:12:38 UTC (rev 30596)
+++ Zope3/trunk/src/zope/app/i18nfile/browser/ftests.py 2005-06-02 10:06:17 UTC (rev 30597)
@@ -0,0 +1,28 @@
+##############################################################################
+#
+# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""Functional tests for i18n versions of several content objects.
+
+$Id$
+"""
+__docformat__ = 'restructuredtext'
+
+import unittest
+from zope.app.testing.functional import FunctionalDocFileSuite
+
+
+def test_suite():
+ suite = unittest.TestSuite()
+ suite.addTest(FunctionalDocFileSuite("i18nfile.txt"))
+ suite.addTest(FunctionalDocFileSuite("i18nimage.txt"))
+ return suite
Property changes on: Zope3/trunk/src/zope/app/i18nfile/browser/ftests.py
___________________________________________________________________
Name: svn:keywords
+ Id
Added: Zope3/trunk/src/zope/app/i18nfile/browser/i18nfile.txt
===================================================================
--- Zope3/trunk/src/zope/app/i18nfile/browser/i18nfile.txt 2005-06-02 03:12:38 UTC (rev 30596)
+++ Zope3/trunk/src/zope/app/i18nfile/browser/i18nfile.txt 2005-06-02 10:06:17 UTC (rev 30597)
@@ -0,0 +1,98 @@
+==============
+I18nFile tests
+==============
+
+First, let's create an I18nFile instance:
+
+ >>> print http(r"""
+ ... POST /@@contents.html HTTP/1.1
+ ... Authorization: Basic mgr:mgrpw
+ ... """, form={"type_name": "BrowserAdd__zope.app.i18nfile.i18nfile.I18nFile",
+ ... "new_value": "i18nfile"})
+ HTTP/1.1 303 See Other
+ ...
+
+Then add some sample data for default (en) language:
+
+ >>> print http(r"""
+ ... POST /i18nfile/edit.html HTTP/1.1
+ ... Authorization: Basic mgr:mgrpw
+ ... """, form={"contentType": "text/plain",
+ ... "defaultLanguage": "en",
+ ... "language": "en",
+ ... "newLanguage": "",
+ ... "data": "English",
+ ... "edit": "Save"})
+ HTTP/1.1 303 See Other
+ ...
+
+Ok, now we can view the data in the edit form:
+
+ >>> print http(r"""
+ ... GET /i18nfile/editForm.html?language=en HTTP/1.1
+ ... Authorization: Basic mgr:mgrpw
+ ... """)
+ HTTP/1.1 200 Ok
+ ...
+ <textarea ...>English</textarea>
+ ...
+
+and as file content:
+
+ >>> print http(r"""
+ ... GET /i18nfile/index.html HTTP/1.1
+ ... Authorization: Basic mgr:mgrpw
+ ... """)
+ HTTP/1.1 200 Ok
+ ...
+ English
+
+Let's add new (russian) language:
+
+ >>> print http(r"""
+ ... POST /i18nfile/edit.html HTTP/1.1
+ ... Authorization: Basic mgr:mgrpw
+ ... """, form={"contentType": "text/plain",
+ ... "defaultLanguage": "en",
+ ... "language": "en",
+ ... "addLanguage": "Add new language",
+ ... "newLanguage": "ru",
+ ... "data": "English"})
+ HTTP/1.1 303 See Other
+ ...
+
+and add some sample data for russian (ru) language:
+
+ >>> print http(r"""
+ ... POST /i18nfile/edit.html HTTP/1.1
+ ... Authorization: Basic mgr:mgrpw
+ ... """, form={"contentType": "text/plain",
+ ... "defaultLanguage": "en",
+ ... "language": "ru",
+ ... "newLanguage": "",
+ ... "data": "Russian",
+ ... "edit": "Save"})
+ HTTP/1.1 303 See Other
+ ...
+
+Then we can view sample data for russain language in the edit form:
+
+ >>> print http(r"""
+ ... GET /i18nfile/editForm.html?language=ru HTTP/1.1
+ ... Authorization: Basic mgr:mgrpw
+ ... """)
+ HTTP/1.1 200 Ok
+ ...
+ <textarea ...>Russian</textarea>
+ ...
+
+and if our preferred language is russian as file content:
+
+ >>> print http(r"""
+ ... GET /i18nfile/index.html HTTP/1.1
+ ... Authorization: Basic mgr:mgrpw
+ ... Accept-Language: ru,en
+ ... """)
+ HTTP/1.1 200 Ok
+ ...
+ Russian
Modified: Zope3/trunk/src/zope/app/i18nfile/browser/i18nimage.py
===================================================================
--- Zope3/trunk/src/zope/app/i18nfile/browser/i18nimage.py 2005-06-02 03:12:38 UTC (rev 30596)
+++ Zope3/trunk/src/zope/app/i18nfile/browser/i18nimage.py 2005-06-02 10:06:17 UTC (rev 30597)
@@ -23,17 +23,22 @@
from zope.app.i18n import ZopeMessageIDFactory as _
from zope.app.file.browser.image import ImageData
-from zope.app.size import byteDisplay
+from zope.app.size import ISized
+
class I18nImageEdit(object):
name = 'editForm'
title = _('Edit Form')
- description = _('This edit form allows you to make changes to the ' +
+ description = _('This edit form allows you to make changes to the '
'properties of this image.')
- def size(self, language=None):
- sized = ISized(self.context._get(language))
+ def size(self):
+ if self.request is not None:
+ language = self.request.get("language")
+ else:
+ language = None
+ sized = ISized(self.context.getObject(language))
return sized.sizeForDisplay()
def action(self, contentType, data, language, defaultLanguage,
@@ -53,7 +58,6 @@
return self.request.response.redirect(self.request.URL[-1] +
"/upload.html?language=%s" % quote(language, ''))
-
class I18nImageData(ImageData):
def __call__(self):
Added: Zope3/trunk/src/zope/app/i18nfile/browser/i18nimage.txt
===================================================================
--- Zope3/trunk/src/zope/app/i18nfile/browser/i18nimage.txt 2005-06-02 03:12:38 UTC (rev 30596)
+++ Zope3/trunk/src/zope/app/i18nfile/browser/i18nimage.txt 2005-06-02 10:06:17 UTC (rev 30597)
@@ -0,0 +1,104 @@
+===============
+I18nImage tests
+===============
+
+First, let's create an I18nImage instance:
+
+ >>> print http(r"""
+ ... POST /@@contents.html HTTP/1.1
+ ... Authorization: Basic mgr:mgrpw
+ ... """, form={
+ ... "type_name": "BrowserAdd__zope.app.i18nfile.i18nimage.I18nImage",
+ ... "new_value": "i18nimage"})
+ HTTP/1.1 303 See Other
+ ...
+
+Then add some sample image data for default (en) language:
+
+ >>> print http(r"""
+ ... POST /i18nimage/uploadAction.html HTTP/1.1
+ ... Authorization: Basic mgr:mgrpw
+ ... """, form={"contentType": "image/gif",
+ ... "defaultLanguage": "en",
+ ... "language": "en",
+ ... "newLanguage": "",
+ ... "data": 'GIF89aENEN',
+ ... "edit": "Save"})
+ HTTP/1.1 303 See Other
+ ...
+
+Ok, now we can view the image size in the edit form:
+
+ >>> print http(r"""
+ ... GET /i18nimage/upload.html?language=en HTTP/1.1
+ ... Authorization: Basic mgr:mgrpw
+ ... """)
+ HTTP/1.1 200 Ok
+ ...
+ ...>1 KB 20037x20037</...
+ ...
+
+and the image data as file content:
+
+ >>> print http(r"""
+ ... GET /i18nimage/ HTTP/1.1
+ ... Authorization: Basic mgr:mgrpw
+ ... """)
+ HTTP/1.1 200 Ok
+ Content-Length: 10
+ Content-Type: image/gif
+ <BLANKLINE>
+ GIF89aENEN
+
+Let's add new (russian) language:
+
+ >>> print http(r"""
+ ... POST /i18nimage/uploadAction.html HTTP/1.1
+ ... Authorization: Basic mgr:mgrpw
+ ... """, form={"contentType": "image/gif",
+ ... "defaultLanguage": "en",
+ ... "language": "en",
+ ... "addLanguage": "Add new language",
+ ... "newLanguage": "ru",
+ ... "data": ""})
+ HTTP/1.1 303 See Other
+ ...
+
+and add some sample image data for russian (ru) language:
+
+ >>> print http(r"""
+ ... POST /i18nimage/uploadAction.html HTTP/1.1
+ ... Authorization: Basic mgr:mgrpw
+ ... """, form={"contentType": "image/gif",
+ ... "defaultLanguage": "en",
+ ... "language": "ru",
+ ... "newLanguage": "",
+ ... "data": "GIF89aRURU",
+ ... "edit": "Save"})
+ HTTP/1.1 303 See Other
+ ...
+
+Then we can view the size of sample image for russain language in
+the edit form:
+
+ >>> print http(r"""
+ ... GET /i18nimage/upload.html?language=ru HTTP/1.1
+ ... Authorization: Basic mgr:mgrpw
+ ... """)
+ HTTP/1.1 200 Ok
+ ...
+ ...>1 KB 21842x21842</...
+ ...
+
+and if our preferred language is russian we can view the image as file content:
+
+ >>> print http(r"""
+ ... GET /i18nimage/ HTTP/1.1
+ ... Authorization: Basic mgr:mgrpw
+ ... Accept-Language: ru,en
+ ... """)
+ HTTP/1.1 200 Ok
+ Content-Length: 10
+ Content-Type: image/gif
+ <BLANKLINE>
+ GIF89aRURU
Modified: Zope3/trunk/src/zope/app/i18nfile/browser/image_edit.pt
===================================================================
--- Zope3/trunk/src/zope/app/i18nfile/browser/image_edit.pt 2005-06-02 03:12:38 UTC (rev 30596)
+++ Zope3/trunk/src/zope/app/i18nfile/browser/image_edit.pt 2005-06-02 10:06:17 UTC (rev 30597)
@@ -1,4 +1,5 @@
-<html metal:use-macro="context/@@standard_macros/view">
+<html metal:use-macro="context/@@standard_macros/view"
+ i18n:domain="zope">
<head>
<style metal:fill-slot="headers" type="text/css">
<!--
@@ -21,7 +22,7 @@
Message will go here.
</p>
- <p tal:content="view/description">
+ <p tal:content="view/description" i18n:translate="">
Description of the Form.
</p>
@@ -35,7 +36,7 @@
tal:attributes="value context/contentType" />
</div>
</div>
-
+
<div class="row">
<div class="label" i18n:translate="">Default Language</div>
<div class="field">
@@ -83,8 +84,7 @@
</div>
<div class="row">
<div class="label" i18n:translate="">Dimensions</div>
- <div class="field"
- tal:content="python:view.size(request.get('language'))">
+ <div class="field" tal:content="view/size" i18n:translate="">
40 x 40 pixels, 10 kB
</div>
</div>
Modified: Zope3/trunk/src/zope/app/i18nfile/configure.zcml
===================================================================
--- Zope3/trunk/src/zope/app/i18nfile/configure.zcml 2005-06-02 03:12:38 UTC (rev 30596)
+++ Zope3/trunk/src/zope/app/i18nfile/configure.zcml 2005-06-02 10:06:17 UTC (rev 30597)
@@ -34,7 +34,7 @@
/>
<require
permission="zope.View"
- attributes="getDefaultLanguage getAvailableLanguages getData"
+ attributes="getDefaultLanguage getAvailableLanguages getData getObject"
/>
<require
permission="zope.ManageContent"
@@ -54,7 +54,7 @@
<require
permission="zope.View"
interface="zope.app.file.interfaces.IFile"
- attributes="getImageSize"
+ attributes="getImageSize getObject"
/>
<require
permission="zope.ManageContent"
Modified: Zope3/trunk/src/zope/app/i18nfile/i18nfile.py
===================================================================
--- Zope3/trunk/src/zope/app/i18nfile/i18nfile.py 2005-06-02 03:12:38 UTC (rev 30596)
+++ Zope3/trunk/src/zope/app/i18nfile/i18nfile.py 2005-06-02 10:06:17 UTC (rev 30597)
@@ -43,11 +43,8 @@
"""
return File(data)
- def _get(self, language):
- """Helper function -- return a subobject for a given language,
- and if it does not exist, return a subobject for the default
- language.
- """
+ def getObject(self, language=None):
+ """See interface `II18nFile`"""
file = self._data.get(language)
if not file:
file = self._data[self.defaultLanguage]
@@ -67,7 +64,7 @@
def getData(self, language=None):
"""See interface `II18nFile`"""
- return self._get(language).data
+ return self.getObject(language).data
def setData(self, data, language=None):
"""See interface `II18nFile`"""
@@ -78,7 +75,7 @@
def getSize(self, language=None):
"""See interface `II18nFile`"""
- return self._get(language).getSize()
+ return self.getObject(language).getSize()
def getDefaultLanguage(self):
"""See `II18nAware`"""
Modified: Zope3/trunk/src/zope/app/i18nfile/i18nimage.py
===================================================================
--- Zope3/trunk/src/zope/app/i18nfile/i18nimage.py 2005-06-02 03:12:38 UTC (rev 30596)
+++ Zope3/trunk/src/zope/app/i18nfile/i18nimage.py 2005-06-02 10:06:17 UTC (rev 30597)
@@ -23,6 +23,7 @@
from interfaces import II18nImage
+
class I18nImage(I18nFile):
"""An internationalized Image object. Note that images of all
languages share the same content type.
@@ -47,4 +48,4 @@
def getImageSize(self, language=None):
'''See interface `II18nImage`'''
- return self._get(language).getImageSize()
+ return self.getObject(language).getImageSize()
Modified: Zope3/trunk/src/zope/app/i18nfile/interfaces.py
===================================================================
--- Zope3/trunk/src/zope/app/i18nfile/interfaces.py 2005-06-02 03:12:38 UTC (rev 30596)
+++ Zope3/trunk/src/zope/app/i18nfile/interfaces.py 2005-06-02 10:06:17 UTC (rev 30597)
@@ -23,6 +23,12 @@
class II18nFile(IFile, II18nAware):
"""I18n aware file interface."""
+ def getObject(language=None):
+ """Return a subobject for a given language,
+ and if it does not exist, return a subobject for the default
+ language.
+ """
+
def getData(language=None):
"""Return the object data for a given language
or for the default language.
More information about the Zope3-Checkins
mailing list