Permalink
Browse files

[IMP] website_slides_forum : Allow to create forum on slide.channel c…

…reation from frontend
  • Loading branch information...
dbeguin committed Feb 8, 2019
1 parent 238abfb commit 603e2d709ba3f69240d1741a7e26f397722966bd
@@ -68,6 +68,9 @@ def _get_slide_detail(self, slide):
'comments': slide.website_message_ids or [],
}

def _prepare_channel_values(self, **kwargs):
return dict(**kwargs)

# --------------------------------------------------
# MAIN / SEARCH
# --------------------------------------------------
@@ -196,12 +199,8 @@ def channel(self, channel, category=None, tag=None, page=1, slide_type=None, sor

@http.route(['/slides/channel/add'], type='http', auth='user', methods=['POST'], website=True)
def slide_channel_create(self, *args, **kw):
channel = request.env['slide.channel'].create({
'name': kw['name'],
'description': kw.get('description'),
'channel_type': kw.get('course_type', 'training'),
'responsible_id': request.env.user.id
})
values = self._prepare_channel_values(**kw)
channel = request.env['slide.channel'].create(values)
#TODO JEM: voir avec sbu si faut garder les url /courses
#if channel.channel_type == 'training':
# return werkzeug.utils.redirect("/courses/%s" % (slug(channel)))
@@ -66,6 +66,7 @@ def _default_access_token(self):
('training', 'Training')
], string="Course type", default="documentation", required=True)
category_ids = fields.One2many('slide.category', 'channel_id', string="Categories")
allow_comment = fields.Boolean('Allow comment', help="Allow comment on slides", default=False)
# slides: promote, statistics
slide_ids = fields.One2many('slide.slide', 'channel_id', string="Slides")
slide_partner_ids = fields.One2many('slide.slide.partner', 'channel_id', string="Slide User Data", groups='website.group_website_publisher')
@@ -12,7 +12,7 @@
<input type="text" class="form-control" name="name" id="title" placeholder="Title"/>
</div>
</div>
<fieldset class="form-group">
<fieldset class="form-group o_wslide_channel_type">
<div class="row">
<legend class="col-form-label col-sm-2">Type</legend>
<div class="col-sm-10">
@@ -9,6 +9,7 @@
'description': """A Slide channel can be linked to forum. Also, profiles from slide and forum are regrouped together""",
'depends': ['website_slides', 'website_forum'],
'data': [
'views/assets.xml',
'views/website_slides_views.xml',
'views/website_slides_forum_profile.xml'
],
@@ -10,6 +10,17 @@


class WebsiteSlidesForum(WebsiteProfile):
def _prepare_channel_values(self, **kwargs):
forum_type = kwargs.get('forum_type')
if forum_type:
if forum_type == 'forum':
forum = request.env['forum.forum'].create({
'name': kwargs.get('name')
})
kwargs['forum_id'] = forum.id
kwargs['allow_comment'] = forum_type == 'comment'
return super(WebsiteSlidesForum, self)._prepare_channel_values(**kwargs)

# Profile
# ---------------------------------------------------
@http.route(['/slides/<model("slide.channel"):channel>/user/<int:user_id>'], type='http', auth="public", website=True)
@@ -0,0 +1,2 @@
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
access_forum_forum_website_publisher,access.forum.forum.website.publisher,model_forum_forum,base.group_website_publisher,1,1,1,1
@@ -0,0 +1,13 @@
odoo.define('website_slides_forum.editor', function (require) {
"use strict";

var core = require('web.core');
var QWeb = core.qweb;
var WebsiteNewMenu = require('website.newMenu');

WebsiteNewMenu.include({
xmlDependencies: WebsiteNewMenu.prototype.xmlDependencies.concat(
['/website_slides_forum/static/src/xml/website_slides_forum_channel.xml']
),
});
});
@@ -0,0 +1,32 @@
<?xml version="1.0" encoding="UTF-8"?>
<templates xml:space="preserve">
<t t-extend="website.slide.channel.create">
<t t-jquery=".o_wslide_channel_type" t-operation="after">
<fieldset id="channel_create_forum" class="form-group">
<div class="row">
<legend class="col-form-label col-sm-2">Communication</legend>
<div class="col-sm-10">
<div class="form-check">
<input class="form-check-input" type="radio" name="forum_type" id="channel_type3" value="nothing" checked="checked"/>
<label class="form-check-label" for="forum_type3">
No communication
</label>
</div>
<div class="form-check">
<input class="form-check-input" type="radio" name="forum_type" id="channel_type1" value="forum"/>
<label class="form-check-label" for="forum_type1">
Create a Forum
</label>
</div>
<div class="form-check">
<input class="form-check-input" type="radio" name="forum_type" id="channel_type2" value="comment"/>
<label class="form-check-label" for="forum_type2">
Allow comments
</label>
</div>
</div>
</div>
</fieldset>
</t>
</t>
</templates>
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<template id="assets_frontend" inherit_id="website.assets_frontend" name="Website slide forum frontend assets">
<xpath expr="//script[last()]" position="after">
<script type="text/javascript" src="/website_slides_forum/static/src/js/website_slides_forum.editor.js"></script>
</xpath>
</template>
</odoo>
@@ -6,8 +6,9 @@
<field name="inherit_id" ref="website_slides.view_slide_channel_form"/>
<field name="arch" type="xml">
<xpath expr="//notebook" position="inside">
<page string="Forum">
<page string="Communication">
<group>
<field name="allow_comment"/>
<field name="forum_id"/>
</group>
</page>

0 comments on commit 603e2d7

Please sign in to comment.