Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
erp5
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Xiaowu Zhang
erp5
Commits
0378c29a
Commit
0378c29a
authored
Oct 16, 2019
by
Xiaowu Zhang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
erp5_web: extend asStrippedHTML to replace relative url by absolute url
parent
6ef450aa
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
184 additions
and
2 deletions
+184
-2
bt5/erp5_web/DocumentTemplateItem/portal_components/document.erp5.ReplaceRelativeUrlTextDocument.py
...omponents/document.erp5.ReplaceRelativeUrlTextDocument.py
+54
-0
bt5/erp5_web/DocumentTemplateItem/portal_components/document.erp5.ReplaceRelativeUrlTextDocument.xml
...mponents/document.erp5.ReplaceRelativeUrlTextDocument.xml
+127
-0
bt5/erp5_web/PortalTypeTemplateItem/portal_types/Web%20Page.xml
...p5_web/PortalTypeTemplateItem/portal_types/Web%20Page.xml
+1
-1
bt5/erp5_web/bt/template_document_id_list
bt5/erp5_web/bt/template_document_id_list
+2
-1
No files found.
bt5/erp5_web/DocumentTemplateItem/portal_components/document.erp5.ReplaceRelativeUrlTextDocument.py
0 → 100644
View file @
0378c29a
import
re
from
AccessControl
import
ClassSecurityInfo
from
Products.ERP5Type
import
Permissions
from
erp5.component.document.TextDocument
import
TextDocument
class
ReplaceRelativeUrlTextDocument
(
TextDocument
,
object
):
"""
XXX Necessairy
"""
# Declarative security
security
=
ClassSecurityInfo
()
security
.
declareProtected
(
Permissions
.
View
,
'asStrippedHTML'
)
def
asStrippedHTML
(
self
,
**
kw
):
match_link_tag
=
'<a.*?>'
match_link
=
'href="(.*)"'
match_img_tag
=
'<img.*?/>'
match_img_src
=
'src="(.*)"'
html
=
super
(
ReplaceRelativeUrlTextDocument
,
self
).
asStrippedHTML
(
**
kw
)
web_section
=
self
.
getWebSectionValue
()
# call directly from web page
if
not
web_section
:
return
html
web_section_url
=
web_section
.
getAbsoluteUrl
()
for
link_tag
in
re
.
findall
(
match_link_tag
,
html
):
link
=
re
.
search
(
match_link
,
link_tag
)
if
link
:
link
=
link
.
group
(
1
)
# link inside page
if
link
and
not
link
.
startswith
(
'http'
)
and
not
link
.
startswith
(
'#'
)
and
not
link
.
startswith
(
'mailto'
):
if
link
.
startswith
(
'./'
):
new_link
=
link
[
2
:]
else
:
new_link
=
link
# By conversion, first letter of reference should be upper case
# To be more sure of what to replace
# erp5-Howto
if
new_link
[
0
].
isupper
()
or
new_link
.
startswith
(
'erp5-'
)
or
new_link
.
startswith
(
'user-'
)
or
\
new_link
.
startswith
(
'slapos-'
)
or
new_link
.
startswith
(
'vifib-'
)
or
new_link
.
startswith
(
'osoe-'
)
or
\
new_link
.
startswith
(
'developer-'
)
or
new_link
.
startswith
(
'slapOS'
):
transformed_link_tag
=
link_tag
.
replace
(
link
,
'%s/%s'
%
(
web_section_url
,
new_link
),
1
)
html
=
html
.
replace
(
link_tag
,
transformed_link_tag
)
for
img_tag
in
re
.
findall
(
match_img_tag
,
html
):
src
=
re
.
search
(
match_img_src
,
img_tag
)
if
src
:
src
=
src
.
group
(
1
)
# consider src = './xxxx' is a local file inside web page
if
src
and
not
src
.
startswith
(
'http'
)
and
not
src
.
startswith
(
'./'
):
if
src
[
0
].
isupper
():
transformed_img_tag
=
img_tag
.
replace
(
src
,
'%s/%s'
%
(
web_section_url
,
src
),
1
)
html
=
html
.
replace
(
img_tag
,
transformed_img_tag
)
return
html
bt5/erp5_web/DocumentTemplateItem/portal_components/document.erp5.ReplaceRelativeUrlTextDocument.xml
0 → 100644
View file @
0378c29a
<?xml version="1.0"?>
<ZopeData>
<record
id=
"1"
aka=
"AAAAAAAAAAE="
>
<pickle>
<global
name=
"Document Component"
module=
"erp5.portal_type"
/>
</pickle>
<pickle>
<dictionary>
<item>
<key>
<string>
_recorded_property_dict
</string>
</key>
<value>
<persistent>
<string
encoding=
"base64"
>
AAAAAAAAAAI=
</string>
</persistent>
</value>
</item>
<item>
<key>
<string>
default_reference
</string>
</key>
<value>
<string>
ReplaceRelativeUrlTextDocument
</string>
</value>
</item>
<item>
<key>
<string>
description
</string>
</key>
<value>
<none/>
</value>
</item>
<item>
<key>
<string>
id
</string>
</key>
<value>
<string>
document.erp5.ReplaceRelativeUrlTextDocument
</string>
</value>
</item>
<item>
<key>
<string>
portal_type
</string>
</key>
<value>
<string>
Document Component
</string>
</value>
</item>
<item>
<key>
<string>
sid
</string>
</key>
<value>
<none/>
</value>
</item>
<item>
<key>
<string>
text_content_error_message
</string>
</key>
<value>
<tuple/>
</value>
</item>
<item>
<key>
<string>
text_content_warning_message
</string>
</key>
<value>
<tuple/>
</value>
</item>
<item>
<key>
<string>
version
</string>
</key>
<value>
<string>
erp5
</string>
</value>
</item>
<item>
<key>
<string>
workflow_history
</string>
</key>
<value>
<persistent>
<string
encoding=
"base64"
>
AAAAAAAAAAM=
</string>
</persistent>
</value>
</item>
</dictionary>
</pickle>
</record>
<record
id=
"2"
aka=
"AAAAAAAAAAI="
>
<pickle>
<global
name=
"PersistentMapping"
module=
"Persistence.mapping"
/>
</pickle>
<pickle>
<dictionary>
<item>
<key>
<string>
data
</string>
</key>
<value>
<dictionary/>
</value>
</item>
</dictionary>
</pickle>
</record>
<record
id=
"3"
aka=
"AAAAAAAAAAM="
>
<pickle>
<global
name=
"PersistentMapping"
module=
"Persistence.mapping"
/>
</pickle>
<pickle>
<dictionary>
<item>
<key>
<string>
data
</string>
</key>
<value>
<dictionary>
<item>
<key>
<string>
component_validation_workflow
</string>
</key>
<value>
<persistent>
<string
encoding=
"base64"
>
AAAAAAAAAAQ=
</string>
</persistent>
</value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</pickle>
</record>
<record
id=
"4"
aka=
"AAAAAAAAAAQ="
>
<pickle>
<global
name=
"WorkflowHistoryList"
module=
"Products.ERP5Type.Workflow"
/>
</pickle>
<pickle>
<dictionary>
<item>
<key>
<string>
_log
</string>
</key>
<value>
<list>
<dictionary>
<item>
<key>
<string>
action
</string>
</key>
<value>
<string>
validate
</string>
</value>
</item>
<item>
<key>
<string>
validation_state
</string>
</key>
<value>
<string>
validated
</string>
</value>
</item>
</dictionary>
</list>
</value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
bt5/erp5_web/PortalTypeTemplateItem/portal_types/Web%20Page.xml
View file @
0378c29a
...
...
@@ -102,7 +102,7 @@
</item>
<item>
<key>
<string>
type_class
</string>
</key>
<value>
<string>
TextDocument
</string>
</value>
<value>
<string>
ReplaceRelativeUrl
TextDocument
</string>
</value>
</item>
<item>
<key>
<string>
type_interface
</string>
</key>
...
...
bt5/erp5_web/bt/template_document_id_list
View file @
0378c29a
document.erp5.StaticWebSection
document.erp5.StaticWebSite
document.erp5.WebSection
document.erp5.WebSite
\ No newline at end of file
document.erp5.WebSite
document.erp5.ReplaceRelativeUrlTextDocument
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment