[Zope3-checkins] SVN: Zope3/trunk/src/zope/app/i18nfile/ Changes
for I18nFile, I18nImage:
Dmitry Vasiliev
dima at hlabs.spb.ru
Tue Jun 8 06:55:59 EDT 2004
Log message for revision 25286:
Changes for I18nFile, I18nImage:
- Fixed bug with outdated getContentType() method
- Interface definitions updated
-=-
Modified: Zope3/trunk/src/zope/app/i18nfile/browser/configure.zcml
===================================================================
--- Zope3/trunk/src/zope/app/i18nfile/browser/configure.zcml 2004-06-07 20:30:41 UTC (rev 25285)
+++ Zope3/trunk/src/zope/app/i18nfile/browser/configure.zcml 2004-06-08 10:55:59 UTC (rev 25286)
@@ -15,7 +15,7 @@
<browser:pages
for="zope.app.i18nfile.interfaces.II18nFile"
- permission="zope.View"
+ permission="zope.ManageContent"
class=".i18nfile.I18nFileEdit">
<browser:page name="editForm.html" template="file_edit.pt" />
Modified: Zope3/trunk/src/zope/app/i18nfile/browser/file_edit.pt
===================================================================
--- Zope3/trunk/src/zope/app/i18nfile/browser/file_edit.pt 2004-06-07 20:30:41 UTC (rev 25285)
+++ Zope3/trunk/src/zope/app/i18nfile/browser/file_edit.pt 2004-06-08 10:55:59 UTC (rev 25286)
@@ -1,4 +1,4 @@
-<html metal:use-macro="views/standard_macros/page">
+<html metal:use-macro="views/standard_macros/view">
<head>
<style metal:fill-slot="headers" type="text/css">
<!--
@@ -31,7 +31,7 @@
<div class="label" i18n:translate="">Content Type</div>
<div class="field">
<input name="contentType" type="text" size="20"
- tal:attributes="value context/getContentType" />
+ tal:attributes="value context/contentType" />
</div>
</div>
Modified: Zope3/trunk/src/zope/app/i18nfile/browser/i18nfile.py
===================================================================
--- Zope3/trunk/src/zope/app/i18nfile/browser/i18nfile.py 2004-06-07 20:30:41 UTC (rev 25285)
+++ Zope3/trunk/src/zope/app/i18nfile/browser/i18nfile.py 2004-06-08 10:55:59 UTC (rev 25286)
@@ -16,6 +16,7 @@
$Id$
"""
from zope.i18n.negotiator import negotiator
+from zope.app.i18n import ZopeMessageIDFactory as _
__metaclass__ = type
@@ -31,7 +32,7 @@
language = negotiator.getLanguage(langs, request)
request.response.setHeader('Content-Type',
- self.context.getContentType())
+ self.context.contentType)
request.response.setHeader('Content-Length',
self.context.getSize(language))
@@ -41,8 +42,8 @@
class I18nFileEdit:
name = 'editForm'
- title = 'Edit Form'
- description = ('This edit form allows you to make changes to the ' +
+ title = _('Edit Form')
+ description = _('This edit form allows you to make changes to the ' +
'properties of this file.')
def action(self, contentType, data, language, defaultLanguage,
Modified: Zope3/trunk/src/zope/app/i18nfile/browser/i18nimage.py
===================================================================
--- Zope3/trunk/src/zope/app/i18nfile/browser/i18nimage.py 2004-06-07 20:30:41 UTC (rev 25285)
+++ Zope3/trunk/src/zope/app/i18nfile/browser/i18nimage.py 2004-06-08 10:55:59 UTC (rev 25286)
@@ -18,10 +18,10 @@
from zope.i18n.negotiator import negotiator
from zope.app.i18n import ZopeMessageIDFactory as _
from zope.app.file.browser.image import ImageData
+from zope.app.size import byteDisplay
-__metaclass__ = type
-class I18nImageEdit:
+class I18nImageEdit(object):
name = 'editForm'
title = _('Edit Form')
@@ -31,7 +31,13 @@
def getImageSize(self, language=None):
# XXX Change to ISizeable adapter
size = self.context.getImageSize(language)
- return "%d x %d" % (size[0], size[1])
+ sx, sy = size
+ if sx < 0:
+ sx = '?'
+ if sy < 0:
+ sy = '?'
+ return "%s x %s pixels, %s" % (sx, sy,
+ byteDisplay(self.context.getSize()))
def action(self, contentType, data, language, defaultLanguage,
selectLanguage=None, removeLanguage=None,
@@ -48,7 +54,7 @@
self.context.setData(data, language)
self.context.contentType = contentType
return self.request.response.redirect(self.request.URL[-1] +
- "/editForm.html?language=%s" % language) # XXX url_quote
+ "/upload.html?language=%s" % language) # XXX url_quote
class I18nImageData(ImageData):
@@ -60,8 +66,7 @@
langs = self.context.getAvailableLanguages()
language = negotiator.getLanguage(langs, self.request)
- self.request.response.setHeader('content-type',
- image.getContentType())
+ self.request.response.setHeader('content-type', image.contentType)
# XXX: no content-length? See ImageData.__call__
return image.getData(language)
Modified: Zope3/trunk/src/zope/app/i18nfile/browser/image_edit.pt
===================================================================
--- Zope3/trunk/src/zope/app/i18nfile/browser/image_edit.pt 2004-06-07 20:30:41 UTC (rev 25285)
+++ Zope3/trunk/src/zope/app/i18nfile/browser/image_edit.pt 2004-06-08 10:55:59 UTC (rev 25286)
@@ -1,4 +1,4 @@
-<html metal:use-macro="views/standard_macros/page">
+<html metal:use-macro="views/standard_macros/view">
<head>
<style metal:fill-slot="headers" type="text/css">
<!--
@@ -32,7 +32,7 @@
<div class="label" i18n:translate="">Content Type</div>
<div class="field">
<input name="contentType" type="text" size="20"
- tal:attributes="value context/getContentType" />
+ tal:attributes="value context/contentType" />
</div>
</div>
@@ -85,16 +85,9 @@
<div class="label" i18n:translate="">Dimensions</div>
<div class="field"
tal:content="python:view.getImageSize(request.get('language'))">
- 40 x 40
+ 40 x 40 pixels, 10 kB
</div>
</div>
- <div class="row">
- <div class="label" i18n:translate="">Dimensions</div>
- <div class="field"
- tal:content="python:view.getSize(request.get('language'))">
- 40 kB
- </div>
- </div>
<div class="row">
<div class="controls">
Modified: Zope3/trunk/src/zope/app/i18nfile/configure.zcml
===================================================================
--- Zope3/trunk/src/zope/app/i18nfile/configure.zcml 2004-06-07 20:30:41 UTC (rev 25285)
+++ Zope3/trunk/src/zope/app/i18nfile/configure.zcml 2004-06-08 10:55:59 UTC (rev 25286)
@@ -34,11 +34,11 @@
/>
<require
permission="zope.View"
- attributes="getDefaultLanguage getAvailableLanguages"
+ attributes="getDefaultLanguage getAvailableLanguages getData"
/>
<require
permission="zope.ManageContent"
- attributes="setDefaultLanguage removeLanguage"
+ attributes="setDefaultLanguage removeLanguage setData"
/>
<implements
interface="zope.app.annotation.interfaces.IAttributeAnnotatable"
@@ -62,11 +62,11 @@
/>
<require
permission="zope.View"
- attributes="getDefaultLanguage getAvailableLanguages"
+ attributes="getDefaultLanguage getAvailableLanguages getData"
/>
<require
permission="zope.ManageContent"
- attributes="setDefaultLanguage removeLanguage"
+ attributes="setDefaultLanguage removeLanguage setData"
/>
<implements
interface="zope.app.annotation.interfaces.IAttributeAnnotatable"
Modified: Zope3/trunk/src/zope/app/i18nfile/i18nfile.py
===================================================================
--- Zope3/trunk/src/zope/app/i18nfile/i18nfile.py 2004-06-07 20:30:41 UTC (rev 25285)
+++ Zope3/trunk/src/zope/app/i18nfile/i18nfile.py 2004-06-08 10:55:59 UTC (rev 25286)
@@ -64,38 +64,39 @@
return file
def getData(self, language=None):
+ """See interface II18nFile"""
return self._get(language).data
def setData(self, data, language=None):
+ """See interface II18nFile"""
self._get_or_add(language).data = data
# See IFile.
data = property(getData, setData)
def getSize(self, language=None):
- '''See interface IFile'''
+ """See interface II18nFile"""
return self._get(language).getSize()
def getDefaultLanguage(self):
- 'See II18nAware'
+ """See II18nAware"""
return self.defaultLanguage
def setDefaultLanguage(self, language):
- 'See II18nAware'
- if not self._data.has_key(language):
- raise ValueError, \
- 'cannot set nonexistent language (%s) as default' % language
+ """See II18nAware"""
+ if language not in self._data:
+ raise ValueError(
+ 'cannot set nonexistent language (%s) as default' % language)
self.defaultLanguage = language
def getAvailableLanguages(self):
- 'See II18nAware'
+ """See II18nAware"""
return self._data.keys()
def removeLanguage(self, language):
- '''See interface II18nFile'''
-
+ """See interface II18nFile"""
if language == self.defaultLanguage:
- raise ValueError, 'cannot remove default language (%s)' % language
- if self._data.has_key(language):
+ raise ValueError('cannot remove default language (%s)' % language)
+ if language in self._data:
del self._data[language]
self._p_changed = True
Modified: Zope3/trunk/src/zope/app/i18nfile/i18nimage.py
===================================================================
--- Zope3/trunk/src/zope/app/i18nfile/i18nimage.py 2004-06-07 20:30:41 UTC (rev 25285)
+++ Zope3/trunk/src/zope/app/i18nfile/i18nimage.py 2004-06-08 10:55:59 UTC (rev 25286)
@@ -32,7 +32,7 @@
return Image(data)
def setData(self, data, language=None):
- '''See interface IFile'''
+ '''See interface II18nFile'''
super(I18nImage, self).setData(data, language)
if language is None or language == self.getDefaultLanguage():
@@ -44,5 +44,5 @@
self.contentType = contentType
def getImageSize(self, language=None):
- '''See interface IImage'''
+ '''See interface II18nImage'''
return self._get(language).getImageSize()
Modified: Zope3/trunk/src/zope/app/i18nfile/interfaces.py
===================================================================
--- Zope3/trunk/src/zope/app/i18nfile/interfaces.py 2004-06-07 20:30:41 UTC (rev 25285)
+++ Zope3/trunk/src/zope/app/i18nfile/interfaces.py 2004-06-08 10:55:59 UTC (rev 25286)
@@ -20,9 +20,29 @@
class II18nFile(IFile, II18nAware):
"""I18n aware file interface."""
+ def getData(language=None):
+ """Return the object data for a given language
+ or for the default language.
+ """
+
+ def setData(data, language=None):
+ """Set the object data for a given language
+ or for the default language.
+ """
+
+ def getSize(language=None):
+ """Return the byte-size of the data of the object for a given language
+ or for the default language.
+ """
+
def removeLanguage(language):
"""Remove translated content for a given language.
"""
class II18nImage(II18nFile, IImage):
"""I18n aware image interface."""
+
+ def getImageSize(language=None):
+ """Return a tuple (x, y) that describes the dimensions of the object
+ for a given language or for the default language.
+ """
More information about the Zope3-Checkins
mailing list