コード例 #1
0
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))
コード例 #2
0
ファイル: views.py プロジェクト: mkcode/lernanta
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.',
    }))
コード例 #3
0
ファイル: views.py プロジェクト: mkcode/lernanta
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'))