Exemple #1
0
def change_user_info(request):
    response = {}
    response.update(csrf(request))

    if request.method == "GET":
        user = UserInfo.objects.get(pk=1)
        form = UserInfoForm(instance=user)
        response["form"] = form
        return render_to_response("userinfo/change_user_info.html", response)

    elif request.method == "POST" and request.is_ajax():
        instance = UserInfo.objects.get(pk=1)
        form = UserInfoForm(
            data=request.POST or None,
            files=request.FILES or None,
            instance=instance
        )
        response = {}
        if form.is_valid():
            form.save()
            response['status'] = u'success'
            return HttpResponse(json.dumps(response), content_type="application/json")
        else:
            response['status'] = u'error'
            response['error_list'] = form.errors
            return HttpResponse(json.dumps(response), content_type="application/json")
Exemple #2
0
 def test_UserInfoFormValid(self):
     """Test UserInfoForm validation"""
     form_data1 = {
         u"name": u"Jho",
         u"last_name": u"Rogan"
     }
     form1 = UserInfoForm(form_data1)
     form_data2 = {
         'name': u"True",
         'last_name': u"Samuro",
         'email': u"*****@*****.**",
         'biography': u"Son of the Rising Sun.",
         'date_of_birth': datetime.datetime(year=1967, month=5, day=23)
     }
     form2 = UserInfoForm(form_data2)
     self.assertFalse(form1.is_valid())
     self.assertTrue(form2.is_valid())