Browse Source

Fix bug introduced by dealing with invalid numbers.

Cleanup file copyrights as suggested by Eric Caudal.
get_caller_name.py should handle Unicode results properly.
pull/59/head
Trever L. Adams 8 years ago
parent
commit
f45be166d4
  1. 6
      base_phone_popup/popup.py
  2. 21
      freeswitch_click2dial/__init__.py
  3. 21
      freeswitch_click2dial/__openerp__.py
  4. 25
      freeswitch_click2dial/controller.py
  5. 37
      freeswitch_click2dial/freeswitch_click2dial.py
  6. 32
      freeswitch_click2dial/scripts/get_caller_name.py

6
base_phone_popup/popup.py

@ -86,11 +86,13 @@ class phone_common(orm.AbstractModel):
def incall_notify_by_extension(
self, cr, uid, number, extension_list, context=None):
assert isinstance(extension_list, list), 'extension_list must be a list'
assert isinstance(extension_list, list), \
'extension_list must be a list'
res = self.get_record_from_phone_number(
cr, uid, number, context=context)
user_ids = self.pool['res.users'].search(
cr, uid, [('internal_number', 'in', extension_list)], context=context)
cr, uid, [('internal_number', 'in', extension_list)],
context=context)
logger.debug(
'Notify incoming call from number %s to users %s'
% (number, user_ids))

21
freeswitch_click2dial/__init__.py

@ -1,23 +1,6 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# FreeSWITCH Click2Dial module for OpenERP
# Copyright (C) 2010-2013 Alexis de Lattre <alexis@via.ecp.fr>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
# (c) 2010-2013 Alexis de Lattre <alexis.delattre@akretion.com>
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html
from . import freeswitch_click2dial
from . import controller

21
freeswitch_click2dial/__openerp__.py

@ -1,23 +1,6 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# FreeSWITCH Click2dial module for OpenERP
# Copyright (C) 2010-2014 Alexis de Lattre <alexis@via.ecp.fr>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
# (c) 2010-2014 Alexis de Lattre <alexis.delattre@akretion.com>
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html
{

25
freeswitch_click2dial/controller.py

@ -1,23 +1,6 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# FreeSWITCH click2dial module for OpenERP
# Copyright (C) 2014 Alexis de Lattre (alexis@via.ecp.fr)
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
# (c) 2014 Alexis de Lattre <alexis.delattre@akretion.com>
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html
import openerp
@ -27,5 +10,5 @@ class FreeSWITCHClick2dialController(openerp.addons.web.http.Controller):
@openerp.addons.web.http.jsonrequest
def get_record_from_my_channel(self, req):
res = req.session.model('freeswitch.server').get_record_from_my_channel()
return res
FreeswitchServer = req.session.model('freeswitch.server')
return FreeswitchServer.get_record_from_my_channel()

37
freeswitch_click2dial/freeswitch_click2dial.py

@ -1,24 +1,7 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# FreeSWITCH Click2dial module for OpenERP
# Copyright (C) 2014-2016 Trever L. Adams
# Copyright (C) 2010-2013 Alexis de Lattre <alexis@via.ecp.fr>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
# (c) 2010-2013 Alexis de Lattre <alexis.delattre@akretion.com>
# (c) 2014-2016 Trever L. Adams <trever.adams@gmail.com>
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html
from openerp.osv import fields, orm
from openerp.tools.translate import _
@ -35,7 +18,8 @@ _logger = logging.getLogger(__name__)
class freeswitch_server(orm.Model):
'''FreeSWITCH server object, stores the parameters of the FreeSWITCH Servers'''
'''FreeSWITCH server object, stores the parameters of the FreeSWITCH
Servers'''
_name = "freeswitch.server"
_description = "FreeSWITCH Servers"
_columns = {
@ -232,9 +216,9 @@ class freeswitch_server(orm.Model):
except Exception, e:
pass
raise orm.except_orm(
_("Connection Test Successfull!"),
_("OpenERP can successfully login to the FreeSWITCH Event "
"Socket."))
_("Connection Test Successful!"),
_("OpenERP can successfully login to the FreeSWITCH Event "
"Socket."))
def _get_calling_number(self, cr, uid, context=None):
user, fs_server, fs_manager = self._connect_to_freeswitch(
@ -253,7 +237,7 @@ class freeswitch_server(orm.Model):
f = json.load(StringIO.StringIO(ret.getBody()))
if int(f['row_count']) > 0:
for x in range(0, int(f['row_count'])):
if (is_fq_res and f['rows'][x]['presence_id'] !=
if (is_fq_res > 0 and f['rows'][x]['presence_id'] !=
user.resource):
continue
if (f['rows'][x]['cid_num'] == user.internal_number or
@ -275,7 +259,7 @@ class freeswitch_server(orm.Model):
fs_manager.disconnect()
_logger.debug("Calling party number: '%s'" % calling_party_number)
if isinstance(calling_party_number, int):
if calling_party_number and calling_party_number.isdigit():
return calling_party_number
else:
return False
@ -466,7 +450,6 @@ class PhoneCommon(orm.AbstractModel):
channel + ' ' + fs_number + ' ' + fs_server.context + ' ' + \
'\'' + self.get_name_from_phone_number(cr, uid, fs_number) + \
'\' ' + fs_number
# raise orm.except_orm(_('Error :'), dial_string)
fs_manager.api('originate', dial_string.encode('utf-8'))
except Exception, e:
_logger.error(

32
freeswitch_click2dial/scripts/get_caller_name.py

@ -1,5 +1,9 @@
#!/usr/bin/python
# -*- encoding: utf-8 -*-
# (c) 2010-2014 Alexis de Lattre <alexis.delattre@akretion.com>
# (c) 2014-2016 Trever L. Adams <trever.adams@gmail.com>
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html
# flake8: noqa: E501
"""
Name lookup in OpenERP for incoming and outgoing calls with an
FreeSWITCH system
@ -34,8 +38,6 @@
comma (,) delimited, not :_: delimited. It is up to you to format the
extensions list appropriately. The persons who are at extensions in the
notify list will receive a poppup if so configured and if they are logged in.
The notify list actually shouldn't be in the cidlookup.conf, but should be
used when doing notify (in an on answer hook for example).
From the dialplan, do something like this <action application="set"
data="effective_caller_id_name=${cidlookup(${caller_id_number})}"/>.
@ -54,25 +56,9 @@
"""
__author__ = "Trever Adams <trever.adams@gmail.com>"
__date__ = "May 2016"
__date__ = "August 2016"
__version__ = "0.5"
# Copyright (C) 2014-2015 Trever L. Adams <trever.adams@gmail.com>
# Copyright (C) 2010-2014 Alexis de Lattre <alexis.delattre@akretion.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import sys
sys.path.append('.')
import xmlrpclib
@ -228,7 +214,7 @@ def main(name, phone_number, options):
# All SIP phones should support UTF-8...
# but in case you have analog phones over TDM
# or buggy phones, you should use the command line option --ascii
# or buggy phones, you should set options["ascii"] to True below
if options["ascii"]:
res = convert_to_ascii(res)
@ -249,7 +235,7 @@ def application(environ, start_response):
options["country"] = "US"
options["lang"] = "en"
options["ssl"] = False
options["ascii"] = True
options["ascii"] = False
options["max_size"] = 40
parameters = parse_qs(environ.get('QUERY_STRING', ''))
if 'number' in parameters:
@ -275,8 +261,10 @@ def application(environ, start_response):
except:
output = name
output = output.encode('utf-8')
status = '200 OK'
response_headers = [('Content-type', 'text/plain'),
response_headers = [('Content-type', 'text/plain; charset=utf-8'),
('Content-Length', str(len(output)))]
start_response(status, response_headers)
return [output]
Loading…
Cancel
Save