class Incall(AbstractObject): _ATTRIBUTES = [ Attribute('id'), Attribute('number', required=True), Attribute('context', required=True), Attribute('destination', required=True), Attribute('caller_id_mode'), ] def _to_obj_dict(self, obj_dict): self._add_incall(obj_dict) self._add_dialaction(obj_dict) self._add_caller_id_mode(obj_dict) def _add_incall(self, obj_dict): obj_dict['incall'] = { 'exten': self.number, 'context': self.context, } def _add_dialaction(self, obj_dict): obj_dict['dialaction'] = {'answer': self.destination.to_obj_dict()} def _add_caller_id_mode(self, obj_dict): if self.caller_id_mode: obj_dict['callerid'] = self.caller_id_mode.to_obj_dict() @classmethod def from_list_obj_dict(cls, obj_dict): obj = cls() obj.id = int(obj_dict['id']) obj.number = obj_dict['exten'] obj.context = obj_dict['context'] return obj
class Group(AbstractObject): _ATTRIBUTES = [ Attribute('id'), Attribute('name', required=True), Attribute('number'), Attribute('context', required=True), Attribute('user_ids', default_factory=list), ] def _to_obj_dict(self, obj_dict): self._add_groupfeatures(obj_dict) self._add_queue(obj_dict) self._add_user(obj_dict) def _add_groupfeatures(self, obj_dict): groupfeatures = { 'name': self.name, 'context': self.context, 'timeout': '0' } if self.number is not None: groupfeatures['number'] = self.number obj_dict['groupfeatures'] = groupfeatures def _add_queue(self, obj_dict): obj_dict['queue'] = {} def _add_user(self, obj_dict): obj_dict['user'] = list(self.user_ids) @classmethod def from_obj_dict(cls, obj_dict): obj = cls() obj._from_groupfeatures(obj_dict['groupfeatures']) obj._from_user_ids(obj_dict['user']) return obj def _from_groupfeatures(self, groupfeatures): self.id = int(groupfeatures['id']) self.name = groupfeatures['name'] self.number = groupfeatures['number'] self.context = groupfeatures['context'] def _from_user_ids(self, user_ids): if user_ids: for user_id in user_ids: self.user_ids.append(user_id['userid']) @classmethod def from_list_obj_dict(cls, obj_dict): obj = cls() obj.id = int(obj_dict['id']) obj.name = obj_dict['name'] obj.number = obj_dict['number'] obj.context = obj_dict['context'] return obj
class Device(AbstractObject): _ATTRIBUTES = [ Attribute('id'), Attribute('ip'), Attribute('mac'), Attribute('plugin'), Attribute('vendor'), Attribute('model'), Attribute('version'), Attribute('status'), Attribute('template_id') ] @classmethod def from_obj_dict(cls, obj_dict): obj = cls() obj._from_device(obj_dict) return obj def _from_device(self, device): self.id = device.get('id') self.ip = device.get('ip') self.mac = device.get('mac') self.plugin = device.get('plugin') self.vendor = device.get('vendor') self.model = device.get('model') self.version = device.get('version') self.status = device.get('status') self.template_id = device.get('template_id') from_list_obj_dict = from_obj_dict
class CTIProfile(AbstractObject): _ATTRIBUTES = [ Attribute('id'), Attribute('name'), ] @classmethod def from_list_obj_dict(cls, obj_dict): obj = cls() obj.id = int(obj_dict['id']) obj.name = obj_dict['name'] return obj
class OutcallExten(AbstractObject): _ATTRIBUTES = [ Attribute('exten', required=True), Attribute('stripnum', default=0, required=True), Attribute('caller_id', default='', required=True), ] def _to_obj_dict(self, obj_dict): obj_dict.update({ 'id': '0', 'externprefix': '', 'prefix': '', 'exten': self.exten, 'stripnum': self.stripnum, 'callerid': self.caller_id, })
class IAXTrunk(AbstractObject): TYPE_PEER = 'peer' TYPE_USER = '******' TYPE_FRIEND = 'friend' _ATTRIBUTES = [ Attribute('id'), Attribute('name', required=True), Attribute('username'), Attribute('secret'), Attribute('context', required=True), Attribute('host'), Attribute('type', default=TYPE_PEER), Attribute('description'), Attribute('requirecalltoken', default='auto') ] def _to_obj_dict(self, obj_dict): self._to_protocol(obj_dict) self._to_trunkfeatures(obj_dict) def _to_protocol(self, obj_dict): protocol = { 'name': self.name, 'context': self.context, 'type': self.type, } if self.username is not None: protocol['username'] = self.username if self.secret is not None: protocol['secret'] = self.secret if self.host is None: protocol['host-type'] = 'dynamic' else: protocol.update({ 'host-type': 'static', 'host-static': self.host, }) if self.requirecalltoken is not None: protocol['requirecalltoken'] = self.requirecalltoken obj_dict['protocol'] = protocol def _to_trunkfeatures(self, obj_dict): trunkfeatures = {'description': self.description} obj_dict['trunkfeatures'] = trunkfeatures @classmethod def from_list_obj_dict(cls, obj_dict): obj = cls() obj.id = int(obj_dict['id']) obj.name = obj_dict['name'] return obj
class ConfRoom(AbstractObject): _ATTRIBUTES = [ Attribute('id'), Attribute('name', required=True), Attribute('number', required=True), Attribute('context', required=True), ] def _to_obj_dict(self, obj_dict): self._add_meetmefeatures(obj_dict) self._add_meetmeroom(obj_dict) def _add_meetmefeatures(self, obj_dict): obj_dict['meetmefeatures'] = { 'name': self.name, 'confno': self.number, 'context': self.context, 'maxusers': '0', 'admin_typefrom': 'none', 'user_mode': 'all', 'user_announcejoinleave': 'no', 'user_musiconhold': 'default', } def _add_meetmeroom(self, obj_dict): obj_dict['meetmeroom'] = {'confno': self.number} @classmethod def from_obj_dict(cls, obj_dict): obj = cls() obj._from_meetmefeatures(obj_dict['meetmefeatures']) return obj def _from_meetmefeatures(self, meetmefeatures): self.id = int(meetmefeatures['id']) self.name = meetmefeatures['name'] self.number = meetmefeatures['confno'] self.context = meetmefeatures['context'] @classmethod def from_list_obj_dict(cls, obj_dict): obj = cls() obj._from_meetmefeatures(obj_dict) return obj
class UserLine(AbstractObject): _ATTRIBUTES = [ Attribute('id'), Attribute('protocol', default='sip', required=True), Attribute('context', required=True), Attribute('secret'), Attribute('number'), Attribute('device_id'), Attribute('device_slot'), ] def _add_line(self, obj_dict): if self.id is not None: linefeatures = {'id': [self.id]} else: self._check_required_attributes() linefeatures = { 'protocol': [self.protocol], 'context': [self.context], 'number': [self.number], 'secret': [self.secret] } if self.device_id is not None: linefeatures['device'] = [self.device_id] if self.device_slot is not None: linefeatures['num'] = [self.device_slot] obj_dict['linefeatures'] = linefeatures
class UserVoicemail(AbstractObject): _ATTRIBUTES = [ Attribute('id'), Attribute('name', required=True), Attribute('number', required=True), Attribute('context', required=True), Attribute('password'), ] def _add_voicemail(self, obj_dict): self._check_required_attributes() voicemail_dict = { 'name': self.name, 'number': self.number, 'context': self.context } if self.password is not None: voicemail_dict['password'] = self.password obj_dict['voicemail'] = voicemail_dict
class Outcall(AbstractObject): _ATTRIBUTES = [ Attribute('id'), Attribute('name', required=True), Attribute('context', required=True), Attribute('trunks', default_factory=list), Attribute('extens', default_factory=list), ] def _to_obj_dict(self, obj_dict): if not self.trunks: raise ValueError('at least 1 trunk must be specified') self._add_outcall(obj_dict) self._add_outcalltrunk(obj_dict) self._add_dialpattern(obj_dict) def _add_outcall(self, obj_dict): obj_dict['outcall'] = { 'name': self.name, 'context': self.context, } def _add_outcalltrunk(self, obj_dict): obj_dict['outcalltrunk'] = list(self.trunks) def _add_dialpattern(self, obj_dict): if self.extens: exten_dicts = [ exten.to_obj_dict() for exten in reversed(self.extens) ] dialpattern = {} for key in exten_dicts[0]: dialpattern[key] = map(itemgetter(key), exten_dicts) dialpattern[key].append('') obj_dict['dialpattern'] = dialpattern @classmethod def from_list_obj_dict(cls, obj_dict): obj = cls() obj.id = int(obj_dict['id']) obj.name = obj_dict['name'] obj.context = obj_dict['context'] return obj
class Entity(AbstractObject): _ATTRIBUTES = [ Attribute('id'), Attribute('name', required=True), Attribute('display_name', required=True), ] def _to_obj_dict(self, obj_dict): obj_dict['name'] = self.name obj_dict['displayname'] = self.display_name @classmethod def from_obj_dict(cls, obj_dict): obj = cls() obj.id = int(obj_dict['id']) obj.name = obj_dict['name'] obj.display_name = obj_dict['displayname'] return obj from_list_obj_dict = from_obj_dict
class Agent(AbstractObject): _ATTRIBUTES = [ Attribute('id'), Attribute('firstname', required=True), Attribute('lastname'), Attribute('password'), Attribute('number', required=True), Attribute('context', required=True), Attribute('users', default_factory=list), ] def _to_obj_dict(self, obj_dict): self._to_agentfeatures(obj_dict) self._to_userselect(obj_dict) def _to_agentfeatures(self, obj_dict): agentfeatures = { 'numgroup': '1', 'autologoff': '0', 'firstname': self.firstname, 'number': self.number, 'context': self.context, } if self.lastname is not None: agentfeatures['lastname'] = self.lastname if self.password is not None: agentfeatures['passwd'] = self.password obj_dict['agentfeatures'] = agentfeatures def _to_userselect(self, obj_dict): obj_dict['user-select'] = list(self.users) @classmethod def from_obj_dict(cls, obj_dict): obj = cls() obj._from_agentfeatures(obj_dict['agentfeatures']) obj._from_usermember(obj_dict['usermember']) return obj def _from_agentfeatures(self, agentfeatures): self.id = agentfeatures['id'] self.firstname = agentfeatures['firstname'] self.lastname = agentfeatures['lastname'] self.password = agentfeatures['passwd'] self.number = agentfeatures['number'] self.context = agentfeatures['context'] def _from_usermember(self, usermember): if usermember: self.users = [user['id'] for user in usermember] @classmethod def from_list_obj_dict(cls, obj_dict): obj = cls() obj._from_agentfeatures(obj_dict) return obj
class SCCPGeneralSettings(AbstractObject): _ATTRIBUTES = [ Attribute('directmedia', required=True), Attribute('dialtimeout', required=True), Attribute('language', required=True) ] def _to_obj_dict(self, obj_dict): obj_dict['directmedia'] = int(self.directmedia) obj_dict['dialtimeout'] = int(self.dialtimeout) obj_dict['language'] = unicode(self.language) @classmethod def from_obj_dict(cls, obj_dict): obj = cls() obj._from_sccpgeneralsettings(obj_dict['sccpgeneralsettings']) return obj def _from_sccpgeneralsettings(self, sccpgeneralsettings): self.directmedia = convert_directmedia( sccpgeneralsettings['directmedia']) self.dialtimeout = int(sccpgeneralsettings['dialtimeout']) self.language = unicode(sccpgeneralsettings['language'])
class Voicemail(AbstractObject): _ATTRIBUTES = [ Attribute('id'), Attribute('mailbox', required=True), Attribute('fullname', required=True), Attribute('password'), Attribute('email'), Attribute('tz'), ] def _to_obj_dict(self, obj_dict): self._to_voicemail(obj_dict) def _to_voicemail(self, obj_dict): voicemail = { 'mailbox': self.mailbox, 'fullname': self.fullname, 'password': self.password, 'email': self.email, 'tz': self.tz, } obj_dict['voicemail'] = voicemail @classmethod def from_obj_dict(cls, obj_dict): obj = cls() obj._from_voicemail(obj_dict['voicemail']) return obj def _from_voicemail(self, voicemail): self.id = int(voicemail['uniqueid']) self.mailbox = voicemail['mailbox'] self.fullname = voicemail['fullname'] self.password = voicemail['password'] self.email = voicemail['email'] self.tz = voicemail['tz'] @classmethod def from_list_obj_dict(cls, obj_dict): obj = cls() obj._from_voicemail(obj_dict) return obj
class Statconf(AbstractObject): _ATTRIBUTES = [ Attribute('id'), Attribute('name', required=True), Attribute('hour_start', required=True), Attribute('hour_end', required=True), Attribute('dbegcache', required=True), Attribute('dendcache', required=True, default=0), Attribute('default_delta', required=True, default=0), Attribute('timezone'), Attribute('period1', required=True, default='0-10'), Attribute('period2', default='10-20'), Attribute('period3', default='20-30'), Attribute('period4', default='30-40'), Attribute('period5', default='40'), Attribute('monday'), Attribute('tuesday'), Attribute('wednesday'), Attribute('thursday'), Attribute('friday'), Attribute('saturday'), Attribute('sunday'), Attribute('queue', default_factory=list), Attribute('queue_qos'), Attribute('agent', default_factory=list), Attribute('xivouser', default_factory=list), ] def _to_obj_dict(self, obj_dict): self._add_stats_conf(obj_dict) self._add_queue(obj_dict) self._add_agent(obj_dict) self._add_xivouser(obj_dict) def _add_stats_conf(self, obj_dict): obj_dict['stats_conf'] = { 'name': self.name, 'hour_start': self.hour_start, 'hour_end': self.hour_end, 'dbegcache': self.dbegcache, 'dendcache': self.dendcache, 'default_delta': self.default_delta, 'timezone': self.timezone, 'period1': self.period1, 'period2': self.period2, 'period3': self.period3, 'period4': self.period4, 'period5': self.period5, 'monday': self.monday, 'tuesday': self.tuesday, 'wednesday': self.wednesday, 'thursday': self.thursday, 'friday': self.friday, 'saturday': self.saturday, 'sunday': self.sunday, } def _add_queue(self, obj_dict): if self.queue: if not self.queue_qos: raise ValueError('You must set queue_qos') obj_dict['queue'] = list(self.queue) obj_dict['queue_qos'] = self.queue_qos def _add_agent(self, obj_dict): if self.agent: obj_dict['agent'] = list(self.agent) def _add_xivouser(self, obj_dict): if self.xivouser: obj_dict['xivouser'] = list(self.xivouser) @classmethod def from_list_obj_dict(cls, obj_dict): obj = cls() obj.id = int(obj_dict['id']) obj.name = obj_dict['name'] obj.timezone = obj_dict['timezone'] obj.hour_start = obj_dict['hour_start'] obj.hour_end = obj_dict['hour_end'] obj.dbegcache = obj_dict['dbegcache'] obj.dendcache = obj_dict['dendcache'] obj.default_delta = obj_dict['default_delta'] obj.period1 = obj_dict['period1'] obj.period2 = obj_dict['period2'] obj.period3 = obj_dict['period3'] obj.period4 = obj_dict['period4'] obj.period5 = obj_dict['period5'] obj.monday = obj_dict['monday'] obj.tuesday = obj_dict['tuesday'] obj.wednesday = obj_dict['wednesday'] obj.thursday = obj_dict['thursday'] obj.friday = obj_dict['friday'] obj.saturday = obj_dict['saturday'] obj.sunday = obj_dict['sunday'] return obj
class Line(AbstractObject): PROTOCOL_SIP = 'sip' PROTOCOL_CUSTOM = 'custom' PROTOCOL_SCCP = 'sccp' _ATTRIBUTES = [ Attribute('id'), Attribute('protocol', required=True), Attribute('name', required=True), Attribute('number'), Attribute('context', default='default', required=True), Attribute('user_id'), Attribute('type'), Attribute('username'), Attribute('secret', default='', required=True), Attribute('language'), Attribute('host'), Attribute('port'), Attribute('interface'), ] def _from_linefeatures(self, linefeatures): self.id = linefeatures['id'] self.protocol = linefeatures['protocol'] self.number = linefeatures['number'] self.context = linefeatures['context'] def _from_protocol(self, protocol_name, protocol): if protocol_name == self.PROTOCOL_SIP: self._from_sip_protocol(protocol) elif protocol_name == self.PROTOCOL_CUSTOM: self._from_custom_protocol(protocol) elif protocol_name == self.PROTOCOL_SCCP: self._from_sccp_protocol(protocol) def _from_sip_protocol(self, protocol): self.name = protocol['name'] self.type = protocol['type'] self.username = protocol['username'] self.secret = protocol['secret'] self.language = protocol['language'] self.host = protocol['host'] self.port = protocol['port'] def _from_custom_protocol(self, protocol): self.name = protocol['name'] self.interface = protocol['interface'] def _from_sccp_protocol(self, protocol): self.name = protocol['name'] @classmethod def from_list_obj_dict(cls, obj_dict): obj = cls() obj._from_linefeatures(obj_dict) obj._from_protocol(obj.protocol, obj_dict) return obj
class CEL(AbstractObject): _ATTRIBUTES = [ Attribute('id'), Attribute('eventtype'), Attribute('eventtime'), Attribute('userdeftype'), Attribute('cid_name'), Attribute('cid_num'), Attribute('cid_ani'), Attribute('cid_rdnis'), Attribute('cid_dnid'), Attribute('exten'), Attribute('context'), Attribute('channame'), Attribute('appname'), Attribute('appdata'), Attribute('amaflags'), Attribute('accountcode'), Attribute('peeraccount'), Attribute('uniqueid'), Attribute('linkedid'), Attribute('userfield'), Attribute('peer'), ] @classmethod def from_list_obj_dict(cls, obj_dict): obj = cls() obj.id = obj_dict['id'] obj.eventtype = obj_dict['eventtype'] obj.eventtime = obj_dict['eventtime'] obj.userdeftype = obj_dict['userdeftype'] obj.cid_name = obj_dict['cid_name'] obj.cid_num = obj_dict['cid_num'] obj.cid_ani = obj_dict['cid_ani'] obj.cid_rdnis = obj_dict['cid_rdnis'] obj.cid_dnid = obj_dict['cid_dnid'] obj.exten = obj_dict['exten'] obj.context = obj_dict['context'] obj.channame = obj_dict['channame'] obj.appname = obj_dict['appname'] obj.appdata = obj_dict['appdata'] obj.amaflags = obj_dict['amaflags'] obj.accountcode = obj_dict['accountcode'] obj.peeraccount = obj_dict['peeraccount'] obj.uniqueid = obj_dict['uniqueid'] obj.linkedid = obj_dict['linkedid'] obj.userfield = obj_dict['userfield'] obj.peer = obj_dict['peer'] return obj
class CustomTrunk(AbstractObject): _ATTRIBUTES = [ Attribute('id'), Attribute('name', required=True), Attribute('interface', required=True), Attribute('protocol', default='custom'), Attribute('protocolid'), Attribute('registerid'), Attribute('registercommented'), Attribute('context'), Attribute('intfsuffix'), Attribute('category'), Attribute('registerid'), Attribute('description'), Attribute('commented') ] def _to_obj_dict(self, obj_dict): self._to_protocol(obj_dict) self._to_trunkfeatures(obj_dict) def _to_protocol(self, obj_dict): protocol = { 'name': self.name, 'context': self.context, 'interface': self.interface, 'protocol': self.protocol, } obj_dict['protocol'] = protocol def _to_trunkfeatures(self, obj_dict): trunkfeatures = { 'protocolid': self.protocolid, 'registerid': self.registerid, 'registercommented': self.registercommented, 'description': self.description, } obj_dict['trunkfeatures'] = trunkfeatures @classmethod def from_list_obj_dict(cls, obj_dict): obj = cls() obj.id = int(obj_dict['id']) obj.name = obj_dict['name'] obj.interface = obj_dict['interface'] return obj
class Context(AbstractObject): TYPE_INTERNAL = 'internal' TYPE_INCALL = 'incall' TYPE_OUTCALL = 'outcall' _ATTRIBUTES = [ Attribute('id'), Attribute('name', required=True), Attribute('display_name', required=True), Attribute('entity', required=True), Attribute('type', default=TYPE_INCALL, required=True), Attribute('context_include', default_factory=list), Attribute('users', default_factory=list), Attribute('groups', default_factory=list), Attribute('queues', default_factory=list), Attribute('conf_rooms', default_factory=list), Attribute('incalls', default_factory=list), ] def _to_obj_dict(self, obj_dict): self._to_context(obj_dict) self._to_contextinclude(obj_dict) self._to_contextnumbers(obj_dict) def _to_context(self, obj_dict): context = { 'name': self.name, 'displayname': self.display_name, 'entity': self.entity, 'contexttype': self.type, } obj_dict['context'] = context def _to_contextinclude(self, obj_dict): obj_dict['contextinclude'] = [] if self.context_include: for context_include in self.context_include: obj_dict['contextinclude'].append(context_include['include']) def _to_contextnumbers(self, obj_dict): contextnumbers = {} if self.users: contextnumbers['user'] = self._to_contextnumbers_value(self.users) if self.groups: contextnumbers['group'] = self._to_contextnumbers_value( self.groups) if self.queues: contextnumbers['queue'] = self._to_contextnumbers_value( self.queues) if self.conf_rooms: contextnumbers['meetme'] = self._to_contextnumbers_value( self.conf_rooms) if self.incalls: contextnumbers['incall'] = self._to_contextnumbers_value( self.incalls, include_didlength=True) if contextnumbers: obj_dict['contextnumbers'] = contextnumbers def _to_contextnumbers_value(self, context_ranges, include_didlength=False): return [ context_range.to_obj_dict(include_didlength=include_didlength) for context_range in context_ranges ] @classmethod def from_obj_dict(cls, obj_dict): obj = cls() obj._from_context(obj_dict['context']) obj._from_contextinclude(obj_dict['contextinclude']) obj._from_contextnumbers(obj_dict['contextnumbers']) return obj def _from_context(self, context): self.id = context['name'] self.name = context['name'] self.display_name = context['displayname'] self.entity = context['entity'] self.type = context['contexttype'] def _from_contextinclude(self, contextinclude): self.context_include = contextinclude def _from_contextnumbers(self, contextnumbers): if contextnumbers: if 'user' in contextnumbers: self.users = self._from_contextnumbers_value( contextnumbers['user']) if 'group' in contextnumbers: self.groups = self._from_contextnumbers_value( contextnumbers['group']) if 'queue' in contextnumbers: self.queues = self._from_contextnumbers_value( contextnumbers['queue']) if 'meetme' in contextnumbers: self.conf_rooms = self._from_contextnumbers_value( contextnumbers['meetme']) if 'incall' in contextnumbers: self.incalls = self._from_contextnumbers_value( contextnumbers['incall']) def _from_contextnumbers_value(self, obj_dicts): return [ContextRange.from_obj_dict(obj_dict) for obj_dict in obj_dicts] @classmethod def from_list_obj_dict(cls, obj_dict): obj = cls() obj._from_context(obj_dict['context']) return obj
class Schedule(AbstractObject): _ATTRIBUTES = [ Attribute('id'), Attribute('entity_id'), Attribute('name', required=True), Attribute('timezone', required=True), Attribute('fallback_action'), Attribute('fallback_actiontype'), Attribute('fallback_action_destination_id'), Attribute('fallback_action_destination_args', default_factory=list), Attribute('description'), Attribute('opened', default_factory=list), Attribute('closed', default_factory=list), ] def __eq__(self, other): if self.name != other.name or self.timezone != other.timezone: return False return _same_hours(self.opened, other.opened) and _same_hours( self.closed, other.closed) def _to_obj_dict(self, obj_dict): self._to_schedule(obj_dict) self._to_dialaction(obj_dict) self._to_closed(obj_dict) self._to_opened(obj_dict) def _to_schedule(self, obj_dict): schedule = { 'entity_id': self.entity_id, 'name': self.name, 'timezone': self.timezone, 'description': self.description, } obj_dict['schedule'] = schedule def _to_dialaction(self, obj_dict): if self.fallback_actiontype is None: destination = {"actiontype": 'none'} else: destination = { "actiontype": self.fallback_actiontype, } if self.fallback_action: destination['action'] = self.fallback_action if self.fallback_action_destination_id: destination['actionarg1'] = self.fallback_action_destination_id if self.fallback_action_destination_args: destination[ 'actionarg2'] = self.fallback_action_destination_args obj_dict['dialaction'] = {} obj_dict['dialaction']['schedule_fallback'] = destination def _to_opened(self, obj_dict): obj_dict['opened'] = list(self.opened) def _to_closed(self, obj_dict): obj_dict['closed'] = list(self.closed) @classmethod def from_obj_dict(cls, obj_dict): obj = cls() obj._from_schedule(obj_dict['schedule']) obj._from_opened(obj_dict['opened']) obj._from_closed(obj_dict['closed']) return obj def _from_schedule(self, schedule): self.id = int(schedule['id']) self.entity_id = int( schedule['entity_id']) if schedule['entity_id'] else None self.name = schedule['name'] self.timezone = schedule['timezone'] self.fallback_action = schedule['fallback_action'] self.fallback_action_destination_id = schedule['fallback_actionid'] self.fallback_action_destination_args = schedule['fallback_actionargs'] self.description = schedule['description'] def _from_closed(self, closed): self.closed = closed def _from_opened(self, opened): self.opened = opened @classmethod def from_list_obj_dict(cls, obj_dict): obj = cls() obj._from_schedule(obj_dict) return obj
class User(AbstractObject): _ATTRIBUTES = [ Attribute('id'), Attribute('entity_id', required=True, default=1), Attribute('firstname', required=True), Attribute('lastname'), Attribute('language'), Attribute('agent_id'), Attribute('enable_client'), Attribute('client_username'), Attribute('client_password'), Attribute('client_profile'), Attribute('client_profile_id'), Attribute('enable_hint', default=True), Attribute('enable_transfer', default=True), Attribute('bsfilter', default='no'), Attribute('line'), Attribute('voicemail'), Attribute('mobile_number'), ] def _to_obj_dict(self, obj_dict): if self.voicemail is not None and self.language is None: raise ValueError('language must be set when adding voicemail') self._add_userfeatures(obj_dict) self._add_line(obj_dict) self._add_voicemail(obj_dict) self._add_dialaction(obj_dict) def _add_userfeatures(self, obj_dict): userfeatures = { 'musiconhold': 'default', 'entityid': self.entity_id, # TODO check why default values for enablexfer (and # other that we don't see) aren't working 'enablexfer': True, 'firstname': self.firstname, } if self.lastname is not None: userfeatures['lastname'] = self.lastname if self.language is not None: userfeatures['language'] = self.language if self.enable_client is not None: userfeatures['enableclient'] = self.enable_client if self.client_username is not None: userfeatures['loginclient'] = self.client_username if self.client_password is not None: userfeatures['passwdclient'] = self.client_password if self.client_profile is not None: userfeatures['profileclient'] = self.client_profile elif self.client_profile_id is not None: userfeatures['cti_profile_id'] = self.client_profile_id if self.enable_hint is not None: userfeatures['enablehint'] = self.enable_hint if self.agent_id is not None: userfeatures['agentid'] = self.agent_id if self.bsfilter is not None: userfeatures['bsfilter'] = self.bsfilter if self.mobile_number is not None: userfeatures['mobilephonenumber'] = self.mobile_number obj_dict['userfeatures'] = userfeatures def _add_line(self, obj_dict): if self.line: self.line._add_line(obj_dict) def _add_voicemail(self, obj_dict): if self.voicemail: self.voicemail._add_voicemail(obj_dict) def _add_dialaction(self, obj_dict): dialaction = { 'noanswer': { 'actiontype': 'none', }, 'busy': { 'actiontype': 'none', }, 'congestion': { 'actiontype': 'none', }, 'chanunavail': { 'actiontype': 'none', }, } obj_dict['dialaction'] = dialaction @classmethod def from_list_obj_dict(cls, obj_dict): obj = cls() obj.id = int(obj_dict['id']) obj.entity_id = obj_dict['entityid'] obj.firstname = obj_dict['firstname'] obj.lastname = obj_dict['lastname'] obj.enable_client = obj_dict['enableclient'] obj.client_username = obj_dict['loginclient'] obj.client_password = obj_dict['passwdclient'] obj.client_profile_id = obj_dict['cti_profile_id'] obj.bsfilter = obj_dict['bsfilter'] obj.enable_transfer = obj_dict['enablexfer'] if obj_dict['agentid']: obj.agent_id = int(obj_dict['agentid']) obj.mobile_number = obj_dict['mobilephonenumber'] return obj