def test_functions(self): get_switch_list() get_hangupcause_name(self.hangupcause.pk) get_hangupcause_name(2) get_hangupcause_id(self.hangupcause.code) # Template tags hangupcause_name_with_title(self.hangupcause.pk) value = {'_id': {'val': 1}} mongo_id(value, 'val') get_hc_list() get_country_id(['44', '442'])
def sw_list_with_all(): """Switch list""" list_sw = [] list_sw.append((0, _('all switches').capitalize())) for i in get_switch_list(): list_sw.append((i[0], i[1])) return list_sw
def sw_list_with_all(): """Switch list""" list_sw = [] list_sw.append((0, _('All Switches'))) sw_list = get_switch_list() for i in sw_list: list_sw.append((i[0], i[1])) return list_sw
def test_functions(self): get_switch_list() get_hangupcause_name(self.hangupcause.pk) get_hangupcause_name(2) get_hangupcause_id(self.hangupcause.code) # Template tags hangupcause_name_with_title(self.hangupcause.pk) value = {'_id': {'val': 1}} mongo_id(value, 'val') seen_unseen(value) seen_unseen('') seen_unseen_word(value) seen_unseen_word('')
class SearchForm(forms.Form): """ Form used to search on general parameters in the Customer UI. """ caller = forms.CharField(label=_('Caller ID'), required=False) caller_type = forms.ChoiceField(label='', required=False, choices=list(STRING_SEARCH_TYPE_LIST)) caller_type.widget.attrs['class'] = 'input-small' destination = forms.CharField(label=_('Destination'), required=False) destination_type = forms.ChoiceField(label='', required=False, choices=list(STRING_SEARCH_TYPE_LIST)) destination_type.widget.attrs['class'] = 'input-small' accountcode = forms.CharField(label=_('Account Code'), required=False) accountcode_type = forms.ChoiceField(label='', required=False, choices=list(STRING_SEARCH_TYPE_LIST)) accountcode_type.widget.attrs['class'] = 'input-small' duration = forms.CharField(label=_('Duration (Secs)'), required=False) duration_type = forms.ChoiceField(label='', required=False, choices=COMPARE_LIST) duration_type.widget.attrs['class'] = 'input-small' hangup_cause = forms.ChoiceField(label=_('Hangup cause'), required=False, choices=hc_list_with_all()) switch = forms.ChoiceField(label=_('Switch'), required=False, choices=get_switch_list()) country_id = forms.MultipleChoiceField(label=_('Country'), required=False, choices=country_list_with_all()) def __init__(self, *args, **kwargs): super(SearchForm, self).__init__(*args, **kwargs) self.fields['switch'].choices = sw_list_with_all() def clean_duration(self): """Retrieve valid duration & it should be integer else will raise from validation error """ duration = self.cleaned_data['duration'] if duration: try: int(duration) except: raise forms.ValidationError('%s is not a valid duration.' % duration) return duration def clean_accountcode(self): """Retrieve valid accountcode""" accountcode = self.cleaned_data['accountcode'] return accountcode
def __init__(self, user, *args, **kwargs): super(CDR_FileImport, self).__init__(*args, **kwargs) self.fields['switch_id'].choices = get_switch_list()
class SearchForm(forms.Form): """ Form used to search on general parameters in the Customer UI. """ caller = forms.CharField(label=_('Caller ID'), required=False) caller_type = forms.ChoiceField(label='', required=False, choices=STRING_SEARCH_TYPE_LIST) caller_type.widget.attrs['class'] = 'input-small' destination = forms.CharField(label=_('Destination'), required=False) destination_type = forms.ChoiceField(label='', required=False, choices=STRING_SEARCH_TYPE_LIST) destination_type.widget.attrs['class'] = 'input-small' accountcode = forms.CharField(label=_('Account Code'), required=False) accountcode_type = forms.ChoiceField(label='', required=False, choices=STRING_SEARCH_TYPE_LIST) accountcode_type.widget.attrs['class'] = 'input-small' duration = forms.CharField(label=_('Duration'), required=False) duration_type = forms.ChoiceField(label='', required=False, choices=COMPARE_LIST) duration_type.widget.attrs['class'] = 'input-small' hangup_cause = forms.ChoiceField(label=_('Hangup cause'), required=False, choices=hc_list_with_all()) switch = forms.ChoiceField(label=_('Switch'), required=False, choices=get_switch_list()) country_id = forms.MultipleChoiceField(label=_('Country'), required=False, choices=country_list_with_all(), help_text=COUNTRY_HELP_TEXT) def __init__(self, *args, **kwargs): super(SearchForm, self).__init__(*args, **kwargs) self.fields['switch'].choices = sw_list_with_all() def clean_caller(self): """ """ caller = self.cleaned_data['caller'] if caller: try: int(caller) except: raise forms.ValidationError('%s is not a valid caller.' % caller) return caller def clean_duration(self): """ """ duration = self.cleaned_data['duration'] if duration: try: int(duration) except: raise forms.ValidationError('%s is not a valid duration.' % duration) return duration def clean_accountcode(self): """ """ accountcode = self.cleaned_data['accountcode'] if accountcode: try: int(accountcode) except: raise forms.ValidationError('%s is not a valid accountcode.' % accountcode) return accountcode def clean_destination(self): """ """ destination = self.cleaned_data['destination'] if destination: try: int(destination) except: raise forms.ValidationError('%s is not a valid destination.' % destination) return destination
class CDR_FileImport(FileImport): """Admin Form : Import CSV file with phonebook CDR_FIELD_LIST""" switch = forms.ChoiceField(label=_('Switch'), choices=get_switch_list(), required=True, help_text=_('Select switch')) accountcode_csv = forms.CharField(label=_('Account code'), required=False) caller_id_number = forms.ChoiceField(label=_('caller_id_number'), required=True, choices=CDR_FIELD_LIST_NUM) caller_id_name = forms.ChoiceField(label=_('caller_id_name'), required=True, choices=ACCOUNTCODE_FIELD_LIST_NUM) destination_number = forms.ChoiceField(label=_('destination_number'), required=True, choices=CDR_FIELD_LIST_NUM) duration = forms.ChoiceField(label=_('duration'), required=True, choices=CDR_FIELD_LIST_NUM) billsec = forms.ChoiceField(label=_('billsec'), required=True, choices=CDR_FIELD_LIST_NUM) hangup_cause_id = forms.ChoiceField(label=_('hangup_cause_id'), required=True, choices=CDR_FIELD_LIST_NUM) direction = forms.ChoiceField(label=_('direction'), required=True, choices=ACCOUNTCODE_FIELD_LIST_NUM) uuid = forms.ChoiceField(label=_('uuid'), required=True, choices=ACCOUNTCODE_FIELD_LIST_NUM) remote_media_ip = forms.ChoiceField(label=_('remote_media_ip'), required=True, choices=ACCOUNTCODE_FIELD_LIST_NUM) start_uepoch = forms.ChoiceField(label=_('start_uepoch'), required=True, choices=CDR_FIELD_LIST_NUM) answer_uepoch = forms.ChoiceField(label=_('answer_uepoch'), required=True, choices=ACCOUNTCODE_FIELD_LIST_NUM) end_uepoch = forms.ChoiceField(label=_('end_uepoch'), required=True, choices=ACCOUNTCODE_FIELD_LIST_NUM) mduration = forms.ChoiceField(label=_('mduration'), required=True, choices=ACCOUNTCODE_FIELD_LIST_NUM) billmsec = forms.ChoiceField(label=_('billmsec'), required=True, choices=ACCOUNTCODE_FIELD_LIST_NUM) read_codec = forms.ChoiceField(label=_('read_codec'), required=True, choices=ACCOUNTCODE_FIELD_LIST_NUM) write_codec = forms.ChoiceField(label=_('write_codec'), required=True, choices=ACCOUNTCODE_FIELD_LIST_NUM) accountcode = forms.ChoiceField(label=_('accountcode'), required=True, choices=ACCOUNTCODE_FIELD_LIST_NUM) def __init__(self, user, *args, **kwargs): super(CDR_FileImport, self).__init__(*args, **kwargs) def clean_accountcode_csv(self): accountcode_csv = self.cleaned_data['accountcode_csv'] if accountcode_csv: try: int(accountcode_csv) except: raise forms.ValidationError('%s is not a valid accountcode.' % accountcode_csv) return accountcode_csv def clean_accountcode(self): accountcode = int(self.cleaned_data['accountcode']) accountcode_csv = self.cleaned_data['accountcode_csv'] if not accountcode_csv and accountcode == 0: raise forms.ValidationError( 'select accountcode column no else enter accountcode') return accountcode