def add_or_replace_schedule(data): delete_schedules_with_name(data['name']) entity = entity_helper.get_entity_with_name(data['entity']) if entity: entity_id = entity.id else: entity_id = entity_helper.oldest_entity_id() schedule = Schedule( entity_id=entity_id, name=data['name'], timezone=data.get('timezone', 'America/Montreal'), ) world.ws.schedules.add(schedule)
def _create_schedule(name, timezone, times): schedule = Schedule( entity_id=entity_helper.oldest_entity_id(), name=name, timezone=timezone, ) opened, closed = [], [] for time in times: formatted_time = { 'hours': '%s-%s' % (time['Start hour'], time['End hour']), 'weekdays': time['Days of week'], 'monthdays': time['Days of month'], 'months': time['Months'], } if time['Status'] == 'Opened': opened.append(formatted_time) elif time['Status'] == 'Closed': closed.append(formatted_time) if opened: schedule.opened = opened if closed: schedule.closed = closed return schedule
def add_user(data_dict, step=None): user = User() if 'id' in data_dict: user.id = data_dict['id'] user.firstname = data_dict['firstname'] if 'lastname' in data_dict: user.lastname = data_dict['lastname'] if 'agentid' in data_dict: user.agent_id = int(data_dict['agentid']) if 'language' in data_dict: user.language = data_dict['language'] if 'enable_client' in data_dict: user.enable_client = bool(data_dict['enable_client']) if 'client_username' in data_dict: user.client_username = data_dict['client_username'] if 'client_password' in data_dict: user.client_password = data_dict['client_password'] if 'client_profile' in data_dict: user.client_profile = data_dict['client_profile'] if 'bsfilter' in data_dict: user.bsfilter = data_dict['bsfilter'] if 'entity_name' in data_dict: entity = entity_helper.get_entity_with_name(data_dict['entity_name']) if entity: user.entity_id = entity.id else: user.entity_id = entity_helper.oldest_entity_id() if 'line_number' in data_dict and 'line_context' in data_dict: user.line = UserLine() user.line.number = data_dict['line_number'] user.line.context = data_dict['line_context'] if 'protocol' in data_dict: user.line.protocol = data_dict['protocol'] if 'device' in data_dict: device = provd_helper.find_by_mac(data_dict['device']) if device is not None: user.line.device_id = str(device['id']) if 'voicemail_name' in data_dict and 'voicemail_number' in data_dict: user.voicemail = UserVoicemail() user.voicemail.name = data_dict['voicemail_name'] user.voicemail.number = data_dict['voicemail_number'] if 'mobile_number' in data_dict: user.mobile_number = data_dict['mobile_number'] try: ret = world.ws.users.add(user) except WebServiceRequestError as e: raise Exception('Could not add user %s %s: %s' % (user.firstname, user.lastname, e)) if not ret: return False if step is not None: _register_and_track_phone(step.scenario, data_dict) return int(ret)