def dnc_add(request): """Add new DNC for the logged in user **Attributes**: * ``form`` - DNCForm * ``template`` - frontend/dnc_list/change.html **Logic Description**: * Add a new DNC which will belong to the logged in user via the DNCForm & get redirected to the dnc list """ form = DNCForm() if request.method == 'POST': form = DNCForm(request.POST) if form.is_valid(): obj = form.save(commit=False) obj.user = request.user obj.save() request.session["msg"] = _('"%(name)s" added.') %\ {'name': request.POST['name']} return HttpResponseRedirect('/dnc_list/') template = 'frontend/dnc_list/change.html' data = { 'module': current_view(request), 'form': form, 'action': 'add', 'dialer_setting_msg': user_dialer_setting_msg(request.user), } return render_to_response(template, data, context_instance=RequestContext(request))
def test_dnc_form(self): self.assertEqual(self.dnc.name, 'test_dnc') form = DNCForm({'name': 'sample_dnc'}) obj = form.save(commit=False) obj.user = self.user obj.save() form = DNCForm(instance=self.dnc) self.assertTrue(isinstance(form.instance, DNC))
def dnc_change(request, object_id): """Update/Delete DNC for the logged in user **Attributes**: * ``object_id`` - Selected dnc object * ``form`` - DNCForm * ``template`` - frontend/dnc_list/change.html **Logic Description**: * Update/delete selected dnc from the dnc list via DNCForm & get redirected to dnc list """ dnc = get_object_or_404(DNC, pk=object_id, user=request.user) form = DNCForm(instance=dnc) if request.method == 'POST': if request.POST.get('delete'): dnc_del(request, object_id) return HttpResponseRedirect('/dnc/') else: form = DNCForm(request.POST, instance=dnc) if form.is_valid(): form.save() request.session["msg"] = _('"%(name)s" is updated.') \ % {'name': request.POST['name']} return HttpResponseRedirect('/dnc/') template = 'frontend/dnc_list/change.html' data = { 'module': current_view(request), 'form': form, 'action': 'update', 'dialer_setting_msg': user_dialer_setting_msg(request.user), } return render_to_response(template, data, context_instance=RequestContext(request))
def dnc_change(request, object_id): """Update/Delete DNC for the logged in user **Attributes**: * ``object_id`` - Selected dnc object * ``form`` - DNCForm * ``template`` - frontend/dnc_list/change.html **Logic Description**: * Update/delete selected dnc from the dnc list via DNCForm & get redirected to dnc list """ dnc = get_object_or_404(DNC, pk=object_id, user=request.user) form = DNCForm(instance=dnc) if request.method == 'POST': if request.POST.get('delete'): return HttpResponseRedirect('/dnc_list/del/%s/' % object_id) else: form = DNCForm(request.POST, instance=dnc) if form.is_valid(): form.save() request.session["msg"] = _('"%(name)s" is updated.') \ % {'name': request.POST['name']} return HttpResponseRedirect('/dnc_list/') template = 'frontend/dnc_list/change.html' data = { 'module': current_view(request), 'form': form, 'action': 'update', 'dialer_setting_msg': user_dialer_setting_msg(request.user), } return render_to_response(template, data, context_instance=RequestContext(request))