Example #1
0
def dnc_add(request):
    """Add new DNC for the logged in user

    **Attributes**:

        * ``form`` - DNCListForm
        * ``template`` - dnc/dnc_list/change.html

    **Logic Description**:

        * Add a new DNC which will belong to the logged in user
          via the DNCListForm & get redirected to the dnc list
    """
    form = DNCListForm(request.POST or None)
    if form.is_valid():
        form.save(user=request.user)
        request.session["msg"] = _('"%(name)s" added.') % {
            'name': request.POST['name']
        }
        return HttpResponseRedirect(dnc_list_redirect_url)
    data = {
        'form': form,
        'action': 'add',
    }
    return render_to_response('dnc/dnc_list/change.html',
                              data,
                              context_instance=RequestContext(request))
Example #2
0
def dnc_change(request, object_id):
    """Update/Delete DNC for the logged in user

    **Attributes**:

        * ``object_id`` - Selected dnc object
        * ``form`` - DNCListForm
        * ``template`` - dnc/dnc_list/change.html

    **Logic Description**:

        * Update/delete selected dnc from the dnc list
          via DNCListForm & get redirected to dnc list
    """
    dnc = get_object_or_404(DNC, pk=object_id, user=request.user)
    form = DNCListForm(request.POST or None, instance=dnc)
    if form.is_valid():
        if request.POST.get('delete'):
            dnc_del(request, object_id)
            return HttpResponseRedirect(dnc_list_redirect_url)
        else:
            form.save()
            request.session["msg"] = _('"%(name)s" is updated.') % {
                'name': request.POST['name']
            }
            return HttpResponseRedirect(dnc_list_redirect_url)
    data = {
        'form': form,
        'action': 'update',
    }
    return render_to_response('dnc/dnc_list/change.html',
                              data,
                              context_instance=RequestContext(request))
Example #3
0
def dnc_change(request, object_id):
    """Update/Delete DNC for the logged in user

    **Attributes**:

        * ``object_id`` - Selected dnc object
        * ``form`` - DNCListForm
        * ``template`` - dnc/dnc_list/change.html

    **Logic Description**:

        * Update/delete selected dnc from the dnc list
          via DNCListForm & get redirected to dnc list
    """
    dnc = get_object_or_404(DNC, pk=object_id, user=request.user)
    form = DNCListForm(request.POST or None, instance=dnc)
    if form.is_valid():
        if request.POST.get('delete'):
            dnc_del(request, object_id)
            return HttpResponseRedirect(dnc_list_redirect_url)
        else:
            form.save()
            request.session["msg"] = _('"%(name)s" is updated.') % {'name': request.POST['name']}
            return HttpResponseRedirect(dnc_list_redirect_url)
    data = {
        'form': form,
        'action': 'update',
    }
    return render_to_response('dnc/dnc_list/change.html', data, context_instance=RequestContext(request))
Example #4
0
    def test_dnc_form(self):
        self.assertEqual(self.dnc.name, 'test_dnc')
        form = DNCListForm({'name': 'sample_dnc'})
        form.save(user=self.user)

        form = DNCListForm(instance=self.dnc)
        self.assertTrue(isinstance(form.instance, DNC))
Example #5
0
def dnc_add(request):
    """Add new DNC for the logged in user

    **Attributes**:

        * ``form`` - DNCListForm
        * ``template`` - dnc/dnc_list/change.html

    **Logic Description**:

        * Add a new DNC which will belong to the logged in user
          via the DNCListForm & get redirected to the dnc list
    """
    form = DNCListForm(request.POST or None)
    if form.is_valid():
        form.save(user=request.user)
        request.session["msg"] = _('"%(name)s" added.') % {"name": request.POST["name"]}
        return HttpResponseRedirect(dnc_list_redirect_url)
    data = {"form": form, "action": "add"}
    return render_to_response("dnc/dnc_list/change.html", data, context_instance=RequestContext(request))
Example #6
0
    def test_dnc_form(self):
        self.assertEqual(self.dnc.name, 'test_dnc')
        form = DNCListForm({'name': 'sample_dnc'})
        form.save(user=self.user)

        form = DNCListForm(instance=self.dnc)
        self.assertTrue(isinstance(form.instance, DNC))