Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions imio/dms/mail/adapters.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from AccessControl import getSecurityManager
from collective.classification.folder.interfaces import IServiceInCharge
from collective.classification.folder.interfaces import IServiceInCopy
from collective.collabora.interfaces import IStoredFile
from collective.contact.core.content.held_position import IHeldPosition
from collective.contact.core.content.organization import IOrganization
from collective.contact.core.indexers import contact_source
Expand All @@ -15,6 +16,7 @@
from collective.dms.basecontent.dmsfile import IDmsFile
from collective.dms.mailcontent.indexers import add_parent_organizations
from collective.dms.scanbehavior.behaviors.behaviors import IScanFields
from collective.documentgenerator.content.pod_template import IPODTemplate
from collective.task.interfaces import ITaskContent
from imio.dms.mail import BACK_OR_AGAIN_ICONS
from imio.dms.mail import IM_READER_SERVICE_FUNCTIONS
Expand All @@ -41,6 +43,7 @@
from plone.app.contentmenu.menu import WorkflowMenu as OrigWorkflowMenu
from plone.app.contenttypes.indexers import _unicode_save_string_concat
from plone.indexer import indexer
from plone.namedfile.file import NamedBlobFile
from plone.registry.interfaces import IRegistry
from plone.rfc822.interfaces import IPrimaryFieldInfo
from Products.ATContentTypes.interfaces.folder import IATFolder
Expand Down Expand Up @@ -1043,3 +1046,30 @@ def get(self):
"title": child.title,
"UID": child.UID(),
}


@adapter(IPODTemplate)
@implementer(IStoredFile)
class StoredPodTemplate(object):
"""Access the file storage on a PODTemplate content object.

i.e. the file attribute on the content object.
"""

def __init__(self, context):
self.context = context
self.filename = context.odt_file.filename
self.contentType = context.odt_file.contentType

@property
def data(self):
return self.context.odt_file.data

@data.setter
def data(self, data):
self.context.odt_file = NamedBlobFile(
data=data, filename=self.filename, contentType=self.contentType
)

def getSize(self):
return self.context.odt_file.getSize()
24 changes: 24 additions & 0 deletions imio/dms/mail/browser/configure.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -604,6 +604,30 @@
permission="zope2.View"
/>

<configure package="collective.collabora.browser">
<browser:page
name="collabora-edit"
for="collective.documentgenerator.content.pod_template.IPODTemplate"
class="collective.collabora.browser.edit.CollaboraEditView"
template="templates/edit.pt"
permission="zope2.View"
layer="imio.dms.mail.interfaces.IImioDmsMailLayer"
/>
</configure>

<browser:page
name="collabora-wopi"
for="collective.documentgenerator.content.pod_template.IPODTemplate"
class="collective.collabora.browser.wopi.CollaboraWOPIView"
permission="zope2.View"
layer="imio.dms.mail.interfaces.IImioDmsMailLayer"
/>

<adapter factory="imio.dms.mail.adapters.StoredPodTemplate"
for="collective.documentgenerator.content.pod_template.IPODTemplate"
provides="collective.collabora.interfaces.IStoredFile"
/>

<!-- Viewlets -->
<!-- common for dmsincomingmail, dmsoutgoingmail and task -->
<browser:viewlet
Expand Down
3 changes: 1 addition & 2 deletions imio/dms/mail/browser/documentgenerator.py
Original file line number Diff line number Diff line change
Expand Up @@ -498,8 +498,7 @@ def redirects(self, persisted_doc):
"""
self._set_header_response(persisted_doc.file.filename)
response = self.request.response
# return response.redirect(self.context.absolute_url())
return response.redirect(persisted_doc.absolute_url() + "/external_edit")
return response.redirect(persisted_doc.absolute_url() + "/@@collabora-edit")

def _get_generation_context(self, helper_view, pod_template):
"""
Expand Down
12 changes: 11 additions & 1 deletion imio/dms/mail/browser/table.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# -*- coding: utf-8 -*-
from bs4 import BeautifulSoup
from collective.contact.plonegroup.browser.tables import OrgaPrettyLinkWithAdditionalInfosColumn as opl_base
from collective.dms.basecontent.browser.listing import VersionsTable
from collective.dms.basecontent.browser.listing import VersionsTitleColumn
Expand Down Expand Up @@ -100,7 +101,16 @@ def has_mailing(self, item):
def renderCell(self, item):
if not self.has_mailing(item):
return ""
return super(GenerationColumn, self).renderCell(item)
rendered = super(GenerationColumn, self).renderCell(item)

# Add target="_blank" to open collabora edit in a new tab
# This is a workaround to avoid modifying the original template
soup = BeautifulSoup(rendered, "html.parser")
a_tag = soup.find("a")
a_tag["target"] = "_blank"
rendered = str(soup)

return rendered


class EnquirerColumn(Column):
Expand Down
14 changes: 14 additions & 0 deletions imio/dms/mail/browser/views.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-
from AccessControl import getSecurityManager
from bs4 import BeautifulSoup
from collective.ckeditortemplates.cktemplate import ICKTemplate
from datetime import datetime
from eea.faceted.vocabularies.autocomplete import IAutocompleteSuggest
Expand Down Expand Up @@ -40,6 +41,19 @@ class CreateFromTemplateForm(BaseRenderFancyTree):

root = "/templates/om"

def index(self):
indexed = super(CreateFromTemplateForm, self).index()
# TODO improve this code

# Add target="_blank" to open collabora edit in a new tab
# This is a workaround to avoid modifying the original template
soup = BeautifulSoup(indexed, "html.parser")
form_tag = soup.find("form")
form_tag["target"] = "_blank"
indexed = str(soup)

return indexed

def label(self):
return translate(
_(u"${title}: create from template", mapping={"title": safe_unicode(self.context.Title())}),
Expand Down
4 changes: 2 additions & 2 deletions imio/dms/mail/columns.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,13 +323,13 @@ def renderCell(self, item):
},
)
else:
link_url = "%s/@@external_edit" % item.getURL()
link_url = "%s/@@collabora-edit" % item.getURL()
icon_name = "extedit_icon.png"
link_title = translate(self.linkContent, context=self.request)

link_content = u"""<img title="%s" src="%s" />""" % (link_title, "%s/%s" % (self.table.portal_url, icon_name))

return '<a href="%s"%s%s%s>%s</a>' % (
return '<a target="_blank" href="%s"%s%s%s>%s</a>' % (
link_url,
self.getLinkTarget(item),
self.getLinkCSS(item),
Expand Down