Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
Coopdevs OCB mirror
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
External wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Coopdevs
Odoo
Coopdevs OCB mirror
Commits
c1b1ba69
Commit
c1b1ba69
authored
10 years ago
by
Christophe Matthieu
Browse files
Options
Downloads
Patches
Plain Diff
[IMP] website: image controller can use xmlid
parent
dd4a7213
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
addons/website/controllers/main.py
+17
-1
17 additions, 1 deletion
addons/website/controllers/main.py
addons/website/data/data.xml
+4
-3
4 additions, 3 deletions
addons/website/data/data.xml
with
21 additions
and
4 deletions
addons/website/controllers/main.py
+
17
−
1
View file @
c1b1ba69
...
...
@@ -403,9 +403,11 @@ class Website(openerp.addons.web.controllers.main.Home):
@http.route
([
'
/website/image
'
,
'
/website/image/<xmlid>
'
,
'
/website/image/<xmlid>/<field>
'
,
'
/website/image/<model>/<id>/<field>
'
],
auth
=
"
public
"
,
website
=
True
)
def
website_image
(
self
,
model
,
id
,
field
,
max_width
=
None
,
max_height
=
None
):
def
website_image
(
self
,
model
=
None
,
id
=
None
,
field
=
None
,
xmlid
=
None
,
max_width
=
None
,
max_height
=
None
):
"""
Fetches the requested field and ensures it does not go above
(max_width, max_height), resizing it if necessary.
...
...
@@ -419,7 +421,21 @@ class Website(openerp.addons.web.controllers.main.Home):
The requested field is assumed to be base64-encoded image data in
all cases.
xmlid can be used to load the image. But the field image must by base64-encoded
"""
if
xmlid
and
"
.
"
in
xmlid
:
xmlid
=
xmlid
.
split
(
"
.
"
,
1
)
try
:
model
,
id
=
request
.
registry
[
'
ir.model.data
'
].
get_object_reference
(
request
.
cr
,
request
.
uid
,
xmlid
[
0
],
xmlid
[
1
])
except
:
raise
werkzeug
.
exceptions
.
NotFound
()
if
model
==
'
ir.attachment
'
:
field
=
"
datas
"
if
not
model
or
not
id
or
not
field
:
raise
werkzeug
.
exceptions
.
NotFound
()
response
=
werkzeug
.
wrappers
.
Response
()
return
request
.
registry
[
'
website
'
].
_image
(
request
.
cr
,
request
.
uid
,
model
,
id
,
field
,
response
,
max_width
,
max_height
)
...
...
This diff is collapsed.
Click to expand it.
addons/website/data/data.xml
+
4
−
3
View file @
c1b1ba69
...
...
@@ -92,12 +92,13 @@
<!-- Pre loaded images -->
<record
model=
"ir.attachment"
>
<!-- base64-encoded on ir.attachment, to allow to load image with the xmlid -->
<record
id=
"website.business_conference"
model=
"ir.attachment"
>
<field
name=
"name"
>
business_conference
</field>
<field
name=
"datas_fname"
>
business_conference.jpg
</field>
<field
name=
"res_model"
>
ir.ui.view
</field>
<field
name=
"type"
>
url
</field>
<field
name=
"
url"
>
/
website/static/src/img/library/business_conference.jpg
</field
>
<field
name=
"type"
>
binary
</field>
<field
name=
"
datas"
type=
"base64"
file=
"
website/static/src/img/library/business_conference.jpg
"
/
>
</record>
<record
model=
"ir.attachment"
>
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment