Permalink
Browse files

[ADD] website_slides_forum : Allows to create forum on a course

Adds the mega power to make Super Saiyan fusion between website_slides and website_forum
A slide.channel can now be linked to a forum to allow users to discuss about their courses.

Overrides the slides profile routes to include the potiential linked forum.
the profile page displays now all the information of a specific channel with, also, all the
information of the linked channel. If no channle is specified, the slide profile page shows
every thing (information about all channel and information about all forum LINKED to channels).
If the generic profile template page is called, everything is displayed, all forum and all channels.

Task ID : 1922159
PR #30514
  • Loading branch information...
dbeguin committed Jan 23, 2019
1 parent 8f273db commit 77363a3c1f038cb8f3a29093de2c7457f506433e
@@ -52,7 +52,7 @@
</attribute>
</xpath>
</template>

<template id="edit_slides_profile_main" name="Slides Edit Profile">
<t t-call="website.layout">
<div class="container mt16 mb32">
@@ -0,0 +1,5 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.

from . import models
from . import controllers
@@ -0,0 +1,16 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.

{
'name': 'Forum on course',
'category': 'Hidden',
'version': '1.0',
'summary': 'Allows to link forum on a course',
'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/website_slides_views.xml',
'views/website_slides_forum_profile.xml'
],
'auto_install': False,
}
@@ -0,0 +1,3 @@
# -*- coding: utf-8 -*-

from . import main
@@ -0,0 +1,93 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.

import werkzeug

from odoo.addons.http_routing.models.ir_http import slug
from odoo import http
from odoo.http import request
from odoo.addons.website_profile.controllers.main import WebsiteProfile


class WebsiteSlidesForum(WebsiteProfile):
# Profile
# ---------------------------------------------------
@http.route(['/slides/<model("slide.channel"):channel>/user/<int:user_id>'], type='http', auth="public", website=True)
def open_slide_user(self, channel, user_id=0, **post):
user = request.env['res.users'].sudo().browse(user_id)
current_user = request.env.user.sudo()

# Users with high karma can see users with karma <= 0 for
# moderation purposes, IFF they have posted something (see below)
if (not user or (user.karma < 1 and current_user.karma < channel.karma_unlink_all)):
return werkzeug.utils.redirect("/slides/%s" % slug(channel))
values = self._prepare_user_values(channel=channel, forum=channel.forum_id, **post)

values.update(self._prepare_open_slide_user(user))
values.update(self._prepare_open_forum_user(user, current_user, channel.forum_id, values, **post))
if not values['is_profile_page']:
return request.render("website_slides_forum.private_profile_slide_forum", values, status=404)
return request.render("website_slides_forum.user_detail_full", values)

@http.route(['/slides/user/<int:user_id>'], type='http', auth="public", website=True)
def open_cross_slide_user(self, user_id=0, **post):
user = request.env['res.users'].sudo().browse([user_id])
current_user = request.env.user.sudo()

if post.get('channel'):
channels = post.get('channel')
elif post.get('channel_id'):
channels = request.env['slide.channel'].browse(int(post.get('channel_id')))
else:
channels = request.env['slide.channel'].search([])

if len(channels) == 1:
forums = channels[0].forum_id
else:
forums = channels.mapped('forum_id')

values = {
'user': request.env.user,
'is_public_user': request.env.user.id == request.website.user_id.id,
'notifications': self._get_notifications(),
'header': post.get('header', dict()),
'searches': post.get('searches', dict()),
'validation_email_sent': request.session.get('validation_email_sent', False),
'validation_email_done': request.session.get('validation_email_done', False),
'channel': channels[0] if len(channels) == 1 else True,
'forum': forums[0] if len(forums) == 1 else False if len(forums) == 0 else True,
}

values.update(self._prepare_open_forum_user(user, current_user, forums, values, **post))
if forums and not values['is_profile_page']:
return request.render("website_slides_forum.private_profile_slide_forum", values, status=404)

values.update(self._prepare_open_slide_user(user))
return request.render("website_slides_forum.user_detail_cross_full", values)

@http.route(['/profile/user/<int:user_id>'], type='http', auth="public", website=True)
def open_profile_user(self, user_id=0, **post):
user = request.env['res.users'].sudo().browse([user_id])
current_user = request.env.user.sudo()

channels = request.env['slide.channel'].search([])
forums = request.env['forum.forum'].search([])

values = {
'user': request.env.user,
'is_public_user': request.env.user.id == request.website.user_id.id,
'notifications': self._get_notifications(),
'header': post.get('header', dict()),
'searches': post.get('searches', dict()),
'validation_email_sent': request.session.get('validation_email_sent', False),
'validation_email_done': request.session.get('validation_email_done', False),
'channel': channels[0] if len(channels) == 1 else True,
'forum': forums[0] if len(forums) == 1 else True,
}

values.update(self._prepare_open_forum_user(user, current_user, forums, values, **post))
if forums and not values['is_profile_page']:
return request.render("website_slides_forum.private_profile", values, status=404)

values.update(self._prepare_open_slide_user(user))
return request.render("website_profile.user_detail_main", values)
@@ -0,0 +1,4 @@
# -*- coding: utf-8 -*-

from . import forum
from . import slide_channel
@@ -0,0 +1,10 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.

from odoo import fields, models


class Forum(models.Model):
_inherit = 'forum.forum'

slide_channel_id = fields.Many2one('slide.channel', 'Course')
@@ -0,0 +1,14 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.

from odoo import fields, models


class Channel(models.Model):
_inherit = 'slide.channel'

forum_id = fields.Many2one('forum.forum', 'Course Forum')

_sql_constraints = [
('forum_uniq', 'unique (forum_id)', "Only one forum per slide channel!"),
]
@@ -0,0 +1,84 @@
<?xml version="1.0" ?>
<odoo>
<data>
<template id="website_slide_forum_slides_channel_header" inherit_id="website_slides.slides_channel_header">
<xpath expr="//h3" position="inside">
<t t-if="channel.forum_id">
<a role="button" class="btn btn-primary" title="Go to Forum" t-attf-channel_id="#{channel.id}" aria-label="Go to Forum" t-attf-href="/forum/#{slug(channel.forum_id)}">
Forum
</a>
</t>
</xpath>
</template>

<template id="user_detail_header_slide_forum" inherit_id="website_profile.user_detail_header" primary="True">
<xpath expr="//a[@id='edit_profile_button']" position="replace">
<t t-if="channel">
<t t-if="isinstance(channel, bool)">
<a id="edit_profile_button" class="btn btn-primary o_wprofile_edit"
t-if="request.env.user == user"
t-attf-href="/slides/user/edit"><b>EDIT PROFILE</b></a>
</t>
<t t-else="">
<a id="edit_profile_button" class="btn btn-primary o_wprofile_edit"
t-if="request.env.user == user"
t-attf-href="/slides/user/edit?channel_id=#{channel.id}"><b>EDIT PROFILE</b></a>
</t>
</t>
<t t-if="not channel">
<t t-if="forum">
<t t-if="isinstance(forum, bool)">
<a id="edit_profile_button" class="o_profile_edit"
t-if="request.env.user == user"
t-attf-href="/forum/user/edit"><b>EDIT PROFILE</b></a>
</t>
<t t-else="">
<a id="edit_profile_button" class="o_profile_edit"
t-if="request.env.user == user"
t-attf-href="/forum/user/edit?forum_id=#{forum.id}"><b>EDIT PROFILE</b></a>
</t>
</t>
</t>
</xpath>
</template>

<template id="user_detail_full">
<t t-call="website.layout">
<t t-call="website_slides.profile_header">
</t>
<t t-call="website_slides_forum.user_detail_header_slide_forum"></t>
<t t-call="website_slides.user_detail_content"></t>
</t>
</template>

<template id="user_detail_cross_full">
<t t-call="website.layout">
<t t-call="website_slides_forum.user_detail_header_slide_forum"></t>
<t t-call="website_slides.user_detail_content"></t>
</t>
</template>

<!--Private profile-->
<template id="private_profile_slide_forum">
<t t-call="website.layout">
<div class="container mb32 mt48">
<h1 class="mt32">This profile is private!</h1>
<p>
<a t-attf-href="/slides">Return to the eLearning.</a>
</p>
</div>
</t>
</template>

<template id="private_profile">
<t t-call="website.layout">
<div class="container mb32 mt48">
<h1 class="mt32">This profile is private!</h1>
<p>
<a t-attf-href="/">Return to the website.</a>
</p>
</div>
</t>
</template>
</data>
</odoo>
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record id="website_slides_forum_channel_inherit_view_form" model="ir.ui.view">
<field name="name">website.slides_forum.view.form.inherit.slide.channel</field>
<field name="model">slide.channel</field>
<field name="inherit_id" ref="website_slides.view_slide_channel_form"/>
<field name="arch" type="xml">
<xpath expr="//notebook" position="inside">
<page string="Forum">
<group>
<field name="forum_id"/>
</group>
</page>
</xpath>
</field>
</record>
</odoo>

0 comments on commit 77363a3

Please sign in to comment.