Beispiel #1
0
def edit_my_profile(request):
    my_info = get_object_or_None(PersonalInfo, pk=1)
    if request.method == 'POST':
        form = PersonalInfoForm(request.POST, request.FILES, instance=my_info)
        response_dict = {}
        if request.is_ajax():
            if form.is_valid():
                form.save()
                response_dict['result'] = 'success'
            else:
                response_dict['result'] = 'error'
                errors = {}
                for error in form.errors:
                    errors[error] = form.errors[error][0]
                response_dict['form_errors'] = errors
            json = simplejson.dumps(response_dict, ensure_ascii=False)
            return HttpResponse(json, mimetype='application/json')
        else:
            if form.is_valid():
                form.save()
                return redirect(reverse('mainpage_url'))
    else:
        form = PersonalInfoForm(instance=my_info)
    return direct_to_template(
        request, 'profile_edit.html', {'form': form, 'photo': my_info.photo})
def edit_home(request):
    page = PersonInfo.objects.get(pk=1)
    form = PersonalInfoForm(request.POST or None, request.FILES or None,
                            instance=page, prefix='page')
    if request.method == 'POST':
        status = None
        if form.is_valid():
            form.save()
            status = ' Changes have been saved'
        return {'form': form, 'page': page, 'status': status}
    return {'form': form, 'page': page}
Beispiel #3
0
def PersonalView(request):
	if request.method == 'POST':
		form = PersonalInfoForm(request.POST)
		if form.is_valid():
			form.save()
			return redirect('/initial/')
	else:
		form = PersonalInfoForm()
		return render_to_response(
				'info.html',
				{'form': form},
				RequestContext(request)
			)
Beispiel #4
0
 def test_form(self):
     file_dict = {
         'photo': SimpleUploadedFile(
             self.file_obj.name, self.file_obj.read())}
     self.assertTrue(self.current_instance is not None)
     form = PersonalInfoForm(
         self.post_dict, file_dict, instance=self.current_instance)
     self.assertTrue(form.is_valid())
     form.save()
     response = self.client.get(reverse('testapp:mainpage_url'))
     for key, value in self.post_dict.iteritems():
         if key == 'birth_date':
             value = value.strftime('%B %m, %Y')
             self.assertContains(response, value, status_code=200)
         else:
             self.assertContains(response, value, status_code=200)