def __init__(self, user, *args, **kwargs): super(CampaignForm, self).__init__(*args, **kwargs) instance = getattr(self, 'instance', None) self.fields['campaign_code'].initial = get_unique_code(length=5) self.fields['description'].widget.attrs['class'] = "input-xlarge" if user: self.fields['ds_user'].initial = user list_gw = [] list_pb = [] dnc_list = [] list_pb.append((0, '---')) list = Phonebook.objects.values_list('id', 'name')\ .filter(user=user).order_by('id') for l in list: list_pb.append((l[0], l[1])) self.fields['phonebook'].choices = list_pb list = user.get_profile().userprofile_gateway.all() gw_list = ((l.id, l.name) for l in list) dnc_list.append(('', '---')) list = DNC.objects.values_list('id', 'name')\ .filter(user=user).order_by('id') for l in list: dnc_list.append((l[0], l[1])) self.fields['dnc'].choices = dnc_list for i in gw_list: list_gw.append((i[0], i[1])) self.fields['aleg_gateway'].choices = list_gw if instance.has_been_duplicated: from survey.models import Survey available_objects = Survey.objects.filter(user=user, campaign=instance) object_choices = get_object_choices(available_objects) self.fields['content_object'].widget.attrs['readonly'] = True else: from survey.models import Survey_template available_objects = Survey_template.objects.filter(user=user) object_choices = get_object_choices(available_objects) self.fields['content_object'].choices = object_choices # Voicemail setting is not enabled by default if settings.AMD: from survey.forms import get_audiofile_list self.fields['voicemail_audiofile'].choices = get_audiofile_list(user) # if campaign is running if instance.status == CAMPAIGN_STATUS.START: self.fields['name'].widget.attrs['readonly'] = True self.fields['caller_name'].widget.attrs['readonly'] = True self.fields['callerid'].widget.attrs['readonly'] = True self.fields['extra_data'].widget.attrs['readonly'] = True self.fields['phonebook'].widget.attrs['disabled'] = 'disabled' selected_phonebook = '' if instance.phonebook.all(): selected_phonebook = \ ",".join(["%s" % (i.id) for i in instance.phonebook.all()]) self.fields['selected_phonebook'].initial = selected_phonebook self.fields['content_object'].widget.attrs['disabled'] = 'disabled' self.fields['content_object'].required = False self.fields['selected_content_object'].initial = "type:%s-id:%s" \ % (instance.content_type.id, instance.object_id)
def __init__(self, user, *args, **kwargs): super(CampaignForm, self).__init__(*args, **kwargs) self.user = user self.helper = FormHelper() if self.instance.id: form_action = common_submit_buttons(default_action='update') else: form_action = common_submit_buttons(default_action='add') week_days = [ 'monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday', 'sunday' ] week_days_html = """<div class="row"><div class="col-md-12 col-xs-6">""" for i in week_days: week_days_html += """ <div class="col-md-3"> <div class="btn-group" data-toggle="buttons"> <label for="{{ form.%s.auto_id }}">{{ form.%s.label }}</label><br/> <div class="make-switch switch-small"> {{ form.%s }} </div> </div> </div> """ % (i, i, i) week_days_html += """</div></div>""" css_class = 'col-md-6' self.helper.layout = Layout( Field('campaign_code'), TabHolder( Tab(_('general').title(), Div(Div(Fieldset(_('general settings').title()), css_class='col-md-12'), Div('name', css_class=css_class), Div('callerid', css_class=css_class), Div('caller_name', css_class=css_class), Div('content_object', css_class=css_class), css_class='row'), Div(Div('extra_data', css_class=css_class), Div('dnc', css_class=css_class), Div('description', css_class=css_class), Div('phonebook', css_class=css_class), css_class='row'), form_action, css_class='well'), Tab('Dialer', Div(Div(Fieldset(_('dialer settings').title()), css_class='col-md-12'), Div('aleg_gateway', css_class=css_class), Div('frequency', css_class=css_class), Div('callmaxduration', css_class=css_class), Div('maxretry', css_class=css_class), Div('intervalretry', css_class=css_class), Div('calltimeout', css_class=css_class), Div(Fieldset(_('dialer completion settings').title()), css_class='col-md-12'), Div('completion_maxretry', css_class=css_class), Div('completion_intervalretry', css_class=css_class), Div('sms_gateway', css_class=css_class), css_class='row'), form_action, css_class='well'), Tab('schedule', Div(Div(Fieldset(_('schedule settings').title()), css_class='col-md-12'), Div(HTML("""<label>%s<label>""" % (_('week days').capitalize())), css_class="col-md-3"), HTML(week_days_html), HTML("""<div> </div>"""), Div('startingdate', css_class=css_class), Div('expirationdate', css_class=css_class), Div('daily_start_time', css_class=css_class), Div('daily_stop_time', css_class=css_class), css_class='row'), form_action, css_class='well'), ), ) if settings.AMD: amd_layot = Tab(_('voicemail').capitalize(), Div(Div(Fieldset(_('voicemail settings').title()), css_class='col-md-12'), Div(HTML(""" <div class="btn-group" data-toggle="buttons"> <label for="{{ form.voicemail.auto_id }}">{{ form.voicemail.label }}</label> <br/> <div class="make-switch switch-small"> {{ form.voicemail }} </div> </div> """), css_class='col-md-12 col-xs-10'), HTML("""<div> </div>"""), Div('amd_behavior', css_class=css_class), Div('voicemail_audiofile', css_class=css_class), css_class='row'), form_action, css_class='well') self.helper.layout[1].insert(2, amd_layot) # hidden var self.helper.layout.append(Field('selected_phonebook')) self.helper.layout.append(Field('selected_content_object')) instance = getattr(self, 'instance', None) self.fields['campaign_code'].initial = get_unique_code(length=5) if user: list_gw = [] dnc_list = [] phonebook_list = get_phonebook_list(user) if not phonebook_list: phonebook_list = [] phonebook_list.append(('', '---')) self.fields['phonebook'].choices = phonebook_list self.fields['phonebook'].initial = str(phonebook_list[0][0]) gateway_list = UserProfile.objects.get( user=user).userprofile_gateway.all() gw_list = ((l.id, l.name) for l in gateway_list) dnc_list.append(('', '---')) dnc_obj_list = DNC.objects.values_list( 'id', 'name').filter(user=user).order_by('id') for l in dnc_obj_list: dnc_list.append((l[0], l[1])) self.fields['dnc'].choices = dnc_list for i in gw_list: list_gw.append((i[0], i[1])) self.fields['aleg_gateway'].choices = UserProfile.objects.get(user=user)\ .userprofile_gateway.all().values_list('id', 'name') if instance.has_been_duplicated: from survey.models import Survey available_objects = Survey.objects.filter(user=user, campaign=instance) object_choices = get_object_choices(available_objects) self.fields['content_object'].widget.attrs['readonly'] = True else: from survey.models import Survey_template available_objects = Survey_template.objects.filter(user=user) object_choices = get_object_choices(available_objects) self.fields['content_object'].choices = object_choices # Voicemail setting is not enabled by default if settings.AMD: from survey.forms import get_audiofile_list self.fields[ 'voicemail_audiofile'].choices = get_audiofile_list(user) # If campaign is running or has been started if instance.status == CAMPAIGN_STATUS.START or instance.has_been_started: self.fields['name'].widget.attrs['readonly'] = True self.fields['caller_name'].widget.attrs['readonly'] = True self.fields['callerid'].widget.attrs['readonly'] = True self.fields['extra_data'].widget.attrs['readonly'] = True self.fields['phonebook'].widget.attrs['readonly'] = True self.fields['lead_disposition'].widget.attrs['readonly'] = True self.fields['dnc'].widget.attrs['readonly'] = True self.fields['aleg_gateway'].widget.attrs['readonly'] = True self.fields['sms_gateway'].widget.attrs['readonly'] = True self.fields['voicemail'].widget.attrs['readonly'] = True self.fields['amd_behavior'].widget.attrs['readonly'] = True self.fields['voicemail_audiofile'].widget.attrs['readonly'] = True selected_phonebook = '' if instance.phonebook.all(): selected_phonebook = ",".join( ["%s" % (i.id) for i in instance.phonebook.all()]) self.fields['selected_phonebook'].initial = selected_phonebook self.fields['content_object'].widget.attrs['disabled'] = 'disabled' self.fields['content_object'].required = False self.fields['selected_content_object'].initial = "type:%s-id:%s" % \ (instance.content_type.id, instance.object_id)
def __init__(self, user, *args, **kwargs): super(CampaignForm, self).__init__(*args, **kwargs) self.user = user self.helper = FormHelper() if self.instance.id: form_action = common_submit_buttons(default_action='update') else: form_action = common_submit_buttons(default_action='add') week_days = ['monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday', 'sunday'] week_days_html = """<div class="row"><div class="col-md-12 col-xs-6">""" for i in week_days: week_days_html += """ <div class="col-md-3"> <div class="btn-group" data-toggle="buttons"> <label for="{{ form.%s.auto_id }}">{{ form.%s.label }}</label><br/> <div class="make-switch switch-small"> {{ form.%s }} </div> </div> </div> """ % (i, i, i) week_days_html += """</div></div>""" css_class = 'col-md-6' self.helper.layout = Layout( Field('campaign_code'), TabHolder( Tab(_('general').title(), Div( Div(Fieldset(_('general settings').title()), css_class='col-md-12'), Div('name', css_class=css_class), Div('callerid', css_class=css_class), Div('caller_name', css_class=css_class), Div('content_object', css_class=css_class), css_class='row' ), Div( Div('extra_data', css_class=css_class), Div('dnc', css_class=css_class), Div('description', css_class=css_class), Div('phonebook', css_class=css_class), css_class='row' ), form_action, css_class='well' ), Tab('Dialer', Div( Div(Fieldset(_('dialer settings').title()), css_class='col-md-12'), Div('aleg_gateway', css_class=css_class), Div('frequency', css_class=css_class), Div('callmaxduration', css_class=css_class), Div('maxretry', css_class=css_class), Div('intervalretry', css_class=css_class), Div('calltimeout', css_class=css_class), Div(Fieldset(_('dialer completion settings').title()), css_class='col-md-12'), Div('completion_maxretry', css_class=css_class), Div('completion_intervalretry', css_class=css_class), Div('sms_gateway', css_class=css_class), css_class='row' ), form_action, css_class='well' ), Tab('schedule', Div( Div(Fieldset(_('schedule settings').title()), css_class='col-md-12'), Div(HTML("""<label>%s<label>""" % (_('week days').capitalize())), css_class="col-md-3"), HTML(week_days_html), HTML("""<div> </div>"""), Div('startingdate', css_class=css_class), Div('expirationdate', css_class=css_class), Div('daily_start_time', css_class=css_class), Div('daily_stop_time', css_class=css_class), css_class='row' ), form_action, css_class='well' ), ), ) if settings.AMD: amd_layot = Tab(_('voicemail').capitalize(), Div( Div(Fieldset(_('voicemail settings').title()), css_class='col-md-12'), Div(HTML(""" <div class="btn-group" data-toggle="buttons"> <label for="{{ form.voicemail.auto_id }}">{{ form.voicemail.label }}</label> <br/> <div class="make-switch switch-small"> {{ form.voicemail }} </div> </div> """), css_class='col-md-12 col-xs-10'), HTML("""<div> </div>"""), Div('amd_behavior', css_class=css_class), Div('voicemail_audiofile', css_class=css_class), css_class='row' ), form_action, css_class='well' ) self.helper.layout[1].insert(2, amd_layot) # hidden var self.helper.layout.append(Field('selected_phonebook')) self.helper.layout.append(Field('selected_content_object')) instance = getattr(self, 'instance', None) self.fields['campaign_code'].initial = get_unique_code(length=5) if user: list_gw = [] dnc_list = [] phonebook_list = get_phonebook_list(user) if not phonebook_list: phonebook_list = [] phonebook_list.append(('', '---')) self.fields['phonebook'].choices = phonebook_list self.fields['phonebook'].initial = str(phonebook_list[0][0]) gateway_list = UserProfile.objects.get(user=user).userprofile_gateway.all() gw_list = ((l.id, l.name) for l in gateway_list) dnc_list.append(('', '---')) dnc_obj_list = DNC.objects.values_list('id', 'name').filter(user=user).order_by('id') for l in dnc_obj_list: dnc_list.append((l[0], l[1])) self.fields['dnc'].choices = dnc_list for i in gw_list: list_gw.append((i[0], i[1])) self.fields['aleg_gateway'].choices = UserProfile.objects.get(user=user)\ .userprofile_gateway.all().values_list('id', 'name') if instance.has_been_duplicated: from survey.models import Survey available_objects = Survey.objects.filter(user=user, campaign=instance) object_choices = get_object_choices(available_objects) self.fields['content_object'].widget.attrs['readonly'] = True else: from survey.models import Survey_template available_objects = Survey_template.objects.filter(user=user) object_choices = get_object_choices(available_objects) self.fields['content_object'].choices = object_choices # Voicemail setting is not enabled by default if settings.AMD: from survey.forms import get_audiofile_list self.fields['voicemail_audiofile'].choices = get_audiofile_list(user) # If campaign is running or has been started if instance.status == CAMPAIGN_STATUS.START or instance.has_been_started: self.fields['name'].widget.attrs['readonly'] = True self.fields['caller_name'].widget.attrs['readonly'] = True self.fields['callerid'].widget.attrs['readonly'] = True self.fields['extra_data'].widget.attrs['readonly'] = True self.fields['phonebook'].widget.attrs['readonly'] = True self.fields['lead_disposition'].widget.attrs['readonly'] = True self.fields['dnc'].widget.attrs['readonly'] = True self.fields['aleg_gateway'].widget.attrs['readonly'] = True self.fields['sms_gateway'].widget.attrs['readonly'] = True self.fields['voicemail'].widget.attrs['readonly'] = True self.fields['amd_behavior'].widget.attrs['readonly'] = True self.fields['voicemail_audiofile'].widget.attrs['readonly'] = True selected_phonebook = '' if instance.phonebook.all(): selected_phonebook = ",".join(["%s" % (i.id) for i in instance.phonebook.all()]) self.fields['selected_phonebook'].initial = selected_phonebook self.fields['content_object'].widget.attrs['disabled'] = 'disabled' self.fields['content_object'].required = False self.fields['selected_content_object'].initial = "type:%s-id:%s" % \ (instance.content_type.id, instance.object_id)
def __init__(self, user, *args, **kwargs): super(CampaignForm, self).__init__(*args, **kwargs) instance = getattr(self, 'instance', None) self.fields['campaign_code'].initial = get_unique_code(length=5) self.fields['description'].widget.attrs['class'] = "input-xlarge" if user: self.fields['ds_user'].initial = user list_gw = [] list_pb = [] dnc_list = [] list_pb.append((0, '---')) list = Phonebook.objects.values_list('id', 'name')\ .filter(user=user).order_by('id') for l in list: list_pb.append((l[0], l[1])) self.fields['phonebook'].choices = list_pb list = user.get_profile().userprofile_gateway.all() gw_list = ((l.id, l.name) for l in list) dnc_list.append(('', '---')) list = DNC.objects.values_list('id', 'name')\ .filter(user=user).order_by('id') for l in list: dnc_list.append((l[0], l[1])) self.fields['dnc'].choices = dnc_list for i in gw_list: list_gw.append((i[0], i[1])) self.fields['aleg_gateway'].choices = list_gw if instance.has_been_duplicated: from survey.models import Survey available_objects = Survey.objects.filter(user=user, campaign=instance) object_choices = get_object_choices(available_objects) self.fields['content_object'].widget.attrs['readonly'] = True else: from survey.models import Survey_template available_objects = Survey_template.objects.filter(user=user) object_choices = get_object_choices(available_objects) self.fields['content_object'].choices = object_choices # Voicemail setting is not enabled by default if settings.AMD: from survey.forms import get_audiofile_list self.fields[ 'voicemail_audiofile'].choices = get_audiofile_list(user) # if campaign is running if instance.status == CAMPAIGN_STATUS.START: self.fields['name'].widget.attrs['readonly'] = True self.fields['caller_name'].widget.attrs['readonly'] = True self.fields['callerid'].widget.attrs['readonly'] = True self.fields['extra_data'].widget.attrs['readonly'] = True self.fields['phonebook'].widget.attrs['disabled'] = 'disabled' selected_phonebook = '' if instance.phonebook.all(): selected_phonebook = \ ",".join(["%s" % (i.id) for i in instance.phonebook.all()]) self.fields['selected_phonebook'].initial = selected_phonebook self.fields['content_object'].widget.attrs['disabled'] = 'disabled' self.fields['content_object'].required = False self.fields['selected_content_object'].initial = "type:%s-id:%s" \ % (instance.content_type.id, instance.object_id)