def profile_edit_image(request): profile = request.user.get_profile() if request.method == 'POST': form = forms.ProfileImageForm(request.POST, request.FILES, instance=profile) if form.is_valid(): messages.success(request, _('Profile image updated')) form.save() return http.HttpResponseRedirect( reverse('users_profile_edit_image')) else: messages.error(request, _('There was an error uploading ' 'your image.')) else: form = forms.ProfileImageForm(instance=profile) return render_to_response('users/profile_edit_image.html', { 'profile': profile, 'profile_image_form': form, 'image_tab': True, }, context_instance=RequestContext(request))
def profile_edit_image_async(request): profile = get_object_or_404(UserProfile, user=request.user) form = forms.ProfileImageForm(request.POST, request.FILES, instance=profile) if form.is_valid(): instance = form.save() return http.HttpResponse(simplejson.dumps({ 'filename': instance.image.name, })) log.error('Error uploading image:%s' % form.errors) return http.HttpResponse(simplejson.dumps({ 'error': 'There was an error uploading your image.', }))
def profile_edit_image(request): profile = request.user.get_profile() if request.method == 'POST': form = forms.ProfileImageForm(request.POST, request.FILES, instance=profile) if form.is_valid(): messages.success(request, _('Profile image updated')) form.save() return http.HttpResponseRedirect( reverse('users_profile_edit_image')) else: messages.error(request, _('There was an error uploading ' 'your image.')) else: return http.HttpResponseRedirect(reverse('users_profile_edit'))