

@login_required
def update(request):
    if request.POST:
        form = UpdatePreferencesForm(request.POST, instance=get_object_or_404(UserPreferences, user=request.user))
        if form.is_valid():
            form.save()
            messages.add_message(request, messages.SUCCESS, _('You successfuly updated your preferences.'))
            return HttpResponseRedirect('/')
        else:
            return render_to_response('preferences/update.html', {
                'form': form,
            }, context_instance=RequestContext(request))
    else:
        return render_to_response('preferences/update.html', {
            'form': UpdatePreferencesForm(instance=get_object_or_404(UserPreferences, user=request.user)),
        }, context_instance=RequestContext(request))

dataset/ETHPy150Open linkfloyd/linkfloyd/linkfloyd/preferences/views.py update/original