Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
57 changes: 57 additions & 0 deletions website_cms/controllers/form.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@


class PageFormMixin(ContextAwareMixin):

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why these spaces? :)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the editor's autopep8 did it. Did not happen before, will remove them

"""CMS page Form controller."""

form_name = ''
Expand Down Expand Up @@ -132,6 +133,7 @@ def after_post_action(self, parent=None, main_object=None, **kw):


class CreatePage(http.Controller, PageFormMixin):

"""CMS page create controller."""

form_name = 'add-page'
Expand Down Expand Up @@ -196,6 +198,7 @@ def after_post_action(self, parent=None, main_object=None, **kw):


class EditPage(http.Controller, PageFormMixin):

"""CMS page edit controller."""

form_name = 'edit-page'
Expand Down Expand Up @@ -246,3 +249,57 @@ def after_post_action(self, parent=None, main_object=None, **kw):
u'in many views (like listing or homepage).'),
}
self.add_status_message(msg)


class ManageMedia(http.Controller, PageFormMixin):

"""CMS media manage controller."""

form_name = 'manage-media'
form_title = _('Manage media')
form_mode = 'media'
template = 'website_cms.page_media'
status_message_success = {
'type': 'media',
'title': 'Media:',
'msg': _(u'Media updated.'),
}

def load_defaults(self, main_object, **kw):
"""Override to preload values."""
defaults = {}
if main_object:
defaults['parent_id'] = main_object.id
defaults['form_action'] = \
main_object.website_url + '/' + self.form_name
for fname in ('type_id', 'view_id'):
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these fields are not in cms.media model, why do you need them here?

fvalue = getattr(main_object, 'sub_page_' + fname)
defaults[fname] = fvalue and fvalue.id or False
defaults[
'media_categories'] = request.website.get_media_categories()
defaults['media'] = request.website.get_media(
kw.get('media_categ') and kw.get('media_categ').id
)
return defaults

@http.route([
'/cms/manage-media',
'/cms/<secure_model("cms.page"):parent>/manage-media/',
'/cms/<secure_model("cms.page"):parent>/manage-media/'
'<secure_model("cms.media.category"):media_categ>',
'/cms/<path:path>/<secure_model("cms.page"):parent>/manage-media/',
'/cms/<path:path>/<secure_model("cms.page"):parent>/manage-media/'
'<secure_model("cms.media.category"):media_categ>',
], type='http', auth='user', methods=['GET', 'POST'], website=True)
def manage(self, parent=None, **kw):
"""Handle page add view and form submit."""
if request.httprequest.method == 'GET':
return self.render(parent, **kw)

elif request.httprequest.method == 'POST':
self.before_post_action(parent=parent, **kw)
# handle form submission
values = self.load_defaults(parent, **kw)
# TODO: handle errors
_values, errors = self.extract_values(request, parent, **kw)
values.update(_values)
21 changes: 21 additions & 0 deletions website_cms/models/website.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from openerp.addons.web.http import request
from openerp.addons.website.models.website import unslug


from openerp.addons.website_cms.utils import AttrDict

import urlparse
Expand Down Expand Up @@ -147,6 +148,17 @@ def get_media_categories(self, active=True):
return self.env['cms.media.category'].search(
[('active', '=', active)])

@api.model
def get_media(self, category_id=None, published=None):
search_args = []

if category_id:
search_args.append(('category_id', '=', category_id))
if published:
search_args.append(('website_published', '=', True))

return self.env['cms.media'].search(search_args)

def get_alternate_languages(self, cr, uid, ids,
req=None, context=None,
main_object=None):
Expand Down Expand Up @@ -241,3 +253,12 @@ def cms_can_edit(self, main_object=None):
is_owner = main_object.create_uid.id == self.env.user.id
return is_owner or is_manager
return False

def cms_media_categ_links(self, main_object=None, category=None):
"""Retrieve media cms page links"""
if self.is_cms_page(main_object):
url = '%s/manage-media' % main_object.website_url
if category:
url = url + '/%s' % category.public_slug()
return url
return False
43 changes: 43 additions & 0 deletions website_cms/templates/form.xml
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,17 @@ We load each field explicitely here for now.

</div>

<div class="form-group form-field mt8 field-media">
<label class="col-md-2 col-sm-3 control-label" for="tags">Media</label>
<!-- make sure you keep a fake `value` attribute
otherwise `initSelection` mechanism won't work.
See http://select2.github.io/select2/#initSelection -->

<span></span>
<input type="text" name="tag_ids" class="form-control js_select2" style="clear:both"
t-att-data-can-create="is_cms_manager and 1 or None"
placeholder="Tags" t-attf-data-init-value="#{tag_ids}" value="media goes here" />
</div>

<div class="form-group form-field mt8 field-tag_ids">
<label class="col-md-2 col-sm-3 control-label" for="tags">Tags</label>
Expand All @@ -127,4 +138,36 @@ We load each field explicitely here for now.

</template>

<template id="page_media" name="CMS Media Form">

<t t-call="website.layout">
<t t-if="False">
# we can override default action via form values
</t>

<t t-set="title" t-value="view.form_title" />

<div class="col-xs-12 col-md-10 col-md-offset-1">
<h2>
<span class="form_title" t-esc="view.form_title" />
</h2>

<ul class="nav nav-tabs nav-justified mt32">
<li role="presentation" class="active"><a t-att-href="website.cms_media_categ_links(main_object=main_object)">All</a></li>
<t t-foreach="media_categories" t-as="category">
<li role="presentation"><a t-att-href="website.cms_media_categ_links(main_object=main_object, category=category)" t-field="category.name"></a></li>
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

category has a icon field where you can set the css class for it: can you add it here?
It should be something like <i t-ignore="true" t-att-class="category.icon" />

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@PCatinean replace t-ignore with t-translation="off"

</t>
</ul>

<t t-foreach="media" t-as="res">
<div class="col-xs-12 col-md-3 mt16">
<span t-esc="res.name"/>
</div>
</t>

</div>
</t>

</template>

</odoo>