'Controller for message_post. Public user can post; their name and
email is used to find or create a partner and post as admin with the
right partner. Their comments are unpublished by default. Logged
users can post as usual.'

@http.route('/slides/slide/<model("slide.slide",    "[(\'channel_id.can_see\',    \'=\',    True)]"):slide>/comment', type='http', auth='public', methods=['POST'], website=True)
def slide_comment(self, slide, **post):

    if (not post.get('comment')):
        return werkzeug.utils.redirect((request.httprequest.referrer + '#discuss'))
    if (request.uid == request.website.user_id.id):
        if (not post.get('email')):
            return werkzeug.utils.redirect((request.httprequest.referrer + '#discuss'))
        contextual_slide = slide.sudo().with_context(mail_create_nosubcribe=True)
        partner_id = slide.sudo()._find_partner_from_emails([post.get('email')])[0]
        if partner_id:
            partner = request.env['res.partner'].sudo().browse(partner_id)
        else:
            partner = request.env['res.partner'].sudo().create({'name': post.get('name', post['email']), 'email': post['email']})
        post_kwargs = {'author_id': partner.id, 'website_published': False, 'email_from': partner.email}
    else:
        contextual_slide = slide
        post_kwargs = {}
    contextual_slide.message_post(body=post['comment'], message_type='comment', subtype='mt_comment', **post_kwargs)
    return werkzeug.utils.redirect((request.httprequest.referrer + '#discuss'))
