-
Notifications
You must be signed in to change notification settings - Fork 1
[WIP] Adding a section to manage media in the frontend #5
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
base: 9.0
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,6 +14,7 @@ | |
|
|
||
|
|
||
| class PageFormMixin(ContextAwareMixin): | ||
|
|
||
| """CMS page Form controller.""" | ||
|
|
||
| form_name = '' | ||
|
|
@@ -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' | ||
|
|
@@ -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' | ||
|
|
@@ -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'): | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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> | ||
|
|
@@ -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> | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. category has a
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @PCatinean replace |
||
| </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> | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why these spaces? :)
There was a problem hiding this comment.
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