def campaign_add(request): """Add a new campaign for the logged in user **Attributes**: * ``form`` - CampaignForm * ``template`` - dialer_campaign/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'] = _("your settings aren't configured properly, please contact the admin.") return HttpResponseRedirect(redirect_url_to_campaign_list) # 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(redirect_url_to_campaign_list) form = CampaignForm(request.user, request.POST or None) # Add campaign 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(redirect_url_to_campaign_list) data = { 'form': form, 'action': 'add', } return render_to_response('dialer_campaign/campaign/change.html', data, context_instance=RequestContext(request))
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 = {"form": form, "action": "add", "AMD": settings.AMD} return render_to_response(template, data, context_instance=RequestContext(request))
def campaign_change(request, object_id): """Update/Delete campaign for the logged in user **Attributes**: * ``object_id`` - Selected campaign object * ``form`` - CampaignForm * ``template`` - frontend/campaign/change.html **Logic Description**: * Update/delete selected campaign from the campaign list via CampaignForm & get redirected to the campaign list """ # If dialer setting is not attached with user, redirect to campaign list if not user_dialer_setting(request.user): return HttpResponseRedirect("/campaign/") campaign = get_object_or_404(Campaign, pk=object_id, user=request.user) content_object = "type:%s-id:%s" % \ (campaign.content_type_id, campaign.object_id) form = CampaignForm(request.user, instance=campaign, initial={'content_object': content_object}) if campaign.status == CAMPAIGN_STATUS.START: request.session['info_msg'] =\ _('the campaign is started, you can only edit Dialer settings and Campaign schedule') if request.method == 'POST': # Delete campaign if request.POST.get('delete'): return HttpResponseRedirect('/campaign/del/%s/' % object_id) else: # Update campaign form = CampaignForm(request.user, request.POST, instance=campaign) if form.is_valid(): form.save() obj = form.save(commit=False) selected_content_object = form.cleaned_data['content_object'] if not selected_content_object: selected_content_object = form.cleaned_data['selected_content_object'] # while campaign status is running if campaign.status == CAMPAIGN_STATUS.START: if request.POST.get('selected_phonebook'): selected_phonebook = str(request.POST.get('selected_phonebook'))\ .split(',') obj.phonebook = Phonebook.objects\ .filter(id__in=selected_phonebook) contenttype = get_content_type(selected_content_object) obj.content_type = contenttype['object_type'] obj.object_id = contenttype['object_id'] obj.save() request.session["msg"] = _('"%(name)s" is updated.') \ % {'name': request.POST['name']} request.session['error_msg'] = '' return HttpResponseRedirect('/campaign/') template = 'frontend/campaign/change.html' data = { 'module': current_view(request), 'form': form, 'action': 'update', 'error_msg': request.session.get('error_msg'), 'info_msg': request.session.get('info_msg'), 'AMD': settings.AMD, } request.session['error_msg'] = '' request.session['info_msg'] = '' return render_to_response(template, data, context_instance=RequestContext(request))
def campaign_change(request, object_id): """Update/Delete campaign for the logged in user **Attributes**: * ``object_id`` - Selected campaign object * ``form`` - CampaignForm * ``template`` - frontend/campaign/change.html **Logic Description**: * Update/delete selected campaign from the campaign list via CampaignForm & get redirected to the campaign list """ # If dialer setting is not attached with user, redirect to campaign list if not user_dialer_setting(request.user): return HttpResponseRedirect("/campaign/") campaign = get_object_or_404(Campaign, pk=object_id, user=request.user) content_object = "type:%s-id:%s" % (campaign.content_type_id, campaign.object_id) form = CampaignForm(request.user, instance=campaign, initial={"content_object": content_object}) if campaign.status == CAMPAIGN_STATUS.START: request.session["info_msg"] = _( "the campaign is started, you can only edit Dialer settings and Campaign schedule" ) if request.method == "POST": # Delete campaign if request.POST.get("delete"): return HttpResponseRedirect("/campaign/del/%s/" % object_id) else: # Update campaign form = CampaignForm(request.user, request.POST, instance=campaign) if form.is_valid(): form.save() obj = form.save(commit=False) selected_content_object = form.cleaned_data["content_object"] if not selected_content_object: selected_content_object = form.cleaned_data["selected_content_object"] # while campaign status is running if campaign.status == CAMPAIGN_STATUS.START: if request.POST.get("selected_phonebook"): selected_phonebook = str(request.POST.get("selected_phonebook")).split(",") obj.phonebook = Phonebook.objects.filter(id__in=selected_phonebook) contenttype = get_content_type(selected_content_object) obj.content_type = contenttype["object_type"] obj.object_id = contenttype["object_id"] obj.save() request.session["msg"] = _('the campaign "%(name)s" is updated.') % {"name": request.POST["name"]} request.session["error_msg"] = "" return HttpResponseRedirect("/campaign/") template = "frontend/campaign/change.html" data = { "form": form, "action": "update", "error_msg": request.session.get("error_msg"), "info_msg": request.session.get("info_msg"), "AMD": settings.AMD, } request.session["error_msg"] = "" request.session["info_msg"] = "" return render_to_response(template, data, context_instance=RequestContext(request))
def test_campaign_form(self): self.assertEqual(self.campaign.name, "sample_campaign") Campaign.objects.get_running_campaign() Campaign.objects.get_expired_campaign() dialersetting = DialerSetting.objects.get(pk=1) #self.user.get_profile().dialersetting common_contact_authorization(dialersetting, '1234567890') # status = 1 self.campaign.update_campaign_status() get_campaign_status_url(self.campaign.pk, self.campaign.status) self.campaign.status = 2 self.campaign.save() self.campaign.update_campaign_status() get_campaign_status_url(self.campaign.pk, self.campaign.status) self.campaign.status = 3 self.campaign.save() self.campaign.update_campaign_status() get_campaign_status_url(self.campaign.pk, self.campaign.status) self.campaign.status = 4 self.campaign.save() self.campaign.update_campaign_status() get_campaign_status_url(self.campaign.pk, self.campaign.status) self.campaign.is_authorized_contact(dialersetting, '123456789') self.campaign.get_active_max_frequency() self.campaign.get_active_callmaxduration() self.campaign.get_active_contact() self.campaign.progress_bar() self.campaign.subscriber_detail() self.campaign.get_pending_subscriber_update(10, SUBSCRIBER_STATUS.IN_PROCESS) self.assertEqual(self.subscriber.campaign, self.campaign) form = CampaignForm(self.user) obj = form.save(commit=False) obj.name = "new_campaign" obj.user = self.user obj.phonebook_id = 1 obj.aleg_gateway_id = 1 obj.content_type_id = self.content_type_id obj.object_id = 1 obj.save() form = CampaignForm(self.user, instance=self.campaign) self.assertTrue(isinstance(form.instance, Campaign)) form = CampaignForm(self.user, data={ "name": "mylittle_campaign", "description": "xyz", "startingdate": "1301392136.0", "expirationdate": "1301332136.0", "frequency": "120", "callmaxduration": "50", "maxretry": "3", "intervalretry": "2000", "calltimeout": "60", "aleg_gateway": "1", "sms_gateway": "", "content_object": "type:32-id:1", "extra_data": "2000"}) self.assertEquals(form.is_valid(), False)
def test_campaign_form(self): self.assertEqual(self.campaign.name, "sample_campaign") Campaign.objects.get_running_campaign() Campaign.objects.get_expired_campaign() dialersetting = DialerSetting.objects.get(pk=1) #self.user.get_profile().dialersetting common_contact_authorization(dialersetting, '1234567890') # status = 1 self.campaign.update_campaign_status() get_url_campaign_status(self.campaign.pk, self.campaign.status) self.campaign.status = 2 self.campaign.save() self.campaign.update_campaign_status() get_url_campaign_status(self.campaign.pk, self.campaign.status) self.campaign.status = 3 self.campaign.save() self.campaign.update_campaign_status() get_url_campaign_status(self.campaign.pk, self.campaign.status) self.campaign.status = 4 self.campaign.save() self.campaign.update_campaign_status() get_url_campaign_status(self.campaign.pk, self.campaign.status) self.campaign.is_authorized_contact(dialersetting, '123456789') self.campaign.get_active_max_frequency() self.campaign.get_active_callmaxduration() self.campaign.get_active_contact() self.campaign.progress_bar() self.campaign.subscriber_detail() self.campaign.get_pending_subscriber_update( 10, SUBSCRIBER_STATUS.IN_PROCESS) self.assertEqual(self.subscriber.campaign, self.campaign) form = CampaignForm(self.user) obj = form.save(commit=False) obj.name = "new_campaign" obj.user = self.user obj.phonebook_id = 1 obj.aleg_gateway_id = 1 obj.content_type_id = self.content_type_id obj.object_id = 1 obj.save() form = CampaignForm(self.user, instance=self.campaign) self.assertTrue(isinstance(form.instance, Campaign)) form = CampaignForm(self.user, data={ "name": "mylittle_campaign", "description": "xyz", "startingdate": "1301392136.0", "expirationdate": "1301332136.0", "frequency": "120", "callmaxduration": "50", "maxretry": "3", "intervalretry": "2000", "calltimeout": "60", "aleg_gateway": "1", "content_object": "type:32-id:1", "extra_data": "2000", "ds_user": self.user }) self.assertEquals(form.is_valid(), False)
def campaign_change(request, object_id): """Update/Delete campaign for the logged in user **Attributes**: * ``object_id`` - Selected campaign object * ``form`` - CampaignForm * ``template`` - frontend/campaign/change.html **Logic Description**: * Update/delete selected campaign from the campaign list via CampaignForm & get redirected to the campaign list """ # If dialer setting is not attached with user, redirect to campaign list if not user_dialer_setting(request.user): return HttpResponseRedirect("/campaign/") campaign = get_object_or_404(Campaign, pk=object_id, user=request.user) content_object = "type:%s-id:%s" % \ (campaign.content_type_id, campaign.object_id) form = CampaignForm(request.user, instance=campaign, initial={'content_object': content_object}) if campaign.status == CAMPAIGN_STATUS.START: request.session['info_msg'] =\ _('the campaign is started, you can only edit Dialer settings and Campaign schedule') if request.method == 'POST': # Delete campaign if request.POST.get('delete'): return HttpResponseRedirect('/campaign/del/%s/' % object_id) else: # Update campaign form = CampaignForm(request.user, request.POST, instance=campaign) if form.is_valid(): form.save() obj = form.save(commit=False) selected_content_object = form.cleaned_data['content_object'] if not selected_content_object: selected_content_object = form.cleaned_data[ 'selected_content_object'] # while campaign status is running if campaign.status == CAMPAIGN_STATUS.START: if request.POST.get('selected_phonebook'): selected_phonebook = str(request.POST.get('selected_phonebook'))\ .split(',') obj.phonebook = Phonebook.objects\ .filter(id__in=selected_phonebook) contenttype = get_content_type(selected_content_object) obj.content_type = contenttype['object_type'] obj.object_id = contenttype['object_id'] obj.save() request.session["msg"] = _('"%(name)s" is updated.') \ % {'name': request.POST['name']} request.session['error_msg'] = '' return HttpResponseRedirect('/campaign/') template = 'frontend/campaign/change.html' data = { 'module': current_view(request), 'form': form, 'action': 'update', 'error_msg': request.session.get('error_msg'), 'info_msg': request.session.get('info_msg'), 'AMD': settings.AMD, } request.session['error_msg'] = '' request.session['info_msg'] = '' return render_to_response(template, data, context_instance=RequestContext(request))
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))