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()
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 _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()
Exemple #4
0
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()