def is_valid(self, bundle, request=None): errors = {} if not bundle.data: errors['Data'] = ['Data set is empty'] startingdate = bundle.data.get('startingdate') expirationdate = bundle.data.get('expirationdate') if request.method == 'POST': startingdate = get_value_if_none(startingdate, time.time()) # expires in 90 days expirationdate = get_value_if_none(expirationdate, time.time() + 86400 * 90) #Startdate and expirationdate are UTC -> convert to localtime startingdate = float(startingdate) - time.altzone expirationdate = float(expirationdate) - time.altzone bundle.data['startingdate'] = time.strftime( '%Y-%m-%d %H:%M:%S', time.gmtime(float(startingdate))) bundle.data['expirationdate'] = time.strftime( '%Y-%m-%d %H:%M:%S', time.gmtime(float(expirationdate))) if request.method == 'PUT': if startingdate: bundle.data['startingdate'] = time.strftime( '%Y-%m-%d %H:%M:%S', time.gmtime(float(startingdate))) if expirationdate: bundle.data['expirationdate'] = time.strftime( '%Y-%m-%d %H:%M:%S', time.gmtime(float(expirationdate))) if user_attached_with_dialer_settings(request): errors['user_dialer_setting'] = [ 'Your settings are not \ configured properly, Please contact the administrator.' ] if check_dialer_setting(request, check_for="campaign"): errors['chk_campaign'] = ["Too many campaigns. Max allowed %s"\ % dialer_setting_limit(request, limit_for="campaign")] frequency = bundle.data.get('frequency') if frequency: if check_dialer_setting(request, check_for="frequency", field_value=int(frequency)): errors['chk_frequency'] = ["Frequency limit of %s exceeded."\ % dialer_setting_limit(request, limit_for="frequency")] callmaxduration = bundle.data.get('callmaxduration') if callmaxduration: if check_dialer_setting(request, check_for="duration", field_value=int(callmaxduration)): errors['chk_duration'] = ["Duration limit of %s exceeded."\ % dialer_setting_limit(request, limit_for="duration")] maxretry = bundle.data.get('maxretry') if maxretry: if check_dialer_setting(request, check_for="retry", field_value=int(maxretry)): errors['chk_duration'] = ["Retries limit of %s exceeded."\ % dialer_setting_limit(request, limit_for="retry")] calltimeout = bundle.data.get('calltimeout') if calltimeout: if check_dialer_setting(request, check_for="timeout", field_value=int(calltimeout)): errors['chk_timeout'] = ["Timeout limit of %s exceeded."\ % dialer_setting_limit(request, limit_for="timeout")] aleg_gateway_id = bundle.data.get('aleg_gateway') if aleg_gateway_id: try: aleg_gateway_id = Gateway.objects.get(id=aleg_gateway_id).id bundle.data['aleg_gateway'] = '/api/v1/gateway/%s/' %\ aleg_gateway_id except: errors['chk_gateway'] = ["The Gateway ID doesn't exist!"] content_type = bundle.data.get('content_type') if content_type == 'voice_app' or content_type == 'survey': try: content_type_id = ContentType.objects\ .get(app_label=str(content_type)).id bundle.data['content_type'] = '/api/v1/contenttype/%s/' %\ content_type_id except: errors['chk_content_type'] = ["The ContentType doesn't exist!"] else: errors['chk_content_type'] = [ "Entered wrong option. Please enter \ 'voice_app' or 'survey' !" ] object_id = bundle.data.get('object_id') if object_id: try: bundle.data['object_id'] = object_id except: errors['chk_object_id'] = ["App Object ID doesn't exist!"] try: user_id = User.objects.get(username=request.user).id bundle.data['user'] = '******' % user_id except: errors['chk_user'] = ["The User doesn't exist!"] if request.method == 'POST': name_count = Campaign.objects.filter(name=bundle.data.get('name'), user=request.user).count() if (name_count != 0): errors['chk_campaign_name'] = ["The Campaign name duplicated!"] return errors
def is_valid(self, bundle, request=None): errors = {} if not bundle.data: return {'__all__': 'Please enter data'} startingdate = bundle.data.get('startingdate') expirationdate = bundle.data.get('expirationdate') if bundle.request.method == 'POST': startingdate = get_value_if_none(startingdate, time.time()) # expires in 90 days expirationdate = get_value_if_none(expirationdate, time.time() + 86400 * 90) #Startdate and expirationdate are UTC -> convert to localtime startingdate = float(startingdate) - time.altzone expirationdate = float(expirationdate) - time.altzone bundle.data['startingdate'] = time.strftime('%Y-%m-%d %H:%M:%S', time.gmtime(startingdate)) bundle.data['expirationdate'] = time.strftime('%Y-%m-%d %H:%M:%S', time.gmtime(expirationdate)) if bundle.request.method == 'PUT': if startingdate: bundle.data['startingdate'] = time.strftime( '%Y-%m-%d %H:%M:%S', time.gmtime(float(startingdate))) if expirationdate: bundle.data['expirationdate'] = time.strftime( '%Y-%m-%d %H:%M:%S', time.gmtime(float(expirationdate))) if not user_dialer_setting(bundle.request.user): errors['user_dialer_setting'] = ['Your settings are not configured properly, Please contact the administrator.'] if check_dialer_setting(request, check_for="campaign"): errors['chk_campaign'] = ["Too many campaigns. Max allowed %s" % dialer_setting_limit(bundle.request, limit_for="campaign")] frequency = bundle.data.get('frequency') if frequency: if check_dialer_setting(bundle.request, check_for="frequency", field_value=int(frequency)): errors['chk_frequency'] = ["Frequency limit of %s exceeded." % dialer_setting_limit(request, limit_for="frequency")] callmaxduration = bundle.data.get('callmaxduration') if callmaxduration: if check_dialer_setting(bundle.request, check_for="duration", field_value=int(callmaxduration)): errors['chk_duration'] = ["Duration limit of %s exceeded." % dialer_setting_limit(bundle.request, limit_for="duration")] maxretry = bundle.data.get('maxretry') if maxretry: if check_dialer_setting(bundle.request, check_for="retry", field_value=int(maxretry)): errors['chk_duration'] = ["Retries limit of %s exceeded." % dialer_setting_limit(bundle.request, limit_for="retry")] calltimeout = bundle.data.get('calltimeout') if calltimeout: if check_dialer_setting(request, check_for="timeout", field_value=int(calltimeout)): errors['chk_timeout'] = ["Timeout limit of %s exceeded." % dialer_setting_limit(request, limit_for="timeout")] aleg_gateway_id = bundle.data.get('aleg_gateway') if aleg_gateway_id: try: Gateway.objects.get(id=aleg_gateway_id) bundle.data['aleg_gateway'] = '/api/v1/gateway/%s/' % aleg_gateway_id except: errors['chk_gateway'] = ["The Gateway ID doesn't exist!"] content_type = bundle.data.get('content_type') if content_type == 'survey_template': try: content_type_id = ContentType.objects.get(model=str(content_type)).id bundle.data['content_type'] = '/api/v1/contenttype/%s/' % content_type_id except: errors['chk_content_type'] = ["The ContentType doesn't exist!"] else: errors['chk_content_type'] = ["Entered wrong option. Please enter 'survey_template' !"] object_id = bundle.data.get('object_id') if object_id: try: bundle.data['object_id'] = int(object_id) except: errors['chk_object_id'] = ["object_id must be digit"] else: errors['chk_object_id'] = ["App Object ID doesn't exist!"] if bundle.request.method == 'POST': name_count = Campaign.objects.filter(name=bundle.data.get('name'), user=bundle.request.user).count() if (name_count != 0): errors['chk_campaign_name'] = ["The Campaign name duplicated!"] # Voicemail setting is not enabled by default if settings.AMD: voicemail = bundle.data.get('voicemail') if voicemail: bundle.data['voicemail'] = voicemail amd_behavior = bundle.data.get('amd_behavior') audiofile_id = bundle.data.get('voicemail_audiofile') if audiofile_id: try: AudioFile.objects.get(id=audiofile_id) bundle.data['voicemail_audiofile'] = '/api/v1/audiofile/%s/' % audiofile_id except: errors['voicemail_audiofile'] = ["The audiofile ID doesn't exist!"] else: errors['voicemail'] = ["voicemail not enabled!"] if errors: raise BadRequest(errors) return errors
def is_valid(self, bundle, request=None): errors = {} if not bundle.data: return {'__all__': 'Please enter data'} startingdate = bundle.data.get('startingdate') expirationdate = bundle.data.get('expirationdate') if bundle.request.method == 'POST': startingdate = get_value_if_none(startingdate, time.time()) # expires in 90 days expirationdate = get_value_if_none(expirationdate, time.time() + 86400 * 90) #Startdate and expirationdate are UTC -> convert to localtime startingdate = float(startingdate) - time.altzone expirationdate = float(expirationdate) - time.altzone bundle.data['startingdate'] = time.strftime( '%Y-%m-%d %H:%M:%S', time.gmtime(startingdate)) bundle.data['expirationdate'] = time.strftime( '%Y-%m-%d %H:%M:%S', time.gmtime(expirationdate)) if bundle.request.method == 'PUT': if startingdate: bundle.data['startingdate'] = time.strftime( '%Y-%m-%d %H:%M:%S', time.gmtime(float(startingdate))) if expirationdate: bundle.data['expirationdate'] = time.strftime( '%Y-%m-%d %H:%M:%S', time.gmtime(float(expirationdate))) if not user_dialer_setting(bundle.request.user): errors['user_dialer_setting'] = [ 'Your settings are not configured properly, Please contact the administrator.' ] if check_dialer_setting(request, check_for="campaign"): errors['chk_campaign'] = [ "Too many campaigns. Max allowed %s" % dialer_setting_limit(bundle.request, limit_for="campaign") ] frequency = bundle.data.get('frequency') if frequency: if check_dialer_setting(bundle.request, check_for="frequency", field_value=int(frequency)): errors['chk_frequency'] = [ "Frequency limit of %s exceeded." % dialer_setting_limit(request, limit_for="frequency") ] callmaxduration = bundle.data.get('callmaxduration') if callmaxduration: if check_dialer_setting(bundle.request, check_for="duration", field_value=int(callmaxduration)): errors['chk_duration'] = [ "Duration limit of %s exceeded." % dialer_setting_limit(bundle.request, limit_for="duration") ] maxretry = bundle.data.get('maxretry') if maxretry: if check_dialer_setting(bundle.request, check_for="retry", field_value=int(maxretry)): errors['chk_duration'] = [ "Retries limit of %s exceeded." % dialer_setting_limit(bundle.request, limit_for="retry") ] calltimeout = bundle.data.get('calltimeout') if calltimeout: if check_dialer_setting(request, check_for="timeout", field_value=int(calltimeout)): errors['chk_timeout'] = [ "Timeout limit of %s exceeded." % dialer_setting_limit(request, limit_for="timeout") ] aleg_gateway_id = bundle.data.get('aleg_gateway') if aleg_gateway_id: try: Gateway.objects.get(id=aleg_gateway_id) bundle.data[ 'aleg_gateway'] = '/api/v1/gateway/%s/' % aleg_gateway_id except: errors['chk_gateway'] = ["The Gateway ID doesn't exist!"] content_type = bundle.data.get('content_type') if content_type == 'survey_template': try: content_type_id = ContentType.objects.get( model=str(content_type)).id bundle.data[ 'content_type'] = '/api/v1/contenttype/%s/' % content_type_id except: errors['chk_content_type'] = ["The ContentType doesn't exist!"] else: errors['chk_content_type'] = [ "Entered wrong option. Please enter 'survey_template' !" ] object_id = bundle.data.get('object_id') if object_id: try: bundle.data['object_id'] = int(object_id) except: errors['chk_object_id'] = ["object_id must be digit"] else: errors['chk_object_id'] = ["App Object ID doesn't exist!"] if bundle.request.method == 'POST': name_count = Campaign.objects.filter( name=bundle.data.get('name'), user=bundle.request.user).count() if (name_count != 0): errors['chk_campaign_name'] = ["The Campaign name duplicated!"] # Voicemail setting is not enabled by default if settings.AMD: voicemail = bundle.data.get('voicemail') if voicemail: bundle.data['voicemail'] = voicemail amd_behavior = bundle.data.get('amd_behavior') audiofile_id = bundle.data.get('voicemail_audiofile') if audiofile_id: try: AudioFile.objects.get(id=audiofile_id) bundle.data[ 'voicemail_audiofile'] = '/api/v1/audiofile/%s/' % audiofile_id except: errors['voicemail_audiofile'] = [ "The audiofile ID doesn't exist!" ] else: errors['voicemail'] = ["voicemail not enabled!"] if errors: raise BadRequest(errors) return errors
def is_valid(self, bundle, request=None): errors = {} if not bundle.data: errors['Data'] = ['Data set is empty'] startingdate = bundle.data.get('startingdate') expirationdate = bundle.data.get('expirationdate') if request.method == 'POST': startingdate = get_value_if_none(startingdate, time.time()) # expires in 90 days expirationdate = get_value_if_none(expirationdate, time.time() + 86400 * 90) #Startdate and expirationdate are UTC -> convert to localtime startingdate = float(startingdate) - time.altzone expirationdate = float(expirationdate) - time.altzone bundle.data['startingdate'] = time.strftime('%Y-%m-%d %H:%M:%S', time.gmtime(float(startingdate))) bundle.data['expirationdate'] = time.strftime('%Y-%m-%d %H:%M:%S', time.gmtime(float(expirationdate))) if request.method == 'PUT': if startingdate: bundle.data['startingdate'] = time.strftime( '%Y-%m-%d %H:%M:%S', time.gmtime(float(startingdate))) if expirationdate: bundle.data['expirationdate'] = time.strftime( '%Y-%m-%d %H:%M:%S', time.gmtime(float(expirationdate))) if user_attached_with_dialer_settings(request): errors['user_dialer_setting'] = ['Your settings are not \ configured properly, Please contact the administrator.'] if check_dialer_setting(request, check_for="campaign"): errors['chk_campaign'] = ["Too many campaigns. Max allowed %s"\ % dialer_setting_limit(request, limit_for="campaign")] frequency = bundle.data.get('frequency') if frequency: if check_dialer_setting(request, check_for="frequency", field_value=int(frequency)): errors['chk_frequency'] = ["Frequency limit of %s exceeded."\ % dialer_setting_limit(request, limit_for="frequency")] callmaxduration = bundle.data.get('callmaxduration') if callmaxduration: if check_dialer_setting(request, check_for="duration", field_value=int(callmaxduration)): errors['chk_duration'] = ["Duration limit of %s exceeded."\ % dialer_setting_limit(request, limit_for="duration")] maxretry = bundle.data.get('maxretry') if maxretry: if check_dialer_setting(request, check_for="retry", field_value=int(maxretry)): errors['chk_duration'] = ["Retries limit of %s exceeded."\ % dialer_setting_limit(request, limit_for="retry")] calltimeout = bundle.data.get('calltimeout') if calltimeout: if check_dialer_setting(request, check_for="timeout", field_value=int(calltimeout)): errors['chk_timeout'] = ["Timeout limit of %s exceeded."\ % dialer_setting_limit(request, limit_for="timeout")] aleg_gateway_id = bundle.data.get('aleg_gateway') if aleg_gateway_id: try: aleg_gateway_id = Gateway.objects.get(id=aleg_gateway_id).id bundle.data['aleg_gateway'] = '/api/v1/gateway/%s/' %\ aleg_gateway_id except: errors['chk_gateway'] = ["The Gateway ID doesn't exist!"] content_type = bundle.data.get('content_type') if content_type == 'voice_app' or content_type == 'survey': try: content_type_id = ContentType.objects\ .get(app_label=str(content_type)).id bundle.data['content_type'] = '/api/v1/contenttype/%s/' %\ content_type_id except: errors['chk_content_type'] = ["The ContentType doesn't exist!"] else: errors['chk_content_type'] = ["Entered wrong option. Please enter \ 'voice_app' or 'survey' !"] object_id = bundle.data.get('object_id') if object_id: try: bundle.data['object_id'] = object_id except: errors['chk_object_id'] = ["App Object ID doesn't exist!"] try: user_id = User.objects.get(username=request.user).id bundle.data['user'] = '******' % user_id except: errors['chk_user'] = ["The User doesn't exist!"] if request.method == 'POST': name_count = Campaign.objects.filter(name=bundle.data.get('name'), user=request.user).count() if (name_count != 0): errors['chk_campaign_name'] = ["The Campaign name duplicated!"] return errors