<commit_before># -*- encoding: utf-8 -*-
##############################################################
#    Module Writen For Odoo, Open Source Management Solution
#
#    Copyright (c) 2011 Vauxoo - http://www.vauxoo.com
#    All Rights Reserved.
#    info Vauxoo (<EMAIL>)
#    coded by: <EMAIL>
#    planned by: <EMAIL>
#                <EMAIL>
############################################################################

import pprint

from openerp.addons.web import http
from openerp.http import request
from openerp import SUPERUSER_ID, exceptions
from openerp.tools.translate import _


class WebhookController(http.Controller):

    @http.route('/webhook', type='json', auth='none', method=['POST'])
    def webhook(self, *args, **kwargs):
        '''
        Webhook odoo controller to receive json request and send to
        driver method.
        You will need create your webhook with http://0.0.0.0:0000/webhook
        NOTE: Important use --db-filter params in odoo start.
        '''
        cr, context = request.cr, request.context
        webhook_registry = request.registry['webhook']
        webhook = webhook_registry.search_with_request(
            cr, SUPERUSER_ID, request, context=context)
        if not webhook:
            remote_addr = ''
            if hasattr(request, 'httprequest'):
                if hasattr(request.httprequest, 'remote_addr'):
                    remote_addr = request.httprequest.remote_addr
            raise exceptions.ValidationError(_(
                'webhook consumer from remote address [%s] '
                'not found jsonrequest [%s]' % (
                    remote_addr,
                    pprint.pformat(request.jsonrequest)[:450]
                )))
        webhook.run_webhook(request)<commit_msg>[REF] webhook: Add dynamic url with name of webhook record<commit_after># -*- encoding: utf-8 -*-
##############################################################
#    Module Writen For Odoo, Open Source Management Solution
#
#    Copyright (c) 2011 Vauxoo - http://www.vauxoo.com
#    All Rights Reserved.
#    info Vauxoo (<EMAIL>)
#    coded by: <EMAIL>
#    planned by: <EMAIL>
#                <EMAIL>
############################################################################

import pprint

from openerp.addons.web import http
from openerp.http import request
from openerp import SUPERUSER_ID, exceptions
from openerp.tools.translate import _


class WebhookController(http.Controller):

    @http.route(['/webhook/<webhook_name>'], type='json',
                auth='none', method=['POST'])
    def webhook(self, webhook_name, **post):
        '''
        :params string webhook_name: Name of webhook to use
        Webhook odoo controller to receive json request and send to
        driver method.
        You will need create your webhook with http://0.0.0.0:0000/webhook
        NOTE: Important use --db-filter params in odoo start.
        '''
        # Deprecated by webhook_name dynamic name
        # webhook = webhook_registry.search_with_request(
        #     cr, SUPERUSER_ID, request, context=context)
        webhook = request.env['webhook'].with_env(
            request.env(user=SUPERUSER_ID)).search(
                [('name', '=', webhook_name)], limit=1)
        # TODO: Add security by secret string  or/and ip consumer
        if not webhook:
            remote_addr = ''
            if hasattr(request, 'httprequest'):
                if hasattr(request.httprequest, 'remote_addr'):
                    remote_addr = request.httprequest.remote_addr
            raise exceptions.ValidationError(_(
                'webhook consumer [%s] from remote address [%s] '
                'not found jsonrequest [%s]' % (
                    webhook_name,
                    remote_addr,
                    pprint.pformat(request.jsonrequest)[:450]
                )))
        webhook.run_webhook(request)
{'fraction_non_alphanumeric': 0.16709445585215607, 'fraction_numerical': 0.008470225872689939, 'mean_word_length': 2.4982046678635546, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 12, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7291788', 'n_tokens_mistral': 1094, 'n_tokens_neox': 1025, 'n_words': 280}