Beispiel #1
0
def showEditContactsPage(request):
    contacts = get_object_or_404(UserDetail, id=1)
    if request.method == 'POST':
        form = UserDetailForm(request.POST, instance=contacts)
        if form.is_valid():
            form.save()
            return HttpResponseRedirect('/')
        else:
            form = UserDetailForm(request.POST, instance=contacts)
            context = {
                'contacts': contacts,
                'form': form,
            }
            return render_to_response('edit-contacts.html',
                                      context,
                                      context_instance=RequestContext(request))

    form = UserDetailForm(instance=contacts)
    context = {
        'contacts': contacts,
        'form': form,
    }
    return render_to_response('edit-contacts.html',
                              context,
                              context_instance=RequestContext(request))
Beispiel #2
0
def showEditContactsPage(request):
    contacts = get_object_or_404(UserDetail, id=1)
    if request.method == 'POST':
        form = UserDetailForm(request.POST, instance=contacts)
        if form.is_valid():
            form.save()
            return HttpResponseRedirect('/')
        else:
            form = UserDetailForm(request.POST,instance=contacts)
            context = {
                       'contacts':contacts,
                       'form':form,
                       }
            return render_to_response('edit-contacts.html',
                                      context,
                                      context_instance = RequestContext(request))
        
    form = UserDetailForm(instance=contacts)  
    context = {
        'contacts':contacts,
        'form':form,
    }
    return render_to_response('edit-contacts.html',
                              context,
                              context_instance = RequestContext(request))
Beispiel #3
0
 def test_save_form(self):
     from cc42.contacts.forms import UserDetailForm
     from cc42.contacts.models import UserDetail
     
     form = UserDetailForm(test_data, instance=UserDetail.objects.get(id=1))
     form.save()
     UD = UserDetail.objects.get(id=1)
     self.assert_equal(UD.name, test_data['name'])
Beispiel #4
0
    def test_save_form(self):
        from cc42.contacts.forms import UserDetailForm
        from cc42.contacts.models import UserDetail

        form = UserDetailForm(test_data, instance=UserDetail.objects.get(id=1))
        form.save()
        UD = UserDetail.objects.get(id=1)
        self.assert_equal(UD.name, test_data['name'])
Beispiel #5
0
def show_edit_contacts_page(request):
    contacts = get_object_or_404(UserDetail, id=1)
    if request.method == 'POST' and request.is_ajax():
        form = UserDetailForm(request.POST, instance=contacts)
        if form.is_valid():
            form.save()
        response_text = render_to_string("edit-ajax-resp.html",
                    context_instance=RequestContext(request, {'form': form}))

        return HttpResponse(response_text, mimetype='application/javascript')

    # left for old tests and users with disabled js
    elif request.method == 'POST' and not request.is_ajax():
        form = UserDetailForm(request.POST, instance=contacts)
        if form.is_valid():
            form.save()
    else:
        form = UserDetailForm(instance=contacts)

    context = {'contacts': contacts, 'form': form}
    return render_to_response('edit-contacts.html',
                        context_instance=RequestContext(request, context))
Beispiel #6
0
def show_edit_contacts_page(request):
    contacts = get_object_or_404(UserDetail, id=1)
    if request.method == 'POST' and request.is_ajax():
        form = UserDetailForm(request.POST, instance=contacts)
        if form.is_valid():
            form.save()
        response_text = render_to_string("edit-ajax-resp.html",
                                         context_instance=RequestContext(
                                             request, {'form': form}))

        return HttpResponse(response_text, mimetype='application/javascript')

    # left for old tests and users with disabled js
    elif request.method == 'POST' and not request.is_ajax():
        form = UserDetailForm(request.POST, instance=contacts)
        if form.is_valid():
            form.save()
    else:
        form = UserDetailForm(instance=contacts)

    context = {'contacts': contacts, 'form': form}
    return render_to_response('edit-contacts.html',
                              context_instance=RequestContext(
                                  request, context))