[Zope3-checkins] SVN: Zope3/trunk/src/zope/app/file/browser/file.py
Add ObjectModifiedEvent and change the default charset to
utf-8 in FileEditForm.
Yusei Tahara
yusei at domen.cx
Mon Jan 29 11:42:05 EST 2007
Log message for revision 72250:
Add ObjectModifiedEvent and change the default charset to utf-8 in FileEditForm.
Changed:
U Zope3/trunk/src/zope/app/file/browser/file.py
-=-
Modified: Zope3/trunk/src/zope/app/file/browser/file.py
===================================================================
--- Zope3/trunk/src/zope/app/file/browser/file.py 2007-01-29 10:59:41 UTC (rev 72249)
+++ Zope3/trunk/src/zope/app/file/browser/file.py 2007-01-29 16:42:04 UTC (rev 72250)
@@ -337,8 +337,15 @@
>>> view.getData()
{'data': u'', 'contentType': ''}
+ We install an event logger so we can see the events generated.
+
+ >>> def eventLog(event):
+ ... print event
+ >>> zope.event.subscribers.append(eventLog)
+
>>> view.setData({'contentType': 'text/plain; charset=ISO-8859-13',
- ... 'data': u'text \u0105'})
+ ... 'data': u'text \u0105'}) # doctest:+ELLIPSIS
+ <zope.app.event.objectevent.ObjectModifiedEvent object at ...>
u'Updated on ${date_time}'
>>> view.context.contentType
@@ -349,6 +356,10 @@
>>> view.getData()['data']
u'text \u0105'
+ Cleanup eventlog.
+
+ >>> zope.event.subscribers.remove(eventLog)
+
You will get an error if you try to specify a charset that cannot encode
all the characters
@@ -439,6 +450,10 @@
self.context.contentType = data['contentType']
formatter = self.request.locale.dates.getFormatter('dateTime',
'medium')
+
+ event = lifecycleevent.ObjectModifiedEvent(self.context)
+ zope.event.notify(event)
+
return _("Updated on ${date_time}",
mapping={'date_time': formatter.format(datetime.utcnow())})
@@ -460,16 +475,16 @@
def extractCharset(content_type):
"""Extract charset information from a MIME type.
- >>> extractCharset('text/plain; charset=UTF-8')
- 'UTF-8'
+ >>> extractCharset('text/plain; charset=US-ASCII')
+ 'US-ASCII'
>>> extractCharset('text/html; charset=ISO-8859-1')
'ISO-8859-1'
>>> extractCharset('text/plain')
- 'ASCII'
+ 'UTF-8'
"""
if content_type and content_type.strip():
major, minor, params = contenttype.parse(content_type)
- return params.get("charset", "ASCII")
+ return params.get("charset", "UTF-8")
else:
- return "ASCII"
+ return "UTF-8"
More information about the Zope3-Checkins
mailing list