Example #1
0
 def test_form(self):
     p = Person.objects.get(pk=1)
     mdata = {'name': p.name, 'surname': p.surname, 'birth_date': p.birth_date,
              'bio': p.bio, 'skype': p.skype, 'email': p.email,
              'phone': p.phone, 'photo': p.photo}
     form = PersonForm(data=mdata)
     self.assertEqual(form.is_valid(), True)
     mdata['name'] = None
     form = PersonForm(data=mdata)
     self.assertEqual(form.is_valid(), False)
Example #2
0
def editPerson(request):
    p = Person.objects.get(pk=1)
    if request.method == 'POST':
        form = PersonForm(request.POST, request.FILES) #
        if form.is_valid():
            np = form.save(commit=False)
            if (np.photo.name == None):
                np.photo = p.photo
            np.pk = 1
            np.save()
            return HttpResponse(simplejson.dumps({'response': np.photo.url, 'result': 'success'}))
        else:
            response = {}
            for k in form.errors:
                response[k] = form.errors[k][0]
            return HttpResponse(simplejson.dumps({'response': response, 'result': 'error'}))
    else:
        form = PersonForm(instance=p) # An unbound form

    c = {'form': form, 'profile': p}
    return render_to_response("edit.html", c, context_instance=RequestContext(request))