[Python-modules-commits] [python-odf] 10/118: Make it work again Dropped suffix when id is auto-generated
Wolfgang Borgert
debacle at moszumanska.debian.org
Fri Oct 3 21:27:16 UTC 2014
This is an automated email from the git hooks/post-receive script.
debacle pushed a commit to reference refs/remotes/upstream/master
in repository python-odf.
commit a72d744dbb1653301bb5a4a4e23718f34fe470f3
Author: Søren Roug <soren.roug at eea.europa.eu>
Date: Thu Nov 20 20:08:23 2008 +0000
Make it work again
Dropped suffix when id is auto-generated
---
contrib/ODFFile/ODFFile.py | 131 ++++++++++++++++++------------------
contrib/ODFFile/__init__.py | 36 +++++-----
contrib/ODFFile/dtml/odf_index.dtml | 3 -
3 files changed, 80 insertions(+), 90 deletions(-)
diff --git a/contrib/ODFFile/ODFFile.py b/contrib/ODFFile/ODFFile.py
index 31522b7..97e529a 100644
--- a/contrib/ODFFile/ODFFile.py
+++ b/contrib/ODFFile/ODFFile.py
@@ -1,28 +1,27 @@
-# The contents of this file are subject to the Mozilla Public
-# License Version 1.1 (the "License"); you may not use this file
-# except in compliance with the License. You may obtain a copy of
-# The contents of this file are subject to the Mozilla Public
-# License Version 1.1 (the "License"); you may not use this file
-# except in compliance with the License. You may obtain a copy of
-# the License at http://www.mozilla.org/MPL/
+# -*- coding: utf-8 -*-
+# Copyright (C) 2007-2008 Søren Roug, European Environment Agency
#
-# Software distributed under the License is distributed on an "AS
-# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
-# implied. See the License for the specific language governing
-# rights and limitations under the License.
+# This is free software. You may redistribute it under the terms
+# of the Apache license and the GNU General Public License Version
+# 2 or at your option any later version.
#
-# The Initial Owner of the Original Code is European Environment
-# Agency (EEA). Portions created by Finsiel Romania are
-# Copyright (C) European Environment Agency. All
-# Rights Reserved.
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public
+# License along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+#
+# Contributor(s):
#
-# Authors:
-# Alexandru Ghica, Adriana Baciu - Finsiel Romania
-
#Python imports
import zipfile
from odf.odf2xhtml import ODF2XHTML
+from odf.namespaces import OFFICENS, TEXTNS, XLINKNS
+from odf.opendocument import odmimetypes
#Zope imports
from OFS.Image import File, cookId
@@ -36,61 +35,52 @@ except ImportError:
from StringIO import StringIO
class ODF2XHTMLBody(ODF2XHTML):
- def s_draw_image(self, tag, attrs):
- anchor_type = self.tagstack.stackparent()[("urn:oasis:names:tc:opendocument:xmlns:text:1.0",'anchor-type')]
- imghref = attrs[("http://www.w3.org/1999/xlink","href")]
+
+ def rewritelink(self, imghref):
imghref = imghref.replace("Pictures/","index_html?pict=")
- htmlattrs = {'alt':"", 'src':imghref }
- if anchor_type != "character":
- htmlattrs['style'] = "display: block;"
- self.emptytag('img', htmlattrs)
+ return imghref
-class ODF2XHTMLEmbedded(ODF2XHTML):
+class ODF2XHTMLEmbedded(ODF2XHTMLBody):
def __init__(self):
ODF2XHTML.__init__(self)
- self.elements[(OFFICENS, "text")] = (None,None)
- self.elements[(OFFICENS, "spreadsheet")] = (None,None)
- self.elements[(OFFICENS, "presentation")] = (None,None)
- self.elements[(OFFICENS, "document-content")] = (None,None)
-
- def s_draw_image(self, tag, attrs):
- anchor_type = self.tagstack.stackparent()[("urn:oasis:names:tc:opendocument:xmlns:text:1.0",'anchor-type')]
- imghref = attrs[("http://www.w3.org/1999/xlink","href")]
- imghref = imghref.replace("Pictures/","index_html?pict=")
- htmlattrs = {'alt':"", 'src':imghref }
- if anchor_type != "character":
- htmlattrs['style'] = "display: block;"
- self.emptytag('img', htmlattrs)
-
+ self.elements[(OFFICENS, u"text")] = (None,None)
+ self.elements[(OFFICENS, u"spreadsheet")] = (None,None)
+ self.elements[(OFFICENS, u"presentation")] = (None,None)
+ self.elements[(OFFICENS, u"document-content")] = (None,None)
manage_addODFFileForm=DTMLFile('dtml/odffileAdd', globals())
-def manage_addODFFile(self,id,file='',title='',precondition='', content_type='', conversion='embedded',
+def manage_addODFFile(self, id='', file='',title='', precondition='', content_type='', conversion='embedded',
REQUEST=None):
"""Add a new File object.
Creates a new File object 'id' with the contents of 'file'"""
- id=str(id)
- title=str(title)
- conversion=str(conversion)
- content_type=str(content_type)
- precondition=str(precondition)
-
- id, title = cookId(id, title, file)
-
- self=self.this()
+ id = str(id)
+ title = str(title)
+ conversion = str(conversion)
+ content_type = str(content_type)
+ precondition = str(precondition)
+
+ suffix = ''
+ newid, title = cookId(id, title, file)
+ if id == '' and newid[-4:-2]== '.o' and newid[-2] in ['d','t']:
+ id = newid[:-4]
+ suffix = id[-3:]
+ else:
+ id = newid
+ self = self.this()
# First, we create the file without data:
- self._setObject(id, ODFFile(id,title,'',content_type, precondition, conversion))
+ self._setObject(id, ODFFile(id, title, '', suffix, content_type, precondition, conversion))
# Now we "upload" the data. By doing this in two steps, we
# can use a database trick to make the upload more efficient.
if file:
self._getOb(id).manage_upload(file)
if content_type:
- self._getOb(id).content_type=content_type
+ self._getOb(id).content_type = content_type
if REQUEST is not None:
REQUEST['RESPONSE'].redirect(self.absolute_url()+'/manage_main')
@@ -110,10 +100,11 @@ class ODFFile(File):
security = ClassSecurityInfo()
- def __init__(self, id, title, file, content_type='', precondition='', conversion='embedded'):
+ def __init__(self, id, title, file, suffix, content_type='', precondition='', conversion='embedded'):
""" constructor """
self.xhtml = "<h1>Nothing uploaded</h1>"
self.conversion = conversion
+ self.suffix = suffix
self._pictures = {}
File.__dict__['__init__'](self, id, title, file, content_type, precondition)
@@ -124,20 +115,25 @@ class ODFFile(File):
-# security.declareProtected(view, 'index_html')
- embedded_file = DTMLFile('dtml/odf_index', globals())
+ security.declareProtected(view, 'index_html')
def index_html(self, REQUEST=None, RESPONSE=None):
""" Show the HTML part """
if REQUEST.has_key('pict'):
return self.Pictures(REQUEST['pict'], REQUEST, RESPONSE)
- return self.embedded_file(REQUEST, RESPONSE)
+ rsp = []
+ if self.conversion == 'embedded':
+ rsp.append(self.standard_html_header(self, REQUEST, RESPONSE))
+ rsp.append(self.xhtml)
+ if self.conversion == 'embedded':
+ rsp.append(self.standard_html_footer(self, REQUEST, RESPONSE))
+ return(''.join(rsp))
- manage_editForm =DTMLFile('dtml/odfEdit',globals())
+ manage_editForm = DTMLFile('dtml/odfEdit',globals())
manage_editForm._setName('manage_editForm')
- manage=manage_main=manage_editForm
- manage_uploadForm=manage_editForm
+ manage=manage_main = manage_editForm
+ manage_uploadForm = manage_editForm
def manage_edit(self, title, content_type, precondition='',
filedata=None, conversion='none', REQUEST=None):
@@ -158,8 +154,12 @@ class ODFFile(File):
def uploadFile(self, file):
""" asociates a file to the ODFFile object """
data, size = self._read_data(file)
- content_type=self._get_content_type(file, data, self.__name__, 'undefined')
+ content_type = self._get_content_type(file, data, self.__name__, 'undefined')
self.update_data(data, content_type, size)
+ suffix = odmimetypes.get(content_type)
+ if suffix:
+ self.suffix = suffix
+ self.update_xhtml()
self._p_changed = 1
security.declareProtected(view, 'download')
@@ -167,7 +167,7 @@ class ODFFile(File):
""" set for download asociated file """
self.REQUEST.RESPONSE.setHeader('Content-Type', self.content_type)
self.REQUEST.RESPONSE.setHeader('Content-Length', self.size)
- self.REQUEST.RESPONSE.setHeader('Content-Disposition', 'attachment;filename="' + self.id() + '"')
+ self.REQUEST.RESPONSE.setHeader('Content-Disposition', 'attachment;filename="' + self.id() + "." + self.suffix + '"')
return ODFFile.inheritedAttribute('index_html')(self, REQUEST, RESPONSE)
security.declareProtected(view, 'download')
@@ -213,11 +213,10 @@ class ODFFile(File):
self._save_pictures(fd)
fd.seek(0)
self.xhtml = odhandler.odf2xhtml(fd).encode('us-ascii','xmlcharrefreplace')
+ self.title = odhandler.title
- update_data__roles__=()
- def update_data(self, data, content_type=None, size=None):
- File.__dict__['update_data'](self, data, content_type,size)
- self.update_xhtml()
-
+# update_data__roles__=()
+# def update_data(self, data, content_type=None, size=None):
+# File.__dict__['update_data'](self, data, content_type, size)
InitializeClass(ODFFile)
diff --git a/contrib/ODFFile/__init__.py b/contrib/ODFFile/__init__.py
index 36c2f52..1a46204 100644
--- a/contrib/ODFFile/__init__.py
+++ b/contrib/ODFFile/__init__.py
@@ -1,33 +1,27 @@
-# The contents of this file are subject to the Mozilla Public
-# License Version 1.1 (the "License"); you may not use this file
-# except in compliance with the License. You may obtain a copy of
-# the License at http://www.mozilla.org/MPL/
+# -*- coding: utf-8 -*-
+# Copyright (C) 2007-2008 Søren Roug, European Environment Agency
#
-# Software distributed under the License is distributed on an "AS
-# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
-# implied. See the License for the specific language governing
-# rights and limitations under the License.
+# This is free software. You may redistribute it under the terms
+# of the Apache license and the GNU General Public License Version
+# 2 or at your option any later version.
#
-# The Initial Owner of the Original Code is European Environment
-# Agency (EEA). Portions created by Finsiel Romania are
-# Copyright (C) European Environment Agency. All
-# Rights Reserved.
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public
+# License along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+#
+# Contributor(s):
#
-# Authors:
-# Soren Roug
-
-
-__doc__=""" ODFFile """
-__version__='$Revision: 1.7 $'[11:-2]
-#Python imports
#Zope imports
from ODFFile import ODFFile, manage_addODFFileForm, manage_addODFFile
from AccessControl.Permissions import add_documents_images_and_files
-#Product imports
-
def initialize(context):
""" initialize the ODFFile component """
diff --git a/contrib/ODFFile/dtml/odf_index.dtml b/contrib/ODFFile/dtml/odf_index.dtml
deleted file mode 100644
index 0cdd7b8..0000000
--- a/contrib/ODFFile/dtml/odf_index.dtml
+++ /dev/null
@@ -1,3 +0,0 @@
-<dtml-if "conversion == 'embedded'"><dtml-var standard_html_header></dtml-if>
-<dtml-var xhtml>
-<dtml-if "conversion == 'embedded'"><dtml-var standard_html_footer></dtml-if>
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/python-modules/packages/python-odf.git
More information about the Python-modules-commits
mailing list