Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Word/DOCX-Eport: Applying python-docx #287

Open
drfho opened this issue Jun 19, 2024 · 1 comment
Open

Word/DOCX-Eport: Applying python-docx #287

drfho opened this issue Jun 19, 2024 · 1 comment

Comments

@drfho
Copy link
Contributor

drfho commented Jun 19, 2024

Traditionally ZMS uses the XML-represenation of it's content for (XSL-based) transforming it into 3rd-party formats like Word-XML. Instead using XSL (and its efforts with debugging) a direct, pythonic objekt transformation by the python-docx-library may be more practical especially with complex content-models . python-docx is a Python library for creating and updating Microsoft Word (.docx) files:
https://python-docx.readthedocs.io/

@drfho drfho changed the title Word/DOCX-Eport: Applying python-docx instead of XSL Word/DOCX-Eport: Applying python-docx Jun 19, 2024
drfho added a commit that referenced this issue Jun 19, 2024
@drfho
Copy link
Contributor Author

drfho commented Jun 19, 2024

The evaluation notebook of 1e726cd in #288 contains some code- snippets to create a word file interacting directly with ZODB.

image

The notebook code is quite minimalistic to get objects attribute values by the rest_api public functions. @zmsdev: But template based content aggregration will result in "AttributeError: REQUEST" due to ZMSObject.isVisible(self, REQUEST) and its call of self.isActive(REQUEST), Line 502:

def isVisible(self, REQUEST):
REQUEST = standard.nvl(REQUEST, self.REQUEST)
lang = standard.nvl(REQUEST.get('lang'), self.getPrimaryLanguage())
visible = True
visible = visible and self.isTranslated(lang, REQUEST) # Object is translated.
visible = visible and self.isCommitted(REQUEST) # Object has been committed.
visible = visible and self.isActive(REQUEST) # Object is active.
visible = visible and not '/'.join(self.getPhysicalPath()+('',)).startswith('/'.join(self.getTrashcan().getPhysicalPath()+('',))) # Object is not in trashcan.
return visible

The function ObjAttrs.isActive() calls self.getType() and this will break, Line 551;

# --------------------------------------------------------------------------
# ObjAttrs.isActive:
# --------------------------------------------------------------------------
def isActive(self, REQUEST):
b = True
if self.getType() == 'ZMSRecordSet':
return b
v = self.attr('active')
if isinstance(v, bool):
return v
v = self.attr('isActive')
if isinstance(v, bool):
b = b and v
obj_vers = self.getObjVersion(REQUEST)
obj_attrs = self.getObjAttrs()
now = datetime.datetime.now()
for key in ['active', 'attr_active_start', 'attr_active_end']:
if key in obj_attrs:
obj_attr = obj_attrs[key]
lang = self.get_request_context(REQUEST, 'lang', self.getPrimaryLanguage())
while True:
value = self._getObjAttrValue(obj_attr, obj_vers, lang)
empty = False
lang = self.getParentLanguage(lang)
if lang is not None:
empty = value is None
if not empty:
break
# Toggle.
if key == 'active':
b = b and value
# Start time.
elif key == 'attr_active_start':
if value is not None:
if isinstance(value, time.struct_time):
# Convert time.struct_time to datetime tuple.
value = tuple(value[:8]) + (0,)
dt = datetime.datetime.fromtimestamp(time.mktime(value))
b = b and now > dt
if dt > now and self.REQUEST.get('ZMS_CACHE_EXPIRE_DATETIME', dt) >= dt:
self.REQUEST.set('ZMS_CACHE_EXPIRE_DATETIME',dt)
# End time.
elif key == 'attr_active_end':
if value is not None:
if isinstance(value, time.struct_time):
# Convert time.struct_time to datetime tuple.
value = tuple(value[:8]) + (0,)
dt = datetime.datetime.fromtimestamp(time.mktime(value))
b = b and dt > now
if dt > now and self.REQUEST.get('ZMS_CACHE_EXPIRE_DATETIME', dt) >= dt:
self.REQUEST.set('ZMS_CACHE_EXPIRE_DATETIME',dt)
if not b: break
return b

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant