def update_campaign_status_cust(request, pk, status): """Campaign Status (e.g. start|stop|pause|abort) can be changed from customer interface (via dialer_campaign/campaign list)""" obj_campaign = Campaign.objects.get(id=pk) obj_campaign.status = status obj_campaign.save() pagination_path = '/campaign/' if request.session.get('pagination_path'): pagination_path = request.session.get('pagination_path') #Check if no phonebook attached if int(status) == CAMPAIGN_STATUS.START and obj_campaign.phonebook.all().count() == 0: request.session['error_msg'] = _('error : you have to assign a phonebook to your campaign before starting it') else: recipient = request.user frontend_send_notification(request, status, recipient) # Notify user while campaign Start if int(status) == CAMPAIGN_STATUS.START and not obj_campaign.has_been_started: request.session['info_msg'] = \ _('the campaign global settings cannot be edited when the campaign is started') # change has_been_started flag obj_campaign.has_been_started = True obj_campaign.save() if obj_campaign.content_type.model == 'survey_template': # Copy survey survey_template = Survey_template.objects.get(user=request.user, pk=obj_campaign.object_id) survey_template.copy_survey_template(obj_campaign.id) collect_subscriber.delay(obj_campaign.id) return HttpResponseRedirect(pagination_path)
def add_view(self, request, extra_context=None): """Override django admin add_view method for checking the dialer setting limit **Logic Description**: * Before adding a contact, check the dialer setting limit if applicable to the user. If matched, the user will be redirected to the contact list """ # Check dialer setting limit if request.user and request.method == 'POST': # check Max Number of subscribers per campaign if check_dialer_setting(request, check_for="contact"): msg = _("you have too many contacts per campaign. you are allowed a maximum of %(limit)s")\ % {'limit': dialer_setting_limit(request, limit_for="contact")} messages.error(request, msg) # campaign limit reached frontend_send_notification(request, NOTIFICATION_NAME.campaign_limit_reached) return HttpResponseRedirect(reverse( "admin:dialer_campaign_contact_changelist")) ctx = {} return super(ContactAdmin, self).add_view(request, extra_context=ctx)
def campaign_add(request): """Add a new campaign for the logged in user **Attributes**: * ``form`` - CampaignForm * ``template`` - frontend/campaign/change.html **Logic Description**: * Before adding a campaign, check dialer setting limit if applicable to the user. * Add the new campaign which will belong to the logged in user via CampaignForm & get redirected to campaign list """ # If dialer setting is not attached with user, redirect to campaign list if not user_dialer_setting(request.user): request.session['error_msg'] = \ _("in order to add a campaign, you need to have your settings configured properly, please contact the admin.") return HttpResponseRedirect("/campaign/") # Check dialer setting limit if request.user and request.method != 'POST': # check Max Number of running campaign if check_dialer_setting(request, check_for="campaign"): msg = _("you have too many campaigns. Max allowed %(limit)s") \ % {'limit': dialer_setting_limit(request, limit_for="campaign")} request.session['msg'] = msg # campaign limit reached frontend_send_notification(request, NOTIFICATION_NAME.campaign_limit_reached) return HttpResponseRedirect("/campaign/") form = CampaignForm(request.user) # Add campaign if request.method == 'POST': form = CampaignForm(request.user, request.POST) if form.is_valid(): obj = form.save(commit=False) contenttype = get_content_type(form.cleaned_data['content_object']) obj.content_type = contenttype['object_type'] obj.object_id = contenttype['object_id'] obj.user = request.user obj.save() form.save_m2m() request.session["msg"] = _('"%(name)s" added.') %\ {'name': request.POST['name']} return HttpResponseRedirect('/campaign/') template = 'frontend/campaign/change.html' data = { 'module': current_view(request), 'form': form, 'action': 'add', 'AMD': settings.AMD, } return render_to_response(template, data, context_instance=RequestContext(request))
def update_sms_campaign_status_cust(request, pk, status): """SMS Campaign Status (e.g. start|stop|pause|abort) can be changed from customer interface (via sms campaign list)""" recipient = common_sms_campaign_status(pk, status) sms_notification_status = get_sms_notification_status(int(status)) frontend_send_notification(request, sms_notification_status, recipient) return HttpResponseRedirect(redirect_url_to_smscampaign_list)
def update_sms_campaign_status_admin(request, pk, status): """SMS Campaign Status (e.g. start|stop|pause|abort) can be changed from admin interface (via sms campaign list)""" smscampaign = SMSCampaign.objects.get(pk=pk) recipient = smscampaign.common_sms_campaign_status(status) sms_notification_status = get_sms_notification_status(int(status)) frontend_send_notification(request, sms_notification_status, recipient) return HttpResponseRedirect(reverse("admin:mod_sms_smscampaign_changelist"))
def update_campaign_status_admin(request, pk, status): """Campaign Status (e.g. start|stop|pause|abort) can be changed from admin interface (via campaign list)""" obj_campaign = Campaign.objects.get(id=pk) obj_campaign.status = status obj_campaign.save() frontend_send_notification(request, status, recipient=request.user) return HttpResponseRedirect(reverse("admin:dialer_campaign_campaign_changelist"))
def sms_campaign_add(request): """Add a new sms campaign for the logged in user **Attributes**: * ``form`` - SMSCampaignForm * ``template`` - frontend/sms_campaign/change.html **Logic Description**: * Before adding a sms campaign, check dialer setting limit if applicable to the user. * Add the new sms campaign which will belong to the logged in user via SMSCampaignForm & get redirected to sms campaign list """ # If dialer setting is not attached with user, redirect to sms campaign list if not user_dialer_setting(request.user): request.session['error_msg'] = \ _("in order to add a sms campaign, you need to have your \ settings configured properly, please contact the admin.") return HttpResponseRedirect(redirect_url_to_smscampaign_list) # Check dialer setting limit if request.user and request.method != 'POST': # check Max Number of running campaign if check_sms_dialer_setting(request, check_for="smscampaign"): msg = _("you have too many sms campaigns. Max allowed %(limit)s")\ % {'limit': dialer_setting_limit(request, limit_for="smscampaign")} request.session['msg'] = msg # sms campaign limit reached frontend_send_notification( request, SMS_NOTIFICATION_NAME.sms_campaign_limit_reached) return HttpResponseRedirect(redirect_url_to_smscampaign_list) form = SMSCampaignForm(request.user) # Add sms campaign if request.method == 'POST': form = SMSCampaignForm(request.user, request.POST) if form.is_valid(): obj = form.save(commit=False) obj.user = User.objects.get(username=request.user) obj.save() form.save_m2m() request.session["msg"] = _('"%(name)s" is added.') %\ {'name': request.POST['name']} return HttpResponseRedirect(redirect_url_to_smscampaign_list) template = 'frontend/sms_campaign/change.html' data = { 'form': form, 'action': 'add', 'dialer_setting_msg': user_dialer_setting_msg(request.user), } return render_to_response( template, data, context_instance=RequestContext(request))
def contact_add(request): """Add a new contact into the selected phonebook for the logged in user **Attributes**: * ``form`` - ContactForm * ``template`` - frontend/contact/change.html **Logic Description**: * Before adding a contact, check dialer setting limit if applicable to the user. * Add new contact belonging to the logged in user via ContactForm & get redirected to the contact list """ # Check dialer setting limit if request.user and request.method == 'POST': # check Max Number of subscriber per campaign if check_dialer_setting(request, check_for="contact"): request.session['msg'] = \ _("you have too many contacts per campaign. you are allowed a maximum of %(limit)s") % \ {'limit': dialer_setting_limit(request, limit_for="contact")} # contact limit reached frontend_send_notification(request, NOTIFICATION_NAME.contact_limit_reached) return HttpResponseRedirect("/contact/") form = ContactForm(request.user) error_msg = False # Add contact if request.method == 'POST': form = ContactForm(request.user, request.POST) if form.is_valid(): form.save() request.session["msg"] = _('"%(name)s" added.') %\ {'name': request.POST['contact']} return HttpResponseRedirect('/contact/') else: if len(request.POST['contact']) > 0: error_msg = _('"%(name)s" cannot be added.') %\ {'name': request.POST['contact']} phonebook_count = Phonebook.objects.filter(user=request.user).count() template = 'frontend/contact/change.html' data = { 'module': current_view(request), 'form': form, 'action': 'add', 'error_msg': error_msg, 'phonebook_count': phonebook_count, 'dialer_setting_msg': user_dialer_setting_msg(request.user), } return render_to_response(template, data, context_instance=RequestContext(request))
def contact_add(request): """Add a new contact into the selected phonebook for the logged in user **Attributes**: * ``form`` - ContactForm * ``template`` - frontend/contact/change.html **Logic Description**: * Before adding a contact, check dialer setting limit if applicable to the user. * Add new contact belonging to the logged in user via ContactForm & get redirected to the contact list """ # Check dialer setting limit if request.user and request.method == "POST": if check_dialer_setting(request, check_for="contact"): request.session["msg"] = _("you have too many contacts. you are allowed a maximum of %(limit)s") % { "limit": dialer_setting_limit(request, limit_for="contact") } # contact limit reached frontend_send_notification(request, NOTIFICATION_NAME.contact_limit_reached) return HttpResponseRedirect("/contact/") form = ContactForm(request.user) error_msg = False # Add contact if request.method == "POST": form = ContactForm(request.user, request.POST) if form.is_valid(): form.save() request.session["msg"] = _('"%s" is added.') % request.POST["contact"] return HttpResponseRedirect("/contact/") else: if len(request.POST["contact"]) > 0: error_msg = _('"%s" cannot be added.') % request.POST["contact"] phonebook_count = Phonebook.objects.filter(user=request.user).count() template = "frontend/contact/change.html" data = { "form": form, "action": "add", "error_msg": error_msg, "phonebook_count": phonebook_count, "dialer_setting_msg": user_dialer_setting_msg(request.user), } return render_to_response(template, data, context_instance=RequestContext(request))
def notify_admin(request): """Notify administrator regarding dialer setting configuration for system user via mail """ # Get all the admin users - admin superuser all_admin_user = User.objects.filter(is_superuser=True) for user in all_admin_user: recipient = user if not request.session['has_notified']: frontend_send_notification( request, NOTIFICATION_NAME.dialer_setting_configuration, recipient) # Send mail to ADMINS subject = _('dialer setting configuration').title() message = _('Notification - User Dialer Setting. The user "%(user)s" - "%(user_id)s" is not properly configured to use the system, please configure their dialer settings.') %\ {'user': request.user, 'user_id': request.user.id} # mail_admins() is a shortcut for sending an email to the site admins, # as defined in the ADMINS setting mail_admins(subject, message) request.session['has_notified'] = True return HttpResponseRedirect('/dashboard/')
def contact_add(request): """Add a new contact into the selected phonebook for the logged in user **Attributes**: * ``form`` - ContactForm * ``template`` - dialer_contact/contact/change.html **Logic Description**: * Before adding a contact, check dialer setting limit if applicable to the user. * Add new contact belonging to the logged in user via ContactForm & get redirected to the contact list """ # Check dialer setting limit if request.user and request.method == 'POST': if check_dialer_setting(request, check_for="contact"): request.session['msg'] = _("you have too many contacts. you are allowed a maximum of %(limit)s") % \ {'limit': dialer_setting_limit(request, limit_for="contact")} # contact limit reached frontend_send_notification(request, NOTIFICATION_NAME.contact_limit_reached) return HttpResponseRedirect(redirect_url_to_contact_list) form = ContactForm(request.user, request.POST or None) # Add contact if form.is_valid(): form.save() request.session["msg"] = _('"%s" is added.') % request.POST['contact'] return HttpResponseRedirect(redirect_url_to_contact_list) data = { 'form': form, 'action': 'add', } return render_to_response('dialer_contact/contact/change.html', data, context_instance=RequestContext(request))
def contact_import(request): """Import CSV file of Contacts for the logged in user **Attributes**: * ``form`` - Contact_fileImport * ``template`` - dialer_contact/contact/import_contact.html **Logic Description**: * Before adding contacts, check dialer setting limit if applicable to the user. * Add new contacts which will belong to the logged in user via csv file & get the result (upload success and failure statistics) **Important variable**: * total_rows - Total no. of records in the CSV file * retail_record_count - No. of records imported from the CSV file """ # Check dialer setting limit if request.user and request.method == 'POST': # check Max Number of contacts if check_dialer_setting(request, check_for="contact"): request.session['msg'] = _("you have too many contacts. you are allowed a maximum of %(limit)s") % \ {'limit': dialer_setting_limit(request, limit_for="contact")} # contact limit reached frontend_send_notification(request, NOTIFICATION_NAME.contact_limit_reached) return HttpResponseRedirect(redirect_url_to_contact_list) form = Contact_fileImport(request.user, request.POST or None, request.FILES or None) csv_data = '' msg = '' error_msg = '' success_import_list = [] type_error_import_list = [] contact_cnt = 0 bulk_record = [] if form.is_valid(): # col_no - field name # 0 - contact # 1 - last_name # 2 - first_name # 3 - email # 4 - description # 5 - status # 6 - address # 7 - city # 8 - country # 9 - country # 10 - unit_number # 11 - additional_vars # To count total rows of CSV file records = csv.reader(request.FILES['csv_file'], delimiter='|', quotechar='"') total_rows = len(list(records)) BULK_SIZE = 1000 csv_data = csv.reader(request.FILES['csv_file'], delimiter='|', quotechar='"') #Get Phonebook Obj phonebook = get_object_or_404(Phonebook, pk=request.POST['phonebook'], user=request.user) #Read each Row for row in csv_data: row = striplist(row) if not row or str(row[0]) == 0: continue #Check field type if not int(row[5]): error_msg = _("invalid value for import! please check the import samples or phonebook is not valid") type_error_import_list.append(row) break if len(row[9]) > 2: error_msg = _("invalid value for country code, it needs to be a valid ISO 3166-1 alpha-2 codes") type_error_import_list.append(row) break row_11 = '' if row[11]: try: row_11 = json.loads(row[11]) except: row_11 = '' bulk_record.append( Contact( phonebook=phonebook, contact=row[0], last_name=row[1], first_name=row[2], email=row[3], description=row[4], status=int(row[5]), address=row[6], city=row[7], state=row[8], country=row[9], # Note: country needs to be a country code (CA, ES) unit_number=row[10], additional_vars=row_11) ) contact_cnt = contact_cnt + 1 if contact_cnt < 100: #We want to display only 100 lines of the success import success_import_list.append(row) if contact_cnt % BULK_SIZE == 0: #Bulk insert Contact.objects.bulk_create(bulk_record) bulk_record = [] # remaining record Contact.objects.bulk_create(bulk_record) bulk_record = [] #check if there is contact imported if contact_cnt > 0: msg = _('%(contact_cnt)s contact(s) have been uploaded successfully out of %(total_rows)s row(s)!') \ % {'contact_cnt': contact_cnt, 'total_rows': total_rows} data = RequestContext(request, { 'form': form, 'csv_data': csv_data, 'msg': msg, 'error_msg': error_msg, 'success_import_list': success_import_list, 'type_error_import_list': type_error_import_list, }) return render_to_response('dialer_contact/contact/import_contact.html', data, context_instance=RequestContext(request))
def import_contact(self, request): """Add custom method in django admin view to import CSV file of Contacts **Attributes**: * ``form`` - Contact_fileImport * ``template`` - admin/dialer_campaign/contact/import_contact.html **Logic Description**: * Before adding contact, check the dialer setting limit if applicable to the user. * Add a new contact which will belong to the logged in user via csv file & get the result (Upload success & failure statistics) **Important variable**: * total_rows - Total no. of records in the CSV file * retail_record_count - No. of records which are imported from The CSV file """ # Check dialer setting limit if request.user and request.method == 'POST': # check Max Number of subscribers per campaign if check_dialer_setting(request, check_for="contact"): msg = _("you have too many contacts per campaign. you are allowed a maximum of %(limit)s")\ % {'limit': dialer_setting_limit(request, limit_for="contact")} messages.error(request, msg) # campaign limit reached frontend_send_notification(request, NOTIFICATION_NAME.campaign_limit_reached) return HttpResponseRedirect(reverse( "admin:dialer_campaign_contact_changelist")) opts = Contact._meta rdr = '' # will contain CSV data msg = '' error_msg = '' success_import_list = [] type_error_import_list = [] contact_cnt = 0 bulk_record = [] if request.method == 'POST': form = Contact_fileImport( request.user, request.POST, request.FILES) if form.is_valid(): # col_no - field name # 0 - contact # 1 - last_name # 2 - first_name # 3 - email # 4 - description # 5 - status # 6 - address # 7 - city # 8 - state # 9 - country # 10 - unit_number # 11 - additional_vars # To count total rows of CSV file records = csv.reader( request.FILES['csv_file'], delimiter='|', quotechar='"') total_rows = len(list(records)) BULK_SIZE = 1000 rdr = csv.reader( request.FILES['csv_file'], delimiter='|', quotechar='"') #Get Phonebook Obj phonebook = Phonebook.objects.get(pk=request.POST['phonebook']) contact_cnt = 0 # Read each Row for row in rdr: row = striplist(row) if not row or str(row[0]) == 0: continue # check field type if not int(row[5]): error_msg = _("invalid value for import! please check the import samples or phonebook is not valid") type_error_import_list.append(row) break row_11 = '' if row[11]: row_11 = json.loads(row[11]) bulk_record.append( Contact( phonebook=phonebook, contact=row[0], last_name=row[1], first_name=row[2], email=row[3], description=row[4], status=int(row[5]), address=row[6], city=row[7], state=row[8], country=row[9], unit_number=row[10], additional_vars=row_11) ) contact_cnt = contact_cnt + 1 if contact_cnt < 100: success_import_list.append(row) if contact_cnt % BULK_SIZE == 0: # Bulk insert Contact.objects.bulk_create(bulk_record) bulk_record = [] # remaining record Contact.objects.bulk_create(bulk_record) bulk_record = [] #check if there is contact imported if contact_cnt > 0: msg = _('%(contact_cnt)s contact(s) are uploaded successfully out of %(total_rows)s row(s) !!')\ % {'contact_cnt': contact_cnt, 'total_rows': total_rows} else: form = Contact_fileImport(request.user) ctx = RequestContext(request, { 'form': form, 'opts': opts, 'model_name': opts.object_name.lower(), 'app_label': _('dialer contact'), 'title': _('import contact'), 'rdr': rdr, 'msg': msg, 'error_msg': error_msg, 'success_import_list': success_import_list, 'type_error_import_list': type_error_import_list, }) return render_to_response( 'admin/dialer_contact/contact/import_contact.html', context_instance=ctx)
def contact_import(request): """Import CSV file of Contacts for the logged in user **Attributes**: * ``form`` - Contact_fileImport * ``template`` - dialer_contact/contact/import_contact.html **Logic Description**: * Before adding contacts, check dialer setting limit if applicable to the user. * Add new contacts which will belong to the logged in user via csv file & get the result (upload success and failure statistics) **Important variable**: * total_rows - Total no. of records in the CSV file * retail_record_count - No. of records imported from the CSV file """ # Check dialer setting limit if request.user and request.method == 'POST': # check Max Number of contacts if check_dialer_setting(request, check_for="contact"): request.session['msg'] = _("you have too many contacts. you are allowed a maximum of %(limit)s") % \ {'limit': dialer_setting_limit(request, limit_for="contact")} # contact limit reached frontend_send_notification(request, NOTIFICATION_NAME.contact_limit_reached) return HttpResponseRedirect(redirect_url_to_contact_list) form = Contact_fileImport(request.user, request.POST or None, request.FILES or None) csv_data = '' msg = '' error_msg = '' success_import_list = [] type_error_import_list = [] contact_cnt = 0 bulk_record = [] if form.is_valid(): # col_no - field name # 0 - contact # 1 - last_name # 2 - first_name # 3 - email # 4 - description # 5 - status # 6 - address # 7 - city # 8 - country # 9 - country # 10 - unit_number # 11 - additional_vars # To count total rows of CSV file records = csv.reader(request.FILES['csv_file'], delimiter='|', quotechar='"') total_rows = len(list(records)) BULK_SIZE = 1000 csv_data = csv.reader(request.FILES['csv_file'], delimiter='|', quotechar='"') #Get Phonebook Obj phonebook = get_object_or_404(Phonebook, pk=request.POST['phonebook'], user=request.user) #Read each Row for row in csv_data: row = striplist(row) if not row or str(row[0]) == 0: continue #Check field type if not int(row[5]): error_msg = _( "invalid value for import! please check the import samples or phonebook is not valid" ) type_error_import_list.append(row) break if len(row[9]) > 2: error_msg = _( "invalid value for country code, it needs to be a valid ISO 3166-1 alpha-2 codes" ) type_error_import_list.append(row) break row_11 = '' if row[11]: try: row_11 = json.loads(row[11]) except: row_11 = '' bulk_record.append( Contact( phonebook=phonebook, contact=row[0], last_name=row[1], first_name=row[2], email=row[3], description=row[4], status=int(row[5]), address=row[6], city=row[7], state=row[8], country=row[ 9], # Note: country needs to be a country code (CA, ES) unit_number=row[10], additional_vars=row_11)) contact_cnt = contact_cnt + 1 if contact_cnt < 100: #We want to display only 100 lines of the success import success_import_list.append(row) if contact_cnt % BULK_SIZE == 0: #Bulk insert Contact.objects.bulk_create(bulk_record) bulk_record = [] # remaining record Contact.objects.bulk_create(bulk_record) bulk_record = [] #check if there is contact imported if contact_cnt > 0: msg = _('%(contact_cnt)s contact(s) have been uploaded successfully out of %(total_rows)s row(s)!') \ % {'contact_cnt': contact_cnt, 'total_rows': total_rows} data = RequestContext( request, { 'form': form, 'csv_data': csv_data, 'msg': msg, 'error_msg': error_msg, 'success_import_list': success_import_list, 'type_error_import_list': type_error_import_list, }) return render_to_response('dialer_contact/contact/import_contact.html', data, context_instance=RequestContext(request))
def import_contact(self, request): """Add custom method in django admin view to import CSV file of Contacts **Attributes**: * ``form`` - Contact_fileImport * ``template`` - admin/dialer_campaign/contact/import_contact.html **Logic Description**: * Before adding contact, check the dialer setting limit if applicable to the user. * Add a new contact which will belong to the logged in user via csv file & get the result (Upload success & failure statistics) **Important variable**: * total_rows - Total no. of records in the CSV file * retail_record_count - No. of records which are imported from The CSV file """ # Check dialer setting limit if request.user and request.method == 'POST': # check Max Number of subscribers per campaign if check_dialer_setting(request, check_for="contact"): msg = _("you have too many contacts per campaign. you are allowed a maximum of %(limit)s")\ % {'limit': dialer_setting_limit(request, limit_for="contact")} messages.error(request, msg) # campaign limit reached frontend_send_notification( request, NOTIFICATION_NAME.campaign_limit_reached) return HttpResponseRedirect( reverse("admin:dialer_campaign_contact_changelist")) opts = Contact._meta rdr = '' # will contain CSV data msg = '' error_msg = '' success_import_list = [] type_error_import_list = [] contact_cnt = 0 bulk_record = [] if request.method == 'POST': form = Contact_fileImport(request.user, request.POST, request.FILES) if form.is_valid(): # col_no - field name # 0 - contact # 1 - last_name # 2 - first_name # 3 - email # 4 - description # 5 - status # 6 - address # 7 - city # 8 - state # 9 - country # 10 - unit_number # 11 - additional_vars # To count total rows of CSV file records = csv.reader(request.FILES['csv_file'], delimiter='|', quotechar='"') total_rows = len(list(records)) BULK_SIZE = 1000 rdr = csv.reader(request.FILES['csv_file'], delimiter='|', quotechar='"') #Get Phonebook Obj phonebook = Phonebook.objects.get(pk=request.POST['phonebook']) contact_cnt = 0 # Read each Row for row in rdr: row = striplist(row) if not row or str(row[0]) == 0: continue # check field type if not int(row[5]): error_msg = _( "invalid value for import! please check the import samples or phonebook is not valid" ) type_error_import_list.append(row) break row_11 = '' if row[11]: row_11 = json.loads(row[11]) bulk_record.append( Contact(phonebook=phonebook, contact=row[0], last_name=row[1], first_name=row[2], email=row[3], description=row[4], status=int(row[5]), address=row[6], city=row[7], state=row[8], country=row[9], unit_number=row[10], additional_vars=row_11)) contact_cnt = contact_cnt + 1 if contact_cnt < 100: success_import_list.append(row) if contact_cnt % BULK_SIZE == 0: # Bulk insert Contact.objects.bulk_create(bulk_record) bulk_record = [] # remaining record Contact.objects.bulk_create(bulk_record) bulk_record = [] #check if there is contact imported if contact_cnt > 0: msg = _('%(contact_cnt)s contact(s) are uploaded successfully out of %(total_rows)s row(s) !!')\ % {'contact_cnt': contact_cnt, 'total_rows': total_rows} else: form = Contact_fileImport(request.user) ctx = RequestContext( request, { 'form': form, 'opts': opts, 'model_name': opts.object_name.lower(), 'app_label': _('dialer contact'), 'title': _('import contact'), 'rdr': rdr, 'msg': msg, 'error_msg': error_msg, 'success_import_list': success_import_list, 'type_error_import_list': type_error_import_list, }) return render_to_response( 'admin/dialer_contact/contact/import_contact.html', context_instance=ctx)
def campaign_add(request): """Add a new campaign for the logged in user **Attributes**: * ``form`` - CampaignForm * ``template`` - frontend/campaign/change.html **Logic Description**: * Before adding a campaign, check dialer setting limit if applicable to the user. * Add the new campaign which will belong to the logged in user via CampaignForm & get redirected to campaign list """ # If dialer setting is not attached with user, redirect to campaign list if not user_dialer_setting(request.user): request.session['error_msg'] = \ _("in order to add a campaign, you need to have your settings configured properly, please contact the admin.") return HttpResponseRedirect("/campaign/") # Check dialer setting limit if request.user and request.method != 'POST': # check Max Number of running campaign if check_dialer_setting(request, check_for="campaign"): msg = _("you have too many campaigns. Max allowed %(limit)s") \ % {'limit': dialer_setting_limit(request, limit_for="campaign")} request.session['msg'] = msg # campaign limit reached frontend_send_notification( request, NOTIFICATION_NAME.campaign_limit_reached) return HttpResponseRedirect("/campaign/") form = CampaignForm(request.user) # Add campaign if request.method == 'POST': form = CampaignForm(request.user, request.POST) if form.is_valid(): obj = form.save(commit=False) contenttype = get_content_type(form.cleaned_data['content_object']) obj.content_type = contenttype['object_type'] obj.object_id = contenttype['object_id'] obj.user = request.user obj.save() form.save_m2m() request.session["msg"] = _('"%(name)s" added.') %\ {'name': request.POST['name']} return HttpResponseRedirect('/campaign/') template = 'frontend/campaign/change.html' data = { 'module': current_view(request), 'form': form, 'action': 'add', 'AMD': settings.AMD, } return render_to_response(template, data, context_instance=RequestContext(request))