def _delete_profile_if_needed(channel, profile_id): from xivo_dao.helpers.db_manager import DaoSession from xivo_dao.alchemy.cti_profile import CtiProfile from xivo_dao.alchemy.ctipresences import CtiPresences from xivo_dao.alchemy.ctiphonehints import CtiPhoneHints from xivo_dao.alchemy.ctiphonehintsgroup import CtiPhoneHintsGroup from xivo_dao.alchemy.userfeatures import UserFeatures session = DaoSession() session.begin() result = session.query(CtiProfile).filter(CtiProfile.id == profile_id).first() if result is not None: (session.query(UserFeatures).filter(UserFeatures.cti_profile_id == profile_id) .update({'cti_profile_id': None})) session.delete(result) session.commit()
def _find_all_extension_ids(channel): from xivo_dao.alchemy.extension import Extension as ExtensionSchema from xivo_dao.helpers.db_manager import DaoSession rows = (DaoSession.query(ExtensionSchema.id).filter( ExtensionSchema.context != 'xivo-features').all()) extension_ids = [e.id for e in rows] channel.send(extension_ids)
def _get_exten_info(channel, extension_id): from xivo_dao.alchemy.extension import Extension as ExtensionSchema from xivo_dao.helpers.db_manager import DaoSession extension_row = (DaoSession.query(ExtensionSchema).filter( ExtensionSchema.id == extension_id).first()) if extension_row: extension = (extension_row.exten, extension_row.type, extension_row.typeval) channel.send(extension) else: channel.send(None)
def _create_voicemail(channel, parameters): from xivo_dao.alchemy.voicemail import Voicemail as VoicemailSchema from xivo_dao.helpers.db_manager import DaoSession voicemail = VoicemailSchema() voicemail.fullname = parameters['name'] voicemail.mailbox = parameters['number'] voicemail.context = parameters['context'] if 'password' in parameters: voicemail.password = parameters['password'] if 'email' in parameters: voicemail.email = parameters['email'] if 'language' in parameters: voicemail.language = parameters['language'] if 'timezone' in parameters: voicemail.tz = parameters['timezone'] if 'max_messages' in parameters: voicemail.maxmsg = int(parameters['max_messages']) if 'attach_audio' in parameters: voicemail.attach = int(parameters['attach_audio']) if 'delete_messages' in parameters: voicemail.deletevoicemail = int(parameters['delete_messages']) if 'ask_password' in parameters: voicemail.skipcheckpass = int(not parameters['ask_password']) DaoSession.begin() DaoSession.add(voicemail) DaoSession.commit()
# 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 General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/> import unittest import datetime from mock import patch from xivo_stat import core from xivo_stat.core import _ERASE_TIME_WHEN_STARTING from xivo_dao.helpers.db_manager import DaoSession dao_sess = DaoSession() class TestCore(unittest.TestCase): def test_hour_start(self): t = datetime.datetime(2012, 1, 1, 1, 23, 37) expected = datetime.datetime(2012, 1, 1, 1, 0, 0) result = core.hour_start(t) self.assertEqual(result, expected) def test_end_of_previous_hour(self): t = datetime.datetime(2012, 1, 1, 1, 23, 37)
def _total_voicemails(channel): from xivo_dao.alchemy.voicemail import Voicemail as VoicemailSchema from xivo_dao.helpers.db_manager import DaoSession count = DaoSession.query(VoicemailSchema).count() channel.send(count)
def _create_profile(channel, profileinfo): from xivo_dao.helpers.db_manager import DaoSession from xivo_dao.alchemy.cti_profile import CtiProfile from xivo_dao.alchemy.ctipresences import CtiPresences from xivo_dao.alchemy.ctiphonehints import CtiPhoneHints from xivo_dao.alchemy.ctiphonehintsgroup import CtiPhoneHintsGroup profile = CtiProfile(**profileinfo) session = DaoSession() session.begin() session.execute('UPDATE userfeatures SET cti_profile_id = null WHERE cti_profile_id = :profile_id', {'profile_id': int(profile.id)}) session.execute('DELETE FROM cti_profile WHERE id = :profile_id', {'profile_id': int(profile.id)}) session.add(profile) session.commit()